Big endian support kind of broke the nef decoding on my box.

I narrowed it down to the fact the NefDecoder constructor was
passed a copy instead of a ref. This caused a ByteStream instance
to be used in all cases, whatever the endianness, because the
copy constructor is called implicitly during argument passing.

Bonus fix for the Int swap reader, the pos+=4; statement wasn't
reachable. I also added a few casts to make sure the right thing
is done in the short read function.

Index: NikonDecompressor.h
===================================================================
--- NikonDecompressor.h (révision 248)
+++ NikonDecompressor.h (copie de travail)
@@ -32,7 +32,7 @@
   NikonDecompressor(FileMap* file, RawImage img );
 public:
   virtual ~NikonDecompressor(void);
-  void DecompressNikon(ByteStream meta, uint32 w, uint32 h, uint32 bitsPS, 
uint32 offset, uint32 size);
+  void DecompressNikon(ByteStream& meta, uint32 w, uint32 h, uint32 bitsPS, 
uint32 offset, uint32 size);
 private:
   void initTable(uint32 huffSelect);
   int HuffDecodeNikon();
Index: ByteStreamSwap.cpp
===================================================================
--- ByteStreamSwap.cpp  (révision 248)
+++ ByteStreamSwap.cpp  (copie de travail)
@@ -19,17 +19,23 @@
 ushort16 ByteStreamSwap::getShort() {
   if (off + 1 >= size)
     throw IOException("getShort: Out of buffer read");
-  uint32 a = buffer[off++];
-  uint32 b = buffer[off++];
-  return (a << 8) | b;
+  uint32 a = (uint32)buffer[off++];
+  uint32 b = (uint32)buffer[off++];
+  return (ushort16)((a << 8) | b);
 }
 
 /* NOTE: Actually unused, so not tested */
 int ByteStreamSwap::getInt() {
   if (off + 4 >= size)
     throw IOException("getInt: Out of buffer read");
-  return (int)buffer[off] << 24 | (int)buffer[off+1] << 16 | 
(int)buffer[off+2] << 8 | (int)buffer[off+3];
-  off+=4;
+  int r = (int)buffer[off++];
+  r <<= 8;
+  r |= (int)buffer[off++];
+  r <<= 8;
+  r |= (int)buffer[off++];
+  r <<= 8;
+  r |= (int)buffer[off++];
+  return r;
 }
 
 } // namespace RawSpeed
Index: NefDecoder.cpp
===================================================================
--- NefDecoder.cpp      (révision 248)
+++ NefDecoder.cpp      (copie de travail)
@@ -112,13 +112,13 @@
     NikonDecompressor decompressor(mFile, mRaw);
 
     // Nikon is JPEG (Big Endian) byte order
-    if (getHostEndianness() == big)
-      decompressor.DecompressNikon(ByteStream(meta->getData(), meta->count), 
-                                   width, height, bitPerPixel, 
offsets->getInt(), counts->getInt());
-    else
-      decompressor.DecompressNikon(ByteStreamSwap(meta->getData(), 
meta->count), 
-                                   width, height, bitPerPixel, 
offsets->getInt(), counts->getInt());
-
+    if (getHostEndianness() == big) {
+       ByteStream metadata(meta->getData(), meta->count);
+       decompressor.DecompressNikon(metadata, width, height, bitPerPixel, 
offsets->getInt(), counts->getInt());
+    } else {
+       ByteStreamSwap metadata(meta->getData(), meta->count);
+       decompressor.DecompressNikon(metadata, width, height, bitPerPixel, 
offsets->getInt(), counts->getInt());
+    }
   } catch (IOException e) {
     errors.push_back(_strdup(e.what()));
     // Let's ignore it, it may have delivered somewhat useful data.
Index: NikonDecompressor.cpp
===================================================================
--- NikonDecompressor.cpp       (révision 248)
+++ NikonDecompressor.cpp       (copie de travail)
@@ -53,7 +53,7 @@
   createHuffmanTable(dctbl1);
 }
 
-void NikonDecompressor::DecompressNikon(ByteStream metadata, uint32 w, uint32 
h, uint32 bitsPS, uint32 offset, uint32 size) {
+void NikonDecompressor::DecompressNikon(ByteStream& metadata, uint32 w, uint32 
h, uint32 bitsPS, uint32 offset, uint32 size) {
   uint32 v0 = metadata.getByte();
   uint32 v1 = metadata.getByte();
   uint32 huffSelect = 0;


-- 
Edouard Gomez

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

Reply via email to