Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure ParsePNG(const AFileName: TFileName);
- var
- VFile: TFileStream;
- VReader: TPNGReader;
- VColSpace: ShortString;
- VHeight, VWidth: LongWord;
- VBitDepth, VColorType: Byte;
- begin
- VHeight := 0;
- VWidth := 0;
- VBitDepth := 0;
- VColorType := 0;
- VFile := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
- VReader := TPNGReader.Create;
- try
- if not VReader.CheckContents(VFile) then
- raise Exception.CreateFmt('Not a PNG file: %s', [AFileName]);
- if VReader.GetChunk.aType <> ctIHDR then
- raise Exception.CreateFmt('Incorrect PNG file: %s', [AFileName]);
- VBitDepth := VReader.Header.BitDepth;
- if VBitDepth > 8 then
- raise Exception.CreateFmt('16-bit depth not supported: %s', [AFileName]);
- VColorType := VReader.Header.ColorType;
- case VColorType of
- 0, 4: VColSpace := 'DeviceGray';
- 2, 6: VColSpace := 'DeviceRGB';
- 3: VColSpace := 'Indexed';
- else
- raise Exception.CreateFmt('Unknown color type: %s', [AFileName]);
- end;
- if VReader.Header.Compression <> 0 then
- raise Exception.CreateFmt('Unknown compression method: %s', [AFileName]);
- if VReader.Header.Filter <> 0 then
- raise Exception.CreateFmt('Unknown filter method: %s', [AFileName]);
- if VReader.Header.Interlace <> 0 then
- raise Exception.CreateFmt('Interlacing not supported: %s', [AFileName]);
- VHeight := VReader.Header.Height;
- VWidth := VReader.Header.Width;
- { TODO: implement compress/uncompress, trns, pal, index, flate etc. }
- WriteLn('h: ', VHeight, ' w: ', VWidth, ' bpc: ', VBitDepth,
- ' colspace: ', VColSpace);
- finally
- VReader.Free;
- VFile.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement