2004.02.06 21:35 "[Tiff] displaying 12 bit tiff image", by Liliana Resendiz

2004.02.06 21:35 "[Tiff] displaying 12 bit tiff image", by Liliana Resendiz

Hello,

I'm BCB6 user, I've reading the documentation in order to display correctly a 12-bit image on a TImage, first i proved with this code

 TIFF* tif = TIFFOpen(FileName, "rl");

  int max = 0;

  if (tif)
  {
    uint32 w, h, nOffset;
    size_t npixels;
    uint32* raster;
    uint16 pixel_val;
    unsigned short tfBitsPerSample, tfSamplesPerPixel, tfPlanarConfiguration,
                    tfPhotometricInterpretation, tfGrayResponseUnit,
                    tfImageDepth, tfBytesPerRow;

    TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tfPhotometricInterpretation);
    TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &tfBitsPerSample);
    TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &tfSamplesPerPixel);
    TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &tfPlanarConfiguration);
    TIFFGetFieldDefaulted(tif, TIFFTAG_GRAYRESPONSEUNIT, &tfGrayResponseUnit);

    tfImageDepth = tfBitsPerSample * tfSamplesPerPixel;
    nOffset = TIFFCurrentDirOffset( tif );
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);

    npixels = w * h;
    raster = (uint32*) _TIFFmalloc(npixels * sizeof(uint32));
    if (raster != NULL)
    {
      if (TIFFReadRGBAImage(tif, w, h, raster))

      {
        for (int y = 0; y < h; ++y)
        {
          pixel_val = (uint16) *raster++;
          pixel_val = pixel_val;
          if (pixel_val > max)
            max = pixel_val;
        }
      }
      _TIFFfree(raster);
    }
    TIFFClose(tif);
  }

with the TIFFReadRGBAImageOriented(tif, w, h, raster)) function, and i tried to display it on a TImage but it handles data range [0,256], but doing pixel_val = (uint16) *raster++, It seems i get a pixel value with data range [0,4096], is it correct?. I opened the image with the "rl" parameters to get the max pixel value of 3855, but now, how i can display int on a Timage?

If i direclty open the tiff image from the TImage and change its pixel format to pf16bit then it displays something but it is not correclty at all. I imagine that the TImage assumes a data range [0,256] and tries to display it as an 8-bit image because it appears black.

Can you help me to display it correctly?

Thank you in advance.

Liliana