Page 4 of 4

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 1:42 am
by IdeasVacuum
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

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 7:39 am
by Michael Vogel
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...

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 ***
	:
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.

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

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 1:58 pm
by IdeasVacuum
Image

Oh deary me! That Debug thing was such a great invention :mrgreen:
The reason I got zero dimensions is because I never passed the full path of the files to GetImageInformation()
If ExamineDirectory(0,"C:\TempImagesTIF\MV\","*.*")
While NextDirectoryEntry(0)
If DirectoryEntryType(0)=#PB_DirectoryEntry_File
file.s = "C:\TempImagesTIF\MV\" + DirectoryEntryName(0)
I'm going to go away and hide in a corner for a while........

__________________________________________________
Code tags>quote tags
13.02.2016
RSBasic

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 4:04 pm
by Michael Vogel
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 :wink:

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.

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 7:21 pm
by IdeasVacuum
...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!

Re: Get image width and height without loading image

Posted: Sat Feb 13, 2016 7:35 pm
by RSBasic
@IdeasVacuum
I'm sorry, you're right.