Author: post
Date: 2012-11-10 15:25:50 +0100 (Sat, 10 Nov 2012)
New Revision: 491

Modified:
   RawSpeed/BitPumpMSB32.h
   RawSpeed/BitPumpPlain.h
   RawSpeed/Common.h
   RawSpeed/DngDecoder.cpp
   RawSpeed/NefDecoder.cpp
   RawSpeed/OrfDecoder.cpp
   RawSpeed/PefDecoder.cpp
   RawSpeed/RawDecoder.cpp
   RawSpeed/RawDecoder.h
   RawSpeed/RawImageDataU16.cpp
   RawSpeed/Rw2Decoder.cpp
   RawSpeed/SrwDecoder.cpp
Log:
Add support for uncompressed ORF images, and make MSB32 bit order available 
through the generic decoder.

Modified: RawSpeed/BitPumpMSB32.h
===================================================================
--- RawSpeed/BitPumpMSB32.h     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/BitPumpMSB32.h     2012-11-10 14:25:50 UTC (rev 491)
@@ -64,6 +64,16 @@
     return (uint32)((mCurr >> (mLeft -= (nbits))) & ((1 << nbits) - 1));
   }
 
+  __inline void skipBits(unsigned int nbits) {
+    while (nbits) {
+      fill();
+      checkPos();
+      int n = MIN(nbits, mLeft);
+      mLeft -= n;
+      nbits -= n;
+    }
+  }
+
   virtual ~BitPumpMSB32(void);
 protected:
   void __inline init();

Modified: RawSpeed/BitPumpPlain.h
===================================================================
--- RawSpeed/BitPumpPlain.h     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/BitPumpPlain.h     2012-11-10 14:25:50 UTC (rev 491)
@@ -33,13 +33,13 @@
 public:
   BitPumpPlain(ByteStream *s);
   BitPumpPlain(const uchar8* _buffer, uint32 _size );
-       uint32 getBits(uint32 nbits);
-       uint32 getBit();
+       uint32 getBits(uint32 nbits) throw ();
+       uint32 getBit() throw ();
        uint32 getBitsSafe(uint32 nbits);
        uint32 getBitSafe();
-       uint32 peekBits(uint32 nbits);
-       uint32 peekBit();
-  uint32 peekByte();
+       uint32 peekBits(uint32 nbits) throw ();
+       uint32 peekBit() throw ();
+  uint32 peekByte() throw ();
   void skipBits(uint32 nbits);
        uchar8 getByte();
        uchar8 getByteSafe();

Modified: RawSpeed/Common.h
===================================================================
--- RawSpeed/Common.h   2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/Common.h   2012-11-10 14:25:50 UTC (rev 491)
@@ -182,6 +182,12 @@
 
   return result;
 }
+
+typedef enum {
+  BitOrder_Plain,  /* Memory order */
+  BitOrder_Jpeg,   /* Input is added to stack byte by byte, and output is 
lifted from top */
+  BitOrder_Jpeg32, /* Same as above, but 32 bits at the time */
+} BitOrder;
 
 } // namespace RawSpeed
 

Modified: RawSpeed/DngDecoder.cpp
===================================================================
--- RawSpeed/DngDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/DngDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -216,7 +216,7 @@
           if (bps != 8 && bps != 16)
             big_endian = true;
           try {
-            readUncompressedRaw(in, size, pos, width*bps / 8, bps, big_endian);
+            readUncompressedRaw(in, size, pos, width*bps / 8, bps, big_endian 
? BitOrder_Jpeg : BitOrder_Plain);
           } catch(IOException &ex) {
             if (i > 0)
               mRaw->setError(ex.what());

Modified: RawSpeed/NefDecoder.cpp
===================================================================
--- RawSpeed/NefDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/NefDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -218,7 +218,7 @@
       else if (hints.find(string("coolpixsplit")) != hints.end())
         readCoolpixSplitRaw(in, size, pos, width*bitPerPixel / 8);
       else
-        readUncompressedRaw(in, size, pos, width*bitPerPixel / 8, bitPerPixel, 
bitorder);
+        readUncompressedRaw(in, size, pos, width*bitPerPixel / 8, bitPerPixel, 
bitorder ? BitOrder_Jpeg : BitOrder_Plain);
     } catch (RawDecoderException e) {
       if (i>0)
         mRaw->setError(e.what());

Modified: RawSpeed/OrfDecoder.cpp
===================================================================
--- RawSpeed/OrfDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/OrfDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -30,6 +30,7 @@
 
 OrfDecoder::OrfDecoder(TiffIFD *rootIFD, FileMap* file):
     RawDecoder(file), mRootIFD(rootIFD) {
+      decoderVersion = 2;
 }
 
 OrfDecoder::~OrfDecoder(void) {
@@ -61,6 +62,7 @@
   }
   uint32 width = raw->getEntry(IMAGEWIDTH)->getInt();
   uint32 height = raw->getEntry(IMAGELENGTH)->getInt();
+  uint32 bps = raw->getEntry(BITSPERSAMPLE)->getInt();
 
   if (!mFile->isValid(offsets->getInt() + counts->getInt()))
     ThrowRDE("ORF Decoder: Truncated file");
@@ -92,6 +94,11 @@
   // We add 3 bytes slack, since the bitpump might be a few bytes ahead.
   ByteStream s(mFile->getData(offsets->getInt()), counts->getInt() + 3);
 
+  if ((hints.find(string("force_uncompressed")) != hints.end())) {
+    readUncompressedRaw(ByteStream(mFile->getData(offsets->getInt()), 
counts->getInt() + 3), iPoint2D(width, height),iPoint2D(0,0),width*bps/8,bps, 
BitOrder_Jpeg32);
+    return mRaw;
+  }
+
   try {
     decodeCompressed(s, width, height);
   } catch (IOException &e) {

Modified: RawSpeed/PefDecoder.cpp
===================================================================
--- RawSpeed/PefDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/PefDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -46,7 +46,7 @@
   int compression = raw->getEntry(COMPRESSION)->getInt();
 
   if (1 == compression) {
-    decodeUncompressed(raw, true);
+    decodeUncompressed(raw, BitOrder_Jpeg);
     return mRaw;
   }
 

Modified: RawSpeed/RawDecoder.cpp
===================================================================
--- RawSpeed/RawDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/RawDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -32,7 +32,7 @@
 RawDecoder::~RawDecoder(void) {
 }
 
-void RawDecoder::decodeUncompressed(TiffIFD *rawIFD, bool MSBOrder) {
+void RawDecoder::decodeUncompressed(TiffIFD *rawIFD, BitOrder order) {
   uint32 nslices = rawIFD->getEntry(STRIPOFFSETS)->count;
   const uint32 *offsets = rawIFD->getEntry(STRIPOFFSETS)->getIntArray();
   const uint32 *counts = rawIFD->getEntry(STRIPBYTECOUNTS)->getIntArray();
@@ -74,7 +74,7 @@
     iPoint2D pos(0, offY);
     bitPerPixel = (int)((uint64)(slice.count * 8) / (slice.h * width));
     try {
-      readUncompressedRaw(in, size, pos, width*bitPerPixel / 8, bitPerPixel, 
MSBOrder);
+      readUncompressedRaw(in, size, pos, width*bitPerPixel / 8, bitPerPixel, 
order);
     } catch (RawDecoderException &e) {
       if (i>0)
         mRaw->setError(e.what());
@@ -90,7 +90,7 @@
   }
 }
 
-void RawDecoder::readUncompressedRaw(ByteStream &input, iPoint2D& size, 
iPoint2D& offset, int inputPitch, int bitPerPixel, bool MSBOrder) {
+void RawDecoder::readUncompressedRaw(ByteStream &input, iPoint2D& size, 
iPoint2D& offset, int inputPitch, int bitPerPixel, BitOrder order) {
   uchar8* data = mRaw->getData();
   uint32 outPitch = mRaw->pitch;
   uint32 w = size.x;
@@ -124,7 +124,7 @@
     return;
   }
 
-  if (MSBOrder) {
+  if (BitOrder_Jpeg == order) {
     BitPumpMSB bits(&input);
     w *= cpp;
     for (; y < h; y++) {
@@ -136,6 +136,18 @@
       }
       bits.skipBits(skipBits);
     }
+  } else if (BitOrder_Jpeg32 == order) {
+      BitPumpMSB32 bits(&input);
+      w *= cpp;
+      for (; y < h; y++) {
+        ushort16* dest = (ushort16*) & 
data[offset.x*sizeof(ushort16)*cpp+y*outPitch];
+        bits.checkPos();
+        for (uint32 x = 0 ; x < w; x++) {
+          uint32 b = bits.getBits(bitPerPixel);
+          dest[x] = b;
+        }
+        bits.skipBits(skipBits);
+      }
 
   } else {
 

Modified: RawSpeed/RawDecoder.h
===================================================================
--- RawSpeed/RawDecoder.h       2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/RawDecoder.h       2012-11-10 14:25:50 UTC (rev 491)
@@ -6,6 +6,7 @@
 #include "BitPumpJPEG.h" // Includes bytestream
 #include "RawImage.h"
 #include "BitPumpMSB.h"
+#include "BitPumpMSB32.h"
 #include "BitPumpPlain.h"
 #include "CameraMetaData.h"
 #include "TiffIFD.h"
@@ -92,7 +93,6 @@
   /* DNGs are always attempted to be decoded, so this variable has no effect 
on DNGs */
   bool failOnUnknown;
 
-
 protected:
   /* Attempt to decode the image */
   /* A RawDecoderException will be thrown if the image cannot be decoded, */
@@ -123,15 +123,15 @@
   /* offset: offset to write the data into the final image */
   /* inputPitch: Number of bytes between each line in the input image */
   /* bitPerPixel: Number of bits to read for each input pixel. */
-  /* MSBOrder: true -  bits are read from MSB (JPEG style) False: Read from 
LSB. */
-  void readUncompressedRaw(ByteStream &input, iPoint2D& size, iPoint2D& 
offset, int inputPitch, int bitPerPixel, bool MSBOrder);
+  /* order: Order of the bits - see Common.h for possibilities. */
+  void readUncompressedRaw(ByteStream &input, iPoint2D& size, iPoint2D& 
offset, int inputPitch, int bitPerPixel, BitOrder order);
 
   /* Faster version for unpacking 12 bit LSB data */
   void Decode12BitRaw(ByteStream &input, uint32 w, uint32 h);
 
   /* Generic decompressor for uncompressed images */
-  /* MSBOrder: true -  bits are read from MSB (JPEG style) False: Read from 
LSB. */
-  void decodeUncompressed(TiffIFD *rawIFD, bool MSBOrder);
+  /* order: Order of the bits - see Common.h for possibilities. */
+  void decodeUncompressed(TiffIFD *rawIFD, BitOrder order);
 
   /* The Raw input file to be decoded */
   FileMap *mFile; 

Modified: RawSpeed/RawImageDataU16.cpp
===================================================================
--- RawSpeed/RawImageDataU16.cpp        2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/RawImageDataU16.cpp        2012-11-10 14:25:50 UTC (rev 491)
@@ -118,7 +118,7 @@
 void RawImageDataU16::scaleBlackWhite() {
   const int skipBorder = 250;
   int gw = (dim.x - skipBorder) * cpp;
-  if ((blackAreas.empty() && blackLevelSeparate[0] < 0 && blackLevel < 0) || 
whitePoint == 65536) {  // Estimate
+  if ((blackAreas.empty() && blackLevelSeparate[0] < 0 && blackLevel < 0) || 
whitePoint >= 65536) {  // Estimate
     int b = 65536;
     int m = 0;
     for (int row = skipBorder*cpp;row < (dim.y - skipBorder);row++) {
@@ -131,7 +131,7 @@
     }
     if (blackLevel < 0)
       blackLevel = b;
-    if (whitePoint == 65536)
+    if (whitePoint >= 65536)
       whitePoint = m;
     printf("ISO:%d, Estimated black:%d, Estimated white: %d\n", isoSpeed, 
blackLevel, whitePoint);
   }
@@ -144,7 +144,8 @@
   if (blackLevelSeparate[0] < 0)
     calculateBlackAreas();
 
-  //printf("ISO:%d, black:%d, white: %d\n", isoSpeed, blackLevelSeparate[0], 
whitePoint);
+//  printf("ISO:%d, black[0]:%d, white: %d\n", isoSpeed, 
blackLevelSeparate[0], whitePoint);
+//  printf("black[1]:%d, black[2]:%d, black[3]:%d\n", blackLevelSeparate[1], 
blackLevelSeparate[2], blackLevelSeparate[3]);
 
   int threads = getThreadCount(); 
   if (threads <= 1)

Modified: RawSpeed/Rw2Decoder.cpp
===================================================================
--- RawSpeed/Rw2Decoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/Rw2Decoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -77,7 +77,7 @@
     mRaw->createData();
     ByteStream input_start(mFile->getData(off), mFile->getSize() - off);
     iPoint2D pos(0, 0);
-    readUncompressedRaw(input_start, mRaw->dim,pos, width*2, 16, FALSE);
+    readUncompressedRaw(input_start, mRaw->dim,pos, width*2, 16, 
BitOrder_Plain);
 
   } else {
 

Modified: RawSpeed/SrwDecoder.cpp
===================================================================
--- RawSpeed/SrwDecoder.cpp     2012-11-10 13:02:46 UTC (rev 490)
+++ RawSpeed/SrwDecoder.cpp     2012-11-10 14:25:50 UTC (rev 491)
@@ -59,7 +59,7 @@
     map<string,string>::iterator msb_hint = hints.find("msb_override");
     if (msb_hint != hints.end())
       bit_order = (0 == (msb_hint->second).compare("true"));
-    this->decodeUncompressed(raw, bit_order);
+    this->decodeUncompressed(raw, bit_order ? BitOrder_Jpeg : BitOrder_Plain);
     return mRaw;
   }
 
@@ -69,7 +69,7 @@
     map<string,string>::iterator msb_hint = hints.find("msb_override");
     if (msb_hint != hints.end())
       bit_order = (0 == (msb_hint->second).compare("true"));
-    this->decodeUncompressed(raw, bit_order);
+    this->decodeUncompressed(raw, bit_order ? BitOrder_Jpeg : BitOrder_Plain);
     return mRaw;
   }
   ThrowRDE("Srw Decoder: Unsupported compression");


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

Reply via email to