0

Hey I am working with image in JAVA (sobel operator) and I don't understand what some lines of code mean.

int p = img.getRGB(x,y);
int a = (p>>24)&0xff;
int r = (p>>16)&0xff;
int g = (p>>8)&0xff;
int b = p&0xff;
p = (a<<24) | (avg<<16) | (avg<<8) |avg;

So could someone explain what these lines mean?

(p>>24)&0xff
p = (a<<24) | (avg<<16) | (avg<<8) |avg;
Mauro Baraldi
  • 6,346
  • 2
  • 32
  • 43
szufi
  • 219
  • 1
  • 2
  • 9

1 Answers1

0

Those are bitwise operations. p>>24 shifts first byte in p int 24 places to the right and &0xff performs bitwise and with shifted number and hexadecimal number ff(decimal 255). avg << 16 shifts first byte in avg int 16places to the left. And | performs bitwise or with other values. These are so called bitmasks. Search terms bitwise operations and bitmasks for more information. Hope i helped :)

Marko vlaić
  • 316
  • 5
  • 15