Skip to main content
Question

Bitwise operations on rasters evaluate to 0

  • October 21, 2020
  • 1 reply
  • 16 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.

 

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

r_huesken
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • 33 replies
  • 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...