OK - Tiff is complicated. One potential issue is that a jpeg-like compression can be applied to a tif file. The likes of ImageMagick and LeadTools are using the C Tiff Library libtiff (core of which is tiffio.h, tiffio.c). It's a relatively old format, goes back to the days of Silicon Graphics (I used to love using the IRIX workstation for CAD).
Published by Adobe: The TIFF format defined TIFF6.pdf
Get image width and height without loading image
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Get image width and height without loading image
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- Michael Vogel
- Addict
- Posts: 2677
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Get image width and height without loading image
Strange and complicated, my friend...
First, my image examples work here (and should do that in Wales as well), maybe you can add two debug lines to check something...
You should see Tif 8 / 5 / 11 / 17 / 559 x 569 | P1170938.tif for my picture and something like Tif 810008 / 1 / 7 / 600 x 450 | Koala.tif for your examples.
Second, the TGA header seems to allow multiple values, didn't reread the format description but changed the code to allow also $00 (not only $01) now, so I get fine results for these type as well...
559 x 569 | P1170938.jpg
559 x 569 | P1170938.tga
559 x 569 | P1170938.tif
600 x 450 | Chrysanthemum.tga
600 x 450 | Chrysanthemum.tif
960 x 960 | Denzil Washington.jpg
600 x 450 | Desert.tga
600 x 450 | Desert.tif
600 x 450 | Hydrangeas.tga
600 x 450 | Hydrangeas.tif
:
Beside this I start to evaluate the image file type by checking the file extension now, because of the more "looser" header checks (e.g. $00/01 will only be checked for files with the extension TGA). Anyhow you should see correct values for all given images now, I have checked the procedure with ASCII and unicode option set for the compiler.
First, my image examples work here (and should do that in Wales as well), maybe you can add two debug lines to check something...
Code: Select all
Case #ImageHeaderTIF_LSB
a=0
n=*Buffer\l[1]
Debug "Tif "+Str(n); *** ADDED ***
If n>#ImageHeaderSize-#ImageHeaderSizeTif
:
While m And n<#ImageHeaderSizeTif>>1
Debug n; *** ADDED ***
:
Second, the TGA header seems to allow multiple values, didn't reread the format description but changed the code to allow also $00 (not only $01) now, so I get fine results for these type as well...
559 x 569 | P1170938.jpg
559 x 569 | P1170938.tga
559 x 569 | P1170938.tif
600 x 450 | Chrysanthemum.tga
600 x 450 | Chrysanthemum.tif
960 x 960 | Denzil Washington.jpg
600 x 450 | Desert.tga
600 x 450 | Desert.tif
600 x 450 | Hydrangeas.tga
600 x 450 | Hydrangeas.tif
:
Beside this I start to evaluate the image file type by checking the file extension now, because of the more "looser" header checks (e.g. $00/01 will only be checked for files with the extension TGA). Anyhow you should see correct values for all given images now, I have checked the procedure with ASCII and unicode option set for the compiler.
Code: Select all
Procedure.i CheckImageName(*Name)
Enumeration
#ImageTypeUnknown
#ImageTypeJpg
#ImageTypeJp2
#ImageTypePng
#ImageTypeBmp
#ImageTypeTif
#ImageTypePcx
#ImageTypeGif
#ImageTypeTga
EndEnumeration
Protected n
n=FindString("|jpeg|jpg|jp2|png|bmp|tif|pcx|gif|tga|","|"+LCase(GetExtensionPart(PeekS(*Name)))+"|")
If n>2
n>>2
ElseIf n=2
n=1
EndIf
ProcedureReturn n
EndProcedure
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Get image width and height without loading image
Oh deary me! That Debug thing was such a great invention
The reason I got zero dimensions is because I never passed the full path of the files to GetImageInformation()
I'm going to go away and hide in a corner for a while........If ExamineDirectory(0,"C:\TempImagesTIF\MV\","*.*")
While NextDirectoryEntry(0)
If DirectoryEntryType(0)=#PB_DirectoryEntry_File
file.s = "C:\TempImagesTIF\MV\" + DirectoryEntryName(0)
__________________________________________________
Code tags>quote tags
13.02.2016
RSBasic
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- Michael Vogel
- Addict
- Posts: 2677
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Get image width and height without loading image
I feel better now...
...because it looks like I am the only one who is doing strange things from time to time, especially when programming
Just one example (I know many more, but I don't want to talk about them), the CheckImageName procedure above contains the If n>2 : n>>2 : ElseIf n=2 : n=1 : EndIf statement which can be reduced to a much simpler If n>1 : n>>2 : EndIf, because the ElseIf will be needed at no time.
...because it looks like I am the only one who is doing strange things from time to time, especially when programming
Just one example (I know many more, but I don't want to talk about them), the CheckImageName procedure above contains the If n>2 : n>>2 : ElseIf n=2 : n=1 : EndIf statement which can be reduced to a much simpler If n>1 : n>>2 : EndIf, because the ElseIf will be needed at no time.
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Get image width and height without loading image
...RS Basic, I deliberately omitted the code tags so that I could use colour to highlight where the error was! Your change to my post makes it less useful!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.