Author: post
Date: 2009-12-20 11:52:05 +0100 (Sun, 20 Dec 2009)
New Revision: 177

Modified:
   RawSpeed/BitPumpJPEG.h
   RawSpeed/LJpegDecompressor.cpp
   RawSpeed/LJpegPlain.cpp
   RawSpeed/NikonDecompressor.cpp
   RawSpeed/PentaxDecompressor.cpp
Log:
Moved some checks from debug assertions to runtime checks, as they could be 
triggered by corrupted data.
Skipping a few unneeded fill checks in LJPEG, faster decoding.

Modified: RawSpeed/BitPumpJPEG.h
===================================================================
--- RawSpeed/BitPumpJPEG.h      2009-12-20 08:34:13 UTC (rev 176)
+++ RawSpeed/BitPumpJPEG.h      2009-12-20 10:52:05 UTC (rev 177)
@@ -40,6 +40,7 @@
        guint peekBit();
   guint peekByte();
   void skipBits(guint nbits);
+  __inline void skipBitsNoFill(guint nbits){ mLeft -= nbits; }
   __inline void checkPos()  { if (off>size) throw IOException("Out of buffer 
read");};        // Check if we have a valid position
        guchar getByte();
        guchar getByteSafe();

Modified: RawSpeed/LJpegDecompressor.cpp
===================================================================
--- RawSpeed/LJpegDecompressor.cpp      2009-12-20 08:34:13 UTC (rev 176)
+++ RawSpeed/LJpegDecompressor.cpp      2009-12-20 10:52:05 UTC (rev 177)
@@ -529,7 +529,7 @@
     code = bits->peekBitsNoFill(14);
     val = htbl->bigTable[code];
     if ((val&0xff) !=  0xff) {
-      bits->skipBits(val&0xff);
+      bits->skipBitsNoFill(val&0xff);
       return val >> 8;
     }
   }
@@ -543,10 +543,10 @@
   val = htbl->numbits[code];
   l = val & 15;
   if (l) {
-    bits->skipBits(l);
+    bits->skipBitsNoFill(l);
     rv = val >> 4;
   }  else {
-    bits->skipBits(8);
+    bits->skipBitsNoFill(8);
     l = 8;
     while (code > htbl->maxcode[l]) {
       temp = bits->getBitNoFill();
@@ -568,7 +568,7 @@
 
   if (rv == 16) {
     if (mDNGCompatible)
-      bits->skipBits(16);
+      bits->skipBitsNoFill(16);
     return -32768;
   }
 

Modified: RawSpeed/LJpegPlain.cpp
===================================================================
--- RawSpeed/LJpegPlain.cpp     2009-12-20 08:34:13 UTC (rev 176)
+++ RawSpeed/LJpegPlain.cpp     2009-12-20 10:52:05 UTC (rev 177)
@@ -212,10 +212,12 @@
     for (; x < cw ; x += maxSuperH) {
 
       if (0 == pixInSlice) { // Next slice
-        _ASSERTE(slice < slices);
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
-        _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         pixInSlice = slice_width[o>>28];
 
         // If new are at the start of a new line, also update predictors.
@@ -346,9 +348,13 @@
     for (; x < cw ; x += 2) {
 
       if (0 == pixInSlice) { // Next slice
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
         _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         pixInSlice = slice_width[o>>28];
 
         // If new are at the start of a new line, also update predictors.
@@ -466,9 +472,12 @@
     for (; x < cw ; x += 2) {
 
       if (0 == pixInSlice) { // Next slice
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
-        _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         pixInSlice = slice_width[o>>28];
 
         // If new are at the start of a new line, also update predictors.
@@ -556,17 +565,20 @@
       gint diff = HuffDecode(dctbl1);
       p1 += diff;
       *dest++ = (gushort)p1;
-      _ASSERTE(p1 >= 0 && p1 < 65536);
+  //    _ASSERTE(p1 >= 0 && p1 < 65536);
 
       diff = HuffDecode(dctbl2);
       p2 += diff;
       *dest++ = (gushort)p2;
-      _ASSERTE(p2 >= 0 && p2 < 65536);
+//      _ASSERTE(p2 >= 0 && p2 < 65536);
 
       if (0 == --pixInSlice) { // Next slice
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
-        _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         pixInSlice = slice_width[o>>28];
       }
       bits->checkPos();
@@ -653,9 +665,12 @@
       *dest++ = (gushort)p3;
 
       if (0 == --pixInSlice) { // Next slice
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
-        _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         _ASSERTE((o >> 28) < slicesW.size());
         pixInSlice = slice_width[o>>28];
       }
@@ -750,9 +765,12 @@
       *dest++ = (gushort)p4;
 
       if (0 == --pixInSlice) { // Next slice
+        if (slice > slices)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Ran out of slices");
         guint o = offset[slice++];
         dest = (gushort*) & draw[o&0x0fffffff];  // Adjust destination for 
next pixel
-        _ASSERTE((o&0x0fffffff) < mRaw->pitch*mRaw->dim.y);
+        if((o&0x0fffffff) > mRaw->pitch*mRaw->dim.y)
+          ThrowRDE("LJpegPlain::decodeScanLeft: Offset out of bounds");
         pixInSlice = slice_width[o>>28];
       }
       bits->checkPos();

Modified: RawSpeed/NikonDecompressor.cpp
===================================================================
--- RawSpeed/NikonDecompressor.cpp      2009-12-20 08:34:13 UTC (rev 176)
+++ RawSpeed/NikonDecompressor.cpp      2009-12-20 10:52:05 UTC (rev 177)
@@ -157,7 +157,7 @@
   code = bits->peekBitsNoFill(14);
   val = dctbl1->bigTable[code];
   if ((val&0xff) !=  0xff) {
-    bits->skipBits(val&0xff);
+    bits->skipBitsNoFill(val&0xff);
     return val >> 8;
   }
 
@@ -166,7 +166,7 @@
   val = dctbl1->numbits[code];
   l = val & 15;
   if (l) {
-    bits->skipBits(l);
+    bits->skipBitsNoFill(l);
     rv = val >> 4;
   }  else {
     bits->skipBits(8);

Modified: RawSpeed/PentaxDecompressor.cpp
===================================================================
--- RawSpeed/PentaxDecompressor.cpp     2009-12-20 08:34:13 UTC (rev 176)
+++ RawSpeed/PentaxDecompressor.cpp     2009-12-20 10:52:05 UTC (rev 177)
@@ -115,7 +115,7 @@
   code = pentaxBits->peekBitsNoFill(14);
   val = dctbl1->bigTable[code];
   if ((val&0xff) !=  0xff) {
-    pentaxBits->skipBits(val&0xff);
+    pentaxBits->skipBitsNoFill(val&0xff);
     return val >> 8;
   }
 
@@ -124,7 +124,7 @@
   val = dctbl1->numbits[code];
   l = val & 15;
   if (l) {
-    pentaxBits->skipBits(l);
+    pentaxBits->skipBitsNoFill(l);
     rv = val >> 4;
   }  else {
     pentaxBits->skipBits(8);
@@ -156,7 +156,7 @@
   */
 
   if (rv) {
-    gint x = pentaxBits->getBitsNoFill(rv);
+    gint x = pentaxBits->getBits(rv);
     if ((x & (1 << (rv - 1))) == 0)
       x -= (1 << rv) - 1;
     return x;


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

Reply via email to