Author: post
Date: 2014-01-12 20:27:31 +0100 (Sun, 12 Jan 2014)
New Revision: 612

Modified:
   RawSpeed/BitPumpMSB.cpp
   RawSpeed/BitPumpMSB.h
   RawSpeed/NikonDecompressor.cpp
   RawSpeed/NikonDecompressor.h
Log:
Speed up Bitpump and Nikon Decoder, patch by Prakash Punnoor.

Modified: RawSpeed/BitPumpMSB.cpp
===================================================================
--- RawSpeed/BitPumpMSB.cpp     2014-01-06 18:56:58 UTC (rev 611)
+++ RawSpeed/BitPumpMSB.cpp     2014-01-12 19:27:31 UTC (rev 612)
@@ -40,9 +40,6 @@
 
 __inline void BitPumpMSB::init() {
   mStuffed = 0;
-  current_buffer = (uchar8*)_aligned_malloc(16, 16);
-  if (!current_buffer)
-    ThrowRDE("BitPumpMSB::init(): Unable to allocate memory");
   memset(current_buffer,0,16);
   fill();
 }
@@ -122,11 +119,5 @@
   fill();
 }
 
-
-
-BitPumpMSB::~BitPumpMSB(void) {
-       _aligned_free(current_buffer);
-}
-
 } // namespace RawSpeed
 

Modified: RawSpeed/BitPumpMSB.h
===================================================================
--- RawSpeed/BitPumpMSB.h       2014-01-06 18:56:58 UTC (rev 611)
+++ RawSpeed/BitPumpMSB.h       2014-01-12 19:27:31 UTC (rev 612)
@@ -126,11 +126,10 @@
     return ret & 0xff;
   }
 
-  virtual ~BitPumpMSB(void);
 protected:
   void __inline init();
+  uchar8 current_buffer[16];
   const uchar8* buffer;
-  uchar8* current_buffer;
   const uint32 size;            // This if the end of buffer.
   uint32 mLeft;
   uint32 off;                  // Offset in bytes

Modified: RawSpeed/NikonDecompressor.cpp
===================================================================
--- RawSpeed/NikonDecompressor.cpp      2014-01-06 18:56:58 UTC (rev 611)
+++ RawSpeed/NikonDecompressor.cpp      2014-01-12 19:27:31 UTC (rev 612)
@@ -1,5 +1,7 @@
 #include "StdAfx.h"
 #include "NikonDecompressor.h"
+#include "BitPumpMSB.h"
+
 /*
     RawSpeed - RAW file decoder.
 
@@ -29,15 +31,8 @@
   for (uint32 i = 0; i < 0x8000 ; i++) {
     curve[i]  = i;
   }
-  bits = 0;
 }
 
-NikonDecompressor::~NikonDecompressor(void) {
-  if (bits)
-    delete(bits);
-  bits = 0;
-
-}
 void NikonDecompressor::initTable(uint32 huffSelect) {
   HuffmanTable *dctbl1 = &huff[0];
   uint32 acc = 0;
@@ -104,7 +99,7 @@
     curve[i] = top;
 
   uint32 x, y;
-  bits = new BitPumpMSB(mFile->getData(offset), size);
+  BitPumpMSB bits(mFile->getData(offset), size);
   uchar8 *draw = mRaw->getData();
   uint32 *dest;
   uint32 pitch = mRaw->pitch;
@@ -118,15 +113,15 @@
       initTable(huffSelect + 1);
     }
     dest = (uint32*) & draw[y*pitch];  // Adjust destination
-    pUp1[y&1] += HuffDecodeNikon();
-    pUp2[y&1] += HuffDecodeNikon();
+    pUp1[y&1] += HuffDecodeNikon(bits);
+    pUp2[y&1] += HuffDecodeNikon(bits);
     pLeft1 = pUp1[y&1];
     pLeft2 = pUp2[y&1];
     dest[0] = curve[clampbits(pLeft1,15)] | 
((uint32)curve[clampbits(pLeft2,15)] << 16);
     for (x = 1; x < cw; x++) {
-      bits->checkPos();
-      pLeft1 += HuffDecodeNikon();
-      pLeft2 += HuffDecodeNikon();
+      bits.checkPos();
+      pLeft1 += HuffDecodeNikon(bits);
+      pLeft2 += HuffDecodeNikon(bits);
       dest[x] = curve[clampbits(pLeft1,15)] | 
((uint32)curve[clampbits(pLeft2,15)] << 16);
     }
   }
@@ -148,33 +143,33 @@
 *
 *--------------------------------------------------------------
 */
-int NikonDecompressor::HuffDecodeNikon() {
+int NikonDecompressor::HuffDecodeNikon(BitPumpMSB& bits) {
   int rv;
   int l, temp;
   int code, val ;
 
   HuffmanTable *dctbl1 = &huff[0];
 
-  bits->fill();
-  code = bits->peekBitsNoFill(14);
+  bits.fill();
+  code = bits.peekBitsNoFill(14);
   val = dctbl1->bigTable[code];
   if ((val&0xff) !=  0xff) {
-    bits->skipBitsNoFill(val&0xff);
+    bits.skipBitsNoFill(val&0xff);
     return val >> 8;
   }
 
   rv = 0;
-  code = bits->peekByteNoFill();
+  code = bits.peekByteNoFill();
   val = dctbl1->numbits[code];
   l = val & 15;
   if (l) {
-    bits->skipBitsNoFill(l);
+    bits.skipBitsNoFill(l);
     rv = val >> 4;
   }  else {
-    bits->skipBits(8);
+    bits.skipBits(8);
     l = 8;
     while (code > dctbl1->maxcode[l]) {
-      temp = bits->getBitNoFill();
+      temp = bits.getBitNoFill();
       code = (code << 1) | temp;
       l++;
     }
@@ -196,7 +191,7 @@
   */
   uint32 len = rv & 15;
   uint32 shl = rv >> 4;
-  int diff = ((bits->getBits(len - shl) << 1) + 1) << shl >> 1;
+  int diff = ((bits.getBits(len - shl) << 1) + 1) << shl >> 1;
   if ((diff & (1 << (len - 1))) == 0)
     diff -= (1 << len) - !shl;
   return diff;

Modified: RawSpeed/NikonDecompressor.h
===================================================================
--- RawSpeed/NikonDecompressor.h        2014-01-06 18:56:58 UTC (rev 611)
+++ RawSpeed/NikonDecompressor.h        2014-01-12 19:27:31 UTC (rev 612)
@@ -1,11 +1,10 @@
 #ifndef NIKON_DECOMPRESSOR_H
-#define NIKON_DECOMPRESSOR_H
-
-#include "LJpegDecompressor.h"
-#include "BitPumpMSB.h"
-/* 
-    RawSpeed - RAW file decoder.
-
+#define NIKON_DECOMPRESSOR_H
+
+#include "LJpegDecompressor.h"
+/* 
+    RawSpeed - RAW file decoder.
+
     Copyright (C) 2009 Klaus Post
 
     This library is free software; you can redistribute it and/or
@@ -24,26 +23,26 @@
 
     http://www.klauspost.com
 */
-
-namespace RawSpeed {
-
-class NikonDecompressor :
-  public LJpegDecompressor
-{
-public:
-  NikonDecompressor(FileMap* file, RawImage img );
-public:
-  virtual ~NikonDecompressor(void);
-  void DecompressNikon(ByteStream *meta, uint32 w, uint32 h, uint32 bitsPS, 
uint32 offset, uint32 size);
-  bool uncorrectedRawValues;
-private:
-  void initTable(uint32 huffSelect);
-  int HuffDecodeNikon();
-  ushort16 curve[0x8000];
-  BitPumpMSB *bits;
-};
-
-static const uchar8 nikon_tree[][32] = {
+
+namespace RawSpeed {
+
+class BitPumpMSB;
+
+class NikonDecompressor :
+  public LJpegDecompressor
+{
+public:
+  NikonDecompressor(FileMap* file, RawImage img );
+public:
+  void DecompressNikon(ByteStream *meta, uint32 w, uint32 h, uint32 bitsPS, 
uint32 offset, uint32 size);
+  bool uncorrectedRawValues;
+private:
+  void initTable(uint32 huffSelect);
+  int HuffDecodeNikon(BitPumpMSB& bits);
+  ushort16 curve[0x8000];
+};
+
+static const uchar8 nikon_tree[][32] = {
   { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,   /* 12-bit lossy */
   5,4,3,6,2,7,1,0,8,9,11,10,12 },
   { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,   /* 12-bit lossy after split */


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

Reply via email to