Saving TIFF in 16 bits, is it possible?

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

Moderators: XnTriq, helmut, xnview

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

Saving TIFF in 16 bits, is it possible?

Post by _GUI_ »

I have managed to load TIFF 16 bits images, but when it comes the time to save them back, they are stored in 8 bit TIFF.

I hope it is possible to save them with a 16 bit colour depth, is it? how?
I get 8 bits with this code, even if the original image was 16 bit:

MyObj3.SaveFormat = AX_TIFF
MyObj3.SaveBitmap ("c:\pic.tif")



I think this is very important if the library is to be used with high quality photograph images.

Cheers.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Saving TIFF in 16 bits, is it possible?

Post by xnview »

_GUI_ wrote:I have managed to load TIFF 16 bits images, but when it comes the time to save them back, they are stored in 8 bit TIFF.

I hope it is possible to save them with a 16 bit colour depth, is it? how?
I get 8 bits with this code, even if the original image was 16 bit:

MyObj3.SaveFormat = AX_TIFF
MyObj3.SaveBitmap ("c:\pic.tif")



I think this is very important if the library is to be used with high quality photograph images.

Cheers.
You can't use 16 bits per component with ActiveX
Pierre.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Post by _GUI_ »

OK I see, so is there any solution to handle 16-bit images from VB? maybe declaring the libgfl267.dll and libgfle267.dll library functions from a Module and calling them straight like this?:

Dim cx As Long
Dim cy As Long
Dim Color As GFL_COLOR 'This structure is to retrieve the color information

cx = ScaleX(x, vbTwips, vbPixels) 'We convert the Twips data in pixels
cy = ScaleY(y, vbTwips, vbPixels)
gflGetColorAt GflBitmap, cx, cy, Color 'We get the pixel value

If the processed image is 16-bit, will Color.Red, Color.Green and Color.Blue be 16 bit integers in the range 0...65535 or in the 0..255 range?

Thank you in advance and contratulations for your work.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

_GUI_ wrote:OK I see, so is there any solution to handle 16-bit images from VB? maybe declaring the libgfl267.dll and libgfle267.dll library functions from a Module and calling them straight like this?:

Dim cx As Long
Dim cy As Long
Dim Color As GFL_COLOR 'This structure is to retrieve the color information

cx = ScaleX(x, vbTwips, vbPixels) 'We convert the Twips data in pixels
cy = ScaleY(y, vbTwips, vbPixels)
gflGetColorAt GflBitmap, cx, cy, Color 'We get the pixel value

If the processed image is 16-bit, will Color.Red, Color.Green and Color.Blue be 16 bit integers in the range 0...65535 or in the 0..255 range?

Thank you in advance and contratulations for your work.
Yes, here the data will be in the range 0-65535
Pierre.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Post by _GUI_ »

xnview wrote:Yes, here the data will be in the range 0-65535
Hi Pierre, I am sorry to take this again but this is critical to me and after trying I can't manage to read the colour values of 16-bit TIFF files in their original 0..65535 range. Here is a sample of 16-bit TIFF with all 3 channels set to 31612 value: http://www.guillermoluijk.com/download/example.zip

When reading (Gfl functions called from VB) its pixels' colour with:

cx = ScaleX(x, vbTwips, vbPixels) 'We convert the Twips data in pixels
cy = ScaleY(y, vbTwips, vbPixels)
gflGetColorAt GflBitmap, cx, cy, Color 'We get the pixel value

labX.Caption = cx 'Display values
labY.Caption = cy
labR.Caption = Color.Red
labG.Caption = Color.Green
labB.Caption = Color.Blue


It returns the rounded 8-bit value of 123 (equals to 31612/256). Looking at supported bit depths in the help of the gflChangeColorDepth function I cannot see the library can handle 16 bit images (48 bit/pixel), but on the other side when looking at your GFL_COLOR definition you use 16-bit unsigned for each channel.

Is it possible to call your functions and get that 31612 colour value? could you please tell me which function or option I have to use it to get it?
If you could write the little piece of code to produce that 31612 number from that image the problem would be completely solved.

Thanks a lot.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

GFLAx doesn't support 16bit files, you must use GFL SDK with gflLoadBitmap & GFL_LOAD_ORIGINAL_DEPTH flag
Pierre.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Post by _GUI_ »

ok I will try that "GFL_LOAD_ORIGINAL_DEPTH" flag.
I am calling your functions from VB, but I was already using the C libraries according to your examples. Not using the activex component.

Or you mean from VB is absolutely impossible to get the image data in its original 0..65535 range?

Thanks
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

_GUI_ wrote:ok I will try that "GFL_LOAD_ORIGINAL_DEPTH" flag.
I am calling your functions from VB, but I was already using the C libraries according to your examples. Not using the activex component.

Or you mean from VB is absolutely impossible to get the image data in its original 0..65535 range?

Thanks
Houps, sorry. You can use C or VB but with GFL dll
If GFL_LOAD_ORIGINAL_DEPTH is not used, the bitmap is loaded in 8bits per component!
Pierre.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

GFL_COLOR problem

Post by _GUI_ »

Perfect, at last I could read 16-bit TIFF files in their original range!!!

Problem: the The GFL_COLOR structure is defined in C as unsigned int (0..65535) but when called from VB values greater than 32767 are returned as negative, forcing some additional uncomfortable checking.

For instance:

Dim Color As GFL_COLOR
gflGetColorAt GflBitmap, 10, 10, Color

In my almost white image Color.Red should return 62880 but returns -2657. I guess is due to the coding of the UINT16 type in C, that differs from signed 16-bit integers in VB.

Is there any solution to fix this or just have to check values everytime?
I suppose if values are greater than 32767 then conversion rule could be something like value-65537, is that right?

Regards.
User avatar
xnview
Author of XnView
Posts: 44470
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: GFL_COLOR problem

Post by xnview »

_GUI_ wrote:Is there any solution to fix this or just have to check values everytime?
I suppose if values are greater than 32767 then conversion rule could be something like value-65537, is that right?
Do you have an Unsigned word in VB?
Pierre.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Post by _GUI_ »

Unfortunately not.

But I have seen that the signed/unsigned controversia is quite common when dealing with DLL's from VB and can be solved using simple functions as:

Option Explicit

Private Const OFFSET_2 = 65536
Private Const MAXINT_2 = 32767

' Converts from what Color.Red produces into positive 0..65535 range
Function IntegerToUnsigned(Value As Integer) As Long
If Value < 0 Then
IntegerToUnsigned = Value + OFFSET_2
Else
IntegerToUnsigned = Value
End If
End Function

' Converts from positive 0..65535 range into what Color.Red produces
Function UnsignedToInteger(Value As Long) As Integer
If Value <0>= OFFSET_2 Then Error 6 ' Overflow
If Value <= MAXINT_2 Then
UnsignedToInteger = Value
Else
UnsignedToInteger = Value - OFFSET_2
End If
End Function



Thank you very much Pierre, I think I will do nice things thanks to your library.
_GUI_
Posts: 22
Joined: Fri Sep 08, 2006 12:22 am

Post by _GUI_ »

Great Pierre!!! I have finally managed to load two 16-bit TIFFs, process them in the range 0..65535 and put them back into a 16-bit TIFF file, all from VB.
I am really very happy :)

I have written a program to generate virtually noise free images from two shots and it processes two 8Mpx 16-bit TIFF files in less than 5 seconds. The noise reduction results are the same as shown here (see final pictures):
http://www.guillermoluijk.com/tutorial/ ... /index.htm

Thanks again!