Einzelnen Beitrag anzeigen

Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 
#15
  Alt 20. Jul 2002, 07:34
Eine Regelmäßigkeit gibts schon, aber die hat ein paar verschiedene Abhängigkeiten...
Code:
JPEG/JFIF file format:
~~~~~~~~~~~~~~~~~~~~~~

  - header (2 bytes): $ff, $d8 (SOI) (these two identify a JPEG/JFIF file)
  - for JFIF files, an APP0 segment is immediately following the SOI marker, see below
  - any number of "segments" (similar to IFF chunks), see below
  - trailer (2 bytes): $ff, $d9 (EOI)

Segment format:
~~~~~~~~~~~~~~~

  - header (4 bytes):
       $ff    identifies segment
        n     type of segment (one byte)
       sh, sl size of the segment, including these two bytes, but not
               including the $ff and the type byte. Note, not Intel order:
               high byte first, low byte last!
  - contents of the segment, max. 65533 bytes.

 Notes:
  - There are parameterless segments (denoted with a '*' below) that DON'T
    have a size specification (and no contents), just $ff and the type byte.
  - Any number of $ff bytes between segments is legal and must be skipped.

Segment types:
~~~~~~~~~~~~~~

   *TEM  = $01   usually causes a decoding error, may be ignored
    SOF0  = $c0   Start Of Frame (baseline JPEG), for details see below
    SOF1  = $c1   dito
    SOF2  = $c2   usually unsupported
    SOF3  = $c3   usually unsupported

    SOF5  = $c5   usually unsupported
    SOF6  = $c6   usually unsupported
    SOF7  = $c7   usually unsupported

    SOF9  = $c9   for arithmetic coding, usually unsupported
    SOF10 = $ca  usually unsupported
    SOF11 = $cb  usually unsupported

    SOF13 = $cd  usually unsupported
    SOF14 = $ce  usually unsupported
    SOF14 = $ce  usually unsupported
    SOF15 = $cf  usually unsupported

    DHT  = $c4   Define Huffman Table, for details see below
    JPG  = $c8   undefined/reserved (causes decoding error)
    DAC  = $cc  Define Arithmetic Table, usually unsupported

   *RST0  = $d0   RSTn are used for resync, may be ignored
   *RST1  = $d1
   *RST2  = $d2
   *RST3  = $d3
   *RST4  = $d4
   *RST5  = $d5
   *RST6  = $d6
   *RST7  = $d7

    SOI  = $d8   Start Of Image
    EOI  = $d9   End Of Image
    SOS  = $da  Start Of Scan, for details see below
    DQT  = $db  Define Quantization Table, for details see below
    DNL  = $dc  usually unsupported, ignore

    SOI  = $d8   Start Of Image
    EOI  = $d9   End Of Image
    SOS  = $da  Start Of Scan, for details see below
    DQT  = $db  Define Quantization Table, for details see below
    DNL  = $dc  usually unsupported, ignore
    DRI  = $dd  Define Restart Interval, for details see below
    DHP  = $de  ignore (skip)
    EXP  = $df  ignore (skip)

    APP0  = $e0   JFIF APP0 segment marker, for details see below
    APP15 = $ef  ignore

    JPG0  = $f0   ignore (skip)
    JPG13 = $fd  ignore (skip)
    COM  = $fe  Comment, for details see below

 All other segment types are reserved and should be ignored (skipped).

SOF0: Start Of Frame 0:
~~~~~~~~~~~~~~~~~~~~~~~

  - $ff, $c0 (SOF0)
  - length (high byte, low byte), 8+components*3
  - data precision (1 byte) in bits/sample, usually 8 (12 and 16 not
    supported by most software)
  - image height (2 bytes, Hi-Lo), must be >0 if DNL not supported
  - image width (2 bytes, Hi-Lo), must be >0 if DNL not supported
  - number of components (1 byte), usually 1 = grey scaled, 3 = color YCbCr
    or YIQ, 4 = color CMYK)
  - for each component: 3 bytes
     - component id (1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q)
     - sampling factors (bit 0-3 vert., 4-7 hor.)
     - quantization table number
Das heisst, Du musst zuerst das Segment finden, welches mit dem Marker 0xFFC0 markiert ist, und das muss nicht das erste Segment sein, da dort auch andere Informationen gespeichert sein können. in diesem Segment musst Du Byte 5 und 6 für die Höhe lesen und Byte 7 und 8 für die Breite.

Code:
NOTE: The JPEG/JFIF file format uses Motorola format for words, NOT Intel format,
i.e. : high byte first, low byte last -- (ex: the word FFA0 will be written in
the JPEG file in the order : FF at the low offset , A0 at the higher offset)
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat