Skip to main content
Question

Bitwise operations on rasters evaluate to 0

  • October 21, 2020
  • 1 reply
  • 11 views

r_huesken
Contributor
Forum|alt.badge.img+5

Hi,

I have a png raster with RGBA bands, and I need to transform this raster into a single band grayscale (UInt32). By convention, we have set the leftmost bit in the Alpha channel to 1. This bit is to be ignored when computing the result (a "31 bit integer"), which should fit in the UInt32 type (isn't it?).

 

In the rasterexpressionevaluator, I use the following formula:

@if(A[3]<128,0,((A[3] -128)*256*256*256 + A[0]*256*256 + A[1]*256 + A[2]))

 

However, when I try to use bitwise operators, only the value of the blue band (a[2]) is included in the result.

 

((A[3] & 127) << 24) | (A[0] << 16) | (A[1] << 8) | A[2])

 

I used a simpler form for testing purposes (A[1] << 8), but this always evaluates to 0.

 

I can't figure out how to use the bitwise operators, any help would be appreciated.

 

 

 

1 reply

r_huesken
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • October 21, 2020

Hi,

I have found something that works. I first use a RasterBandInterpretationCoercer to cast all bands to UInt32, then I apply the raster formula in the rasterexpressionevaluator :

 

((A[3] & 127) << 24) | (A[0] << 16) | (A[1] << 8) | A[2])

 

Confusing that ne needs 2 steps,and FME does not signal that the operation fails...

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings