Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms


Xpounded Examine JFIF JPEG

Image Scripting: Examine JFIF file structure of JPEG Image



code is copyright Robert Spoons 2007
credit use
Thanks.
Using VBS to evamine baseline JPEG image files...

This script shows how a baseline JPEG is stored in a JFIF file.


USE:

You use the script by dragging and dropping a baseline JPEG Image file onto it.
First the script will examine its own parent folder looking for a subfolder with the same name as the dropped file. If it can not find such a folder, it will create one.
Second, the script will do a simple analysis on the dropped image file and report its findings in a text file which it creates in the files (new) folder.

Built to read baseline JPEG JFIF files
The information for the algorithms abound on the net (google jfif) - the vbs implementaion is my own.

The markers this script will locate and report on are:
	(The 'Sample:' text is the result of a typical run)

	SOI		(FFD8) Start of image
	Sample:
	SOI Marker
			(Start Of Image Marker)
			* No Content *
			Start Byte: 1
			End Byte: 2

	APP0		(FFE0) Application data
	Sample:
	APP0 Marker
		(Application Data Segment)
		LengthOfSegment: 16
		Start Byte: 3
		End Byte: 20
		Version: 1.1
		Units: 1
		Xdensity: 72
		Ydensity: 72
		XThumb (Width): 0
		YThumb (Height): 0

	DQT		(FFDB) Quatization Table
	Sample:
	DQT Marker
		(Quantization Table Segment - QT Tables)
		LengthOfSegment: 67
		Start Byte: 21
		End Byte: 89
		Number Of QT Tables: 1

		Table ID: 0
		Precision: 0
		Table Data: 
		48, 53, 51, 52, 52, 52, 51, 53, 
		52, 52, 52, 53, 53, 53, 54, 55, 
		49, 56, 55, 55, 55, 55, 49, 49, 
		49, 57, 49, 49, 49, 49, 49, 49, 
		49, 49, 49, 49, 50, 50, 50, 49, 
		50, 50, 50, 49, 49, 50, 51, 50, 
		50, 50, 50, 51, 51, 51, 49, 50, 
		51, 51, 51, 51, 51, 50, 51, 51, 

	SOF0		(FFC0) Start of frame 0
	Sample:
	SOF0 Marker
		(Start Of Frame 0 Segment - Components Used By Id 1=Y, 2=Cb, 3=Cr)
		LengthOfSegment: 17
		Start Byte: 159
		End Byte: 177
		Data Precision: 8
		Y (Image Height): 197
		X (Image Width): 300
		NumberOfComponents: 3
		Component Data: 
		Component ID: 1
			Horiz Sample Factor: 3
			Vert Sample Factor: 3
			Quant Table (QT Table ID) To Use : 0
		Component ID: 2
			Horiz Sample Factor: 3
			Vert Sample Factor: 1
			Quant Table (QT Table ID) To Use : 1
		Component ID: 3
			Horiz Sample Factor: 3
			Vert Sample Factor: 1
			Quant Table (QT Table ID) To Use : 1

	DHT		(FFC4) Huffman table
	Sample:
	DHT Marker
			(Huffman Table Segment - HT Tables)
			LengthOfSegment: 28
			Start Byte: 178
			End Byte: 207
			Table Class: 0
			Table ID: 0
			total number of codes: 9
			CodeTable: 
			Code Length (Category): Number Of Codes (In Category): 
				Binary Code (For 8-Bit Lookup Symbol): 8-Bit LookUp Symbol (HEX)
			Code Length = 2 : # of Codes = 1 : 
				00: 00
			Code Length = 3 : # of Codes = 5 : 
				010: 03
				011: 04
				100: 05
				101: 06
				110: 07
			Code Length = 4 : # of Codes = 1 : 
				1110: 02
			Code Length = 5 : # of Codes = 1 : 
				11110: 01
			Code Length = 6 : # of Codes = 1 : 
				111110: 08


	DRI		(FFDD) Retart interval

	SOS		(FFDA) Start of scan
	Sample:
	SOS Marker
			(Start Of Scan Segment - Image Data starts immediatly after this header)
			LengthOfHeader: 12
			Start Byte: 373
			End Byte (Last Byte Of Header):386
			NumberOfComponentsInScan: 3
			Components 
				Component Selector: 1
					Td (HT Table ID For DC - class 0): 0
					Ta (HT Table ID For AC - class 1): 0
				Component Selector: 2
					Td (HT Table ID For DC - class 0): 1
					Ta (HT Table ID For AC - class 1): 1
				Component Selector: 3
					Td (HT Table ID For DC - class 0): 1
					Ta (HT Table ID For AC - class 1): 1
			StartOfSpectralSelection: 0
			EndOfSpectralSelection: 63
			Ah: 0
			Al: 0

	RST0 to RST7	(FFD0 to FFD7) Reset token
	JPG		(FFC8) Reserved for extensions
	DNL		(FFDC) Number of lines
	COM		(FFFE) Comments

	EOI		(FFD9) End of image
	Sample:
	EOI Marker
			(End Of Image Marker)
			* No Content *
			Start Byte: 8164
			End Byte: 8165

If the result looks cryptic to you, google a reference to the (JPEG) JFIF file structure.
Hope this helps someone starting their journey to understanding JPEG/JFIF structure and how to build a JPEG Decoder.
Almost forgot, the 'missing' part of this implementaion that would make this script a JPEG decoder (you know the part where the mcu's are decoded from the encoded image data bitstream and the huffman tables into 8x8 zigzag blocks that are dequantized, have the inverse discrete cosine transform (idct) applied, shited (128), and converted back to RGB) is avilable upon request.
toodles

Available REFS:
Graphics File Formats 2nd Edition. David C. Kay & John R. Levine
JPEG File Interchange Format. Version 1.02 Eric Hamilton
JPEG Standard ISO/IEC 10918-1
CCITT Rec T.81

An nice small intro to decoding jpeg: ImpulseAdventure - JPEG Huffman Coding Tutorial
when reading remember that the huffman table code for ac data is highbits = # of preceding 0's and lowbits = code category

Use the 1st 16 bytes of encoded image data returned by JpegMarkers.vbs to work through the real encoded image data on your own.

Requirements: Windows 98+, WSH 5.6+ (VBS), Image File in 24-bit non-compressed BMP format.

Tested on XP Home edition SP2, IE6 installed. (Not tested with IE7 installed)


Save this file to your system as JpegMarkers.vbs

  Select All

No HTML to View

- Copyright 2007 Xpounded -
All JS code developed by Xpounded is developed in RHSCoder.
All VBS code developed by Xpounded is developed in VBS QuickDev IDE, or RHSCoder.
Privacy Statement