0

I have defined:

typedef unsigned char uint8;

#define IMG_TYPE_DEF(typeName) struct {\
  size_t w;\
  size_t h;\
  typeName* data;\
}

typedef IMG_TYPE_DEF(uint8) ImageU8;
typedef ImageU8 Image;

And in main :

void gradient(const Image* src){
  uint8* pPrev = src->data - src->w;
...

My aim is to rewrite this code from c to java. I have problem with data types. Can unsigned char be just a char or int? And if yes, how i should deal with this line, i do not understand it:

uint8* pPrev = src->data - src->w;

For example if src->w=900 what is heppening?

Mich Z
  • 1
  • 1
  • [Pointer arithmetic](https://stackoverflow.com/questions/394767/pointer-arithmetic) – kaylum Nov 17 '15 at 23:50
  • uint8 would just be Java Byte. So the image type contains a width and height (use int or long), and an array of bytes which is probably (h * w) bytes. Adding or subtracting w is probably being used to move a pointer forward and backward by line. That's not really a Java way of doing things. – Lee Daniel Crocker Nov 17 '15 at 23:50
  • @LeeDanielCrocker `uint8` won't just be Java `byte` because `uint8` is unsigned and `byte` is signed. – MikeCAT Nov 18 '15 at 00:20
  • Are you looking for [ByteBuffer](http://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html)? – Jason Nov 18 '15 at 01:28
  • Sill, you'll often find `uint8` and java `byte` used interchangeably because they both hold 8 bits and most program code does not care about signedness. Especially images. The equivalent of a `uint8* data` array would be a `byte[]` array in Java. @MichZ https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html `char` is kind of special in java but can also hold 16 bit integers. And those pointer operations need an entirely different approach in java since there are no pointers. Translate the algorithm, not the code. – zapl Nov 18 '15 at 02:37

0 Answers0