WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Image Sizer

Keywords: 	  image sizer jpg gif GIF JPG

M_SOF0 =     192; #define M_SOF0  0xC0		/* Start Of Frame N */
M_SOF1 =     193; #define M_SOF1  0xC1		/* N indicates which compression process */
M_SOF2 =     194; #define M_SOF2  0xC2		/* Only SOF0-SOF2 are now in common use */
M_SOF3 =     195; #define M_SOF3  0xC3
M_SOF5 =     197; #define M_SOF5  0xC5		/* NB: codes C4 and CC are NOT SOF markers */
M_SOF6 =     198; #define M_SOF6  0xC6
M_SOF7 =     199; #define M_SOF7  0xC7
M_SOF9 =     201; #define M_SOF9  0xC9
M_SOF10=     202; #define M_SOF10 0xCA
M_SOF11=     203; #define M_SOF11 0xCB
M_SOF13=     205; #define M_SOF13 0xCD
M_SOF14=     206; #define M_SOF14 0xCE
M_SOF15=     207; #define M_SOF15 0xCF
M_SOI  =     216; #define M_SOI   0xD8		/* Start Of Image (beginning of datastream) */
M_EOI  =     217; #define M_EOI   0xD9		/* End Of Image (end of datastream) */
M_SOS  =     218; #define M_SOS   0xDA		/* Start Of Scan (begins compressed data) */
M_APP0 =     224; #define M_APP0	0xE0		/* Application-specific marker, type N */
M_APP12=     236; #define M_APP12	0xEC		/* (we don't bother to list all 16 APPn's) */
M_COM  =     254; #define M_COM   0xFE		/* COMment */



thisfile=AskFilename("Select Image file","","GIF or JPG|*.gif;*.jpg;*.jpeg","*.*",1)

bb=BinaryAlloc(FileSize(thisfile))


   thisExt=strlower(FileExtension(thisfile))
   thisroot=FileRoot(thisfile)
   BinaryEODSet(bb,0)
   BinaryRead(bb,thisfile)
   if thisExt=="gif"
      width=BinaryPeek2(bb,6)
      height=BinaryPeek2(bb,8)
   else     ; JPEG
                   off=0
                  
                  ;Get and check first marker
                  c1=BinaryPeek(bb,off)
                  Terminate(c1!=255,thisfile,"Not jpeg.  First byte not FF")
                  off=off+1
                  
                  c2=BinaryPeek(bb,off)
                  Terminate(c2!=M_SOI,thisfile,"Not jpeg.  SOI marker missing")
                  off=off+1
                  marker=c2
                  
                  ;We just past SOI marker.  Get next marker
                  
                  while 1
                  gosub getnextmarker
                  
                  switch marker
                      case M_SOF0;		/* Baseline */
                      case M_SOF1;		/* Extended sequential, Huffman */
                      case M_SOF2;		/* Progressive, Huffman */
                      case M_SOF3;		/* Lossless, Huffman */
                      case M_SOF5;		/* Differential sequential, Huffman */
                      case M_SOF6;		/* Differential progressive, Huffman */
                      case M_SOF7;		/* Differential lossless, Huffman */
                      case M_SOF9;		/* Extended sequential, arithmetic */
                      case M_SOF10;		/* Progressive, arithmetic */
                      case M_SOF11;		/* Lossless, arithmetic */
                      case M_SOF13;		/* Differential sequential, arithmetic */
                      case M_SOF14;		/* Differential progressive, arithmetic */
                      case M_SOF15;		/* Differential lossless, arithmetic */
                           len=BinaryPeek(bb,off)*256+BinaryPeek(bb,off+1)
                           datapres=BinaryPeek(bb,off+2)
                           height=BinaryPeek(bb,off+3)*256+BinaryPeek(bb,off+4)
                           width=BinaryPeek(bb,off+5)*256+BinaryPeek(bb,off+6)
                           comp=BinaryPeek(bb,off+7)
                           ;Message(off,"H=%height% W=%width%")
                           gosub skipblock
                         break
                  
                  
                      case marker;			/* Anything else just gets skipped */
                        ;Message(off,marker) 
                        gosub skipblock;		/* we assume it has a parameter count... */
                        break;
                  
                  
                  endswitch
                  if marker==M_SOS then break
                  continue
                  endwhile
                  
                  ;Message("All","Doned")


   endif



BinaryFree(bb)
Message(thisfile,strcat("Width=",width,@crlf,"Height=",height))

exit

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

:skipblock
   len=BinaryPeek(bb,off)*256+BinaryPeek(bb,off+1)
   off=off+len
   return

:getnextmarker
;Discard bytes till be get a FF byte

while (BinaryPeek(bb,off)!=255)
      off=off+1
endwhile

;Now discard FF bytes till be get a databyte

while BinaryPeek(bb,off)==255
    off=off+1
endwhile

marker=BinaryPeek(bb,off)
off=off+1
return






Article ID:   W14954
File Created: 2001:11:08:12:41:08
Last Updated: 2001:11:08:12:41:08