tags:

views:

81

answers:

1

The code below (from this thread: http://stackoverflow.com/questions/2405899/how-to-use-delphi-2010s-new-wic-capability-on-canon-files) opens a WIC image into a BitMap.

However, if the dynamic range of WIC pixel values is large, this code loses a lot of information, since it has to scale the wide dynamic range into the low range that a Bitmap pixel can accommodate.

procedure TForm116.Button1Click(Sender: TObject);
var
  WIC: TWICImage;
begin
  WIC := TWICImage.Create;
  try
    WIC.LoadFromFile('MyFilename.raw');
    Image1.Picture.Graphic.Assign(WIC);
  finally
    WIC.Free;
  end;
end;

Can anyone show me sample code that would let me read the pixel values directly from the TWICImage, so I can access the image data without losing information? I need the intensity (gray scale) values of each pixel which perhaps can be calculated from the RGB values if not directly available?

Something like:

var
  PixelValue: Integer; // Grayscale

for Row := 0 to WIC.Width do
  for Col := 0 to WIC.Height
     PixelValue := WIC.GetPixelValue(Row, Col);
A: 

You should be able to assign() the TWICImage to a TBitmap, and then access the bitmap's Pixels or ScanLine property to get at the pixel data. Much like you'd do when loading a JPEG.

For example (untested pseudocode)

w := TWICImage.Create();
w.LoadFromFile(...)
b := TBitmap.Create;
b.assign( w);
ptr := b.ScanLine[...]
GrandmasterB
As I noted (perhaps incorrectly) in my original post, the pixels in a TBitMap have a range from 0..255 (as returned, for example, by ScanLine in a PByteArray.) A WIC image, though, can have pixels whose value is in the tens of thousands or more... The library code that is invoked by (in my original post) Image1.Picture.Graphic.Assign(WIC) scales the wide range (say 0..10000) to (0..255), thus losing a lot of detail.
Robert Frank
A bitmap can have many different color depths, from monochrome (1-bit) to, more commonly, 24/32-bit (4 byte, 2 billion collors) or even higher. The color value, then, for 24 or 32bit bitmaps is a 32bit integer - far more than 0-255. What I think you are misunderstanding is that for 32bit bitmaps, its the individual color components that range from 0-255, not the pixel. To get the grayscale value, you then send those color components through the function of your choice to generate a 0-255 grayscale value.
GrandmasterB
The cannon raw files might be High Dynamic Range images (exposure etc), which may include the full floating point spectrum. There is no 1:1 mapping of these files on any of the formats Delphi supports (nor to the display). In this case the keyword to look for is _tone mapping_.
Paul-Jan
He didnt say he was specifically working with that type of file - he just linked to sample code that did because it used TWICImage. I suspect if he really needs floating point precision, he'll have to use the WIC interfaces directly. Though, for just retrieving grayscale, using TBitmap should do the trick even for those images.
GrandmasterB