Problem loading/reading Gray scale TIFF

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, xnview

Post Reply
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Problem loading/reading Gray scale TIFF

Post by _GUI_ » Sat Apr 12, 2008 4:30 pm

Hi all,

I am reading a gray scale TIFF, i.e. an image where each pixel value just appears once and all pixels should be interpreted as R=G=B.

I am using 16-bit GflSDK from VB with this code to read it:

Code: Select all

Dim GflParams As GFL_LOAD_PARAMS
Dim PtrBitmap As Long
Dim GflInfo As GFL_FILE_INFORMATION
Dim Error As Integer

gflLibraryInit
gflGetDefaultLoadParams GflParams

With GflParams
  .Flags = GFL_LOAD_ORIGINAL_DEPTH
  .Origin = GFL_BOTTOM_LEFT 'Origin is top left
  .ColorModel = GFL_BGR 'Component order like DIB
  .LinePadding = 4 'Line padding on 4 bytes (32bits)
End With

Error = gflLoadBitmap("c:\foto.tif", PtrBitmap, GflParams, GflInfo)

If Error = GFL_NO_ERROR Then
  extGetGflBitmapFromPtr PtrBitmap, GflBitmap
Else
  Exit Sub
End If
Questions:

1. How should I open it and know it is not a RGB but gray scale picture?

2. I have managed to access all the data correctly through Color.Red like this (get the "photo.tiff" image from: foto.tif):

Code: Select all

gflGetColorAt GflBitmap, 0, 0, Color	' Get colour at pixel (0,0)
Color.Red -> 548
Color.Green -> 906
Color.Blue -> 564

Code: Select all

gflGetColorAt GflBitmap, 1, 0, Color	' Get colour at pixel (1,0)
Color.Red -> 906
Color.Green -> 564
Color.Blue -> 900

Code: Select all

gflGetColorAt GflBitmap, 2, 0, Color	' Get colour at pixel (2,0)
Color.Red -> 564
Color.Green -> 900
Color.Blue -> 564

Code: Select all

gflGetColorAt GflBitmap, 3, 0, Color	' Get colour at pixel (3,0)
Color.Red -> 900
Color.Green -> 564
Color.Blue -> 910

...

The values obtained from Color.Red, Color.Green and Color.Blue are not the same, they are cyclic. Just by reading Color.Red I can obtain the entire image data set, but there must be some other way to properly access this kind of images; I guess there must be some LOAD or READ PARAMETER that forces the library to interpret the image as grey scale but I cannot fin which one.

Could you please help?

Thank you very much.

anasrallah
Posts: 2
Joined: Tue Apr 22, 2008 6:18 pm

Post by anasrallah » Tue Apr 22, 2008 6:39 pm

Hi _GUI_,

Did you find a clean solution for your grayscale images? I'm working an a similar issue, I have 12 bit grayscale images.

btw why aren't you using the following:

With GflParams
.Flags = GFL_LOAD_ORIGINAL_DEPTH
.Origin = GFL_BOTTOM_LEFT
.ColorModel = GFL_GREY 'or is this a 255 value grey???
.LinePadding = 2 '2 bytes instead of 4 for 16 bits images
End With

anasrallah
Posts: 2
Joined: Tue Apr 22, 2008 6:18 pm

Post by anasrallah » Tue Apr 22, 2008 10:02 pm

also did you get the loaded image to show on a picture box in VB?

Post Reply