瀏覽代碼

tif: open RGB with 4 samples as RGBA, issue #20148

git-svn-id: trunk@28747 -
Mattias Gaertner 10 年之前
父節點
當前提交
9cf1499851
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      packages/fcl-image/src/fpreadtiff.pas

+ 12 - 4
packages/fcl-image/src/fpreadtiff.pas

@@ -189,8 +189,8 @@ begin
   0, 1: if SampleCnt-ExtraSampleCnt<>1 then
     TiffError('gray images expect one sample per pixel, but found '+IntToStr(
       SampleCnt));
-  2: if SampleCnt-ExtraSampleCnt<>3 then
-    TiffError('rgb images expect three samples per pixel, but found '+IntToStr(
+  2: if (SampleCnt-ExtraSampleCnt<>3) and (SampleCnt-ExtraSampleCnt<>4) then
+    TiffError('rgb(a) images expect three or four samples per pixel, but found '+IntToStr(
       SampleCnt));
   3: if SampleCnt-ExtraSampleCnt<>1 then
     TiffError('palette images expect one sample per pixel, but found '+IntToStr(
@@ -238,10 +238,15 @@ begin
       RedBits:=SampleBits[0];
       GreenBits:=SampleBits[1];
       BlueBits:=SampleBits[2];
+      if SampleCnt=4 then
+        AlphaBits:=SampleBits[3];
       IFD.RedBits:=RedBits;
       IFD.GreenBits:=GreenBits;
       IFD.BlueBits:=BlueBits;
-      IFD.AlphaBits:=0;
+      if SampleCnt=4 then
+        IFD.AlphaBits:=AlphaBits
+      else
+        IFD.AlphaBits:=0;
       for i:=0 to ExtraSampleCnt-1 do begin
         //writeln('  ',i,'/',ExtraSampleCnt,' Type=',ExtraSamples[i],' Count=',SampleBits[3+i]);
         if ExtraSamples[i] in [1, 2] then begin
@@ -1822,7 +1827,10 @@ begin
               ReadImgValue(RedBits,Run,cx,IFD.Predictor,LastRedValue,RedValue);
               ReadImgValue(GreenBits,Run,cx,IFD.Predictor,LastGreenValue,GreenValue);
               ReadImgValue(BlueBits,Run,cx,IFD.Predictor,LastBlueValue,BlueValue);
-              AlphaValue:=alphaOpaque;
+              if SampleBitsPerPixel=32 then
+                ReadImgValue(AlphaBits,Run,cx,IFD.Predictor,LastAlphaValue,AlphaValue)
+              else
+                AlphaValue:=alphaOpaque;
               for i:=0 to ExtraSampleCnt-1 do begin
                 if ExtraSamples[i] in [1,2] then begin
                   ReadImgValue(AlphaBits,Run,cx,IFD.Predictor,LastAlphaValue,AlphaValue);