Author: post
Date: 2010-10-28 22:31:37 +0200 (Thu, 28 Oct 2010)
New Revision: 283

Modified:
   RawSpeed/NefDecoder.cpp
   RawSpeed/NikonDecompressor.cpp
Log:
Apparently Nikon doesn't mind underflows in their LJPEG encoded images.

Modified: RawSpeed/NefDecoder.cpp
===================================================================
--- RawSpeed/NefDecoder.cpp     2010-10-28 19:51:17 UTC (rev 282)
+++ RawSpeed/NefDecoder.cpp     2010-10-28 20:31:37 UTC (rev 283)
@@ -28,7 +28,7 @@
 
 NefDecoder::NefDecoder(TiffIFD *rootIFD, FileMap* file) :
     RawDecoder(file), mRootIFD(rootIFD) {
-  decoderVersion = 1;
+  decoderVersion = 2;
 }
 
 NefDecoder::~NefDecoder(void) {

Modified: RawSpeed/NikonDecompressor.cpp
===================================================================
--- RawSpeed/NikonDecompressor.cpp      2010-10-28 19:51:17 UTC (rev 282)
+++ RawSpeed/NikonDecompressor.cpp      2010-10-28 20:31:37 UTC (rev 283)
@@ -75,7 +75,7 @@
   pUp2[0] = metadata->getShort();
   pUp2[1] = metadata->getShort();
 
-  uint32 _max = 1 << bitsPS & 0x7fff;
+  int _max = 1 << bitsPS & 0x7fff;
   uint32 step = 0;
   uint32 csize = metadata->getShort();
   if (csize  > 1)
@@ -83,7 +83,7 @@
   if (v0 == 68 && v1 == 32 && step > 0) {
     for (uint32 i = 0; i < csize; i++)
       curve[i*step] = metadata->getShort();
-    for (uint32 i = 0; i < _max; i++)
+    for (int i = 0; i < _max; i++)
       curve[i] = (curve[i-i%step] * (step - i % step) +
                   curve[i-i%step+step] * (i % step)) / step;
     metadata->setAbsoluteOffset(562);
@@ -123,9 +123,7 @@
     for (x = 1; x < cw; x++) {
       pLeft1 += HuffDecodeNikon();
       pLeft2 += HuffDecodeNikon();
-      if (pLeft1 < 0 || pLeft1 > 65535 || pLeft2 < 0 || pLeft2 > 65535)
-        ThrowIOE("DecompressNikon: Image value out of range. Corrupt image.");
-      dest[x] =  curve[pLeft1] | (curve[pLeft2] << 16);
+      dest[x] =  curve[MIN(_max-1, MAX(0,pLeft1))] | (curve[MIN(_max-1, 
MAX(0,pLeft2))] << 16);
     }
   }
 }


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to