From 2fd57665cf0d73b8c48482b8c971f648907f3af9 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 21 Apr 2015 11:08:19 +0000 Subject: [PATCH] * Patch from Zilvinas Ledas to implement reading of 12-bit TIFFs git-svn-id: trunk@30690 - --- packages/fcl-image/src/fpreadtiff.pas | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/fcl-image/src/fpreadtiff.pas b/packages/fcl-image/src/fpreadtiff.pas index 629bec8716..e6b0795181 100644 --- a/packages/fcl-image/src/fpreadtiff.pas +++ b/packages/fcl-image/src/fpreadtiff.pas @@ -213,8 +213,8 @@ begin for i:=0 to SampleCnt-1 do begin if SampleBits[i]>64 then TiffError('Samples bigger than 64 bit not supported'); - if not (SampleBits[i] in [1, 8, 16]) then - TiffError('Only samples of 1, 8 and 16 bit are supported'); + if not (SampleBits[i] in [1, 8, 12, 16]) then + TiffError('Only samples of 1, 8, 12 and 16 bit are supported'); inc(SampleBitsPerPixel, SampleBits[i]); end; case IFD.PhotoMetricInterpretation of @@ -228,8 +228,8 @@ begin IFD.AlphaBits:=AlphaBits; end; end; - if not (GrayBits in [1, 8, 16]) then - TiffError('gray image only supported with gray BitsPerSample 1, 8 or 16'); + if not (GrayBits in [1, 8, 12, 16]) then + TiffError('gray image only supported with gray BitsPerSample 1, 8, 12 or 16'); if not (AlphaBits in [0, 8, 16]) then TiffError('gray image only supported with alpha BitsPerSample 8 or 16'); end; @@ -366,6 +366,7 @@ procedure TFPReaderTiff.ReadImgValue(BitCount: Word; var Run: Pointer; x: dword; Predictor: word; var LastValue: word; out Value: Word); inline; var BitNumber: byte; + Byte1, Byte2: byte; begin case BitCount of 1: @@ -391,6 +392,18 @@ begin Value:=Value shl 8+Value; inc(Run); end; + 12: + begin + Byte1 := PCUInt8(Run)^; + Byte2 := PCUInt8(Run+1)^; + if (x mod 2) = 0 then begin + Value := (((Byte1) shl 4) or (Byte2 shr 4)) * 16; + inc(Run); + end else begin + Value := (((Byte1 and $0F) shl 8) or Byte2) * 16; + inc(Run, 2); + end; + end; 16: begin Value:=FixEndian(PCUInt16(Run)^); @@ -1973,7 +1986,7 @@ begin for i:=0 to ImageCount-1 do begin CurImg:=Images[i]; NewSize:=Int64(CurImg.ImageWidth)*CurImg.ImageHeight; - if (NewSize