Author: post
Date: 2010-11-14 13:37:27 +0100 (Sun, 14 Nov 2010)
New Revision: 292
Modified:
RawSpeed/PefDecoder.cpp
RawSpeed/RawDecoder.cpp
RawSpeed/RawDecoder.h
Log:
Add support for Pentax uncompressed images (high ISO).
Modified: RawSpeed/PefDecoder.cpp
===================================================================
--- RawSpeed/PefDecoder.cpp 2010-11-14 08:04:51 UTC (rev 291)
+++ RawSpeed/PefDecoder.cpp 2010-11-14 12:37:27 UTC (rev 292)
@@ -26,7 +26,7 @@
PefDecoder::PefDecoder(TiffIFD *rootIFD, FileMap* file) :
RawDecoder(file), mRootIFD(rootIFD) {
- decoderVersion = 0;
+ decoderVersion = 1;
}
PefDecoder::~PefDecoder(void) {
@@ -41,6 +41,12 @@
TiffIFD* raw = data[0];
int compression = raw->getEntry(COMPRESSION)->getInt();
+
+ if (1 == compression) {
+ decodeUncompressed(raw);
+ return mRaw;
+ }
+
if (65535 != compression)
ThrowRDE("PEF Decoder: Unsupported compression");
Modified: RawSpeed/RawDecoder.cpp
===================================================================
--- RawSpeed/RawDecoder.cpp 2010-11-14 08:04:51 UTC (rev 291)
+++ RawSpeed/RawDecoder.cpp 2010-11-14 12:37:27 UTC (rev 292)
@@ -35,6 +35,65 @@
errors.clear();
}
+void RawDecoder::decodeUncompressed(TiffIFD *rawIFD) {
+ uint32 nslices = rawIFD->getEntry(STRIPOFFSETS)->count;
+ const uint32 *offsets = rawIFD->getEntry(STRIPOFFSETS)->getIntArray();
+ const uint32 *counts = rawIFD->getEntry(STRIPBYTECOUNTS)->getIntArray();
+ uint32 yPerSlice = rawIFD->getEntry(ROWSPERSTRIP)->getInt();
+ uint32 width = rawIFD->getEntry(IMAGEWIDTH)->getInt();
+ uint32 height = rawIFD->getEntry(IMAGELENGTH)->getInt();
+ uint32 bitPerPixel = rawIFD->getEntry(BITSPERSAMPLE)->getInt();
+
+ vector<RawSlice> slices;
+ uint32 offY = 0;
+
+ for (uint32 s = 0; s < nslices; s++) {
+ RawSlice slice;
+ slice.offset = offsets[s];
+ slice.count = counts[s];
+ if (offY + yPerSlice > height)
+ slice.h = height - offY;
+ else
+ slice.h = yPerSlice;
+
+ offY += yPerSlice;
+
+ if (mFile->isValid(slice.offset + slice.count)) // Only decode if size is
valid
+ slices.push_back(slice);
+ }
+
+ if (0 == slices.size())
+ ThrowRDE("RAW Decoder: No valid slices found. File probably truncated.");
+
+ mRaw->dim = iPoint2D(width, offY);
+ mRaw->bpp = 2;
+ mRaw->createData();
+ mRaw->whitePoint = (1<<bitPerPixel)-1;
+
+ offY = 0;
+ for (uint32 i = 0; i < slices.size(); i++) {
+ RawSlice slice = slices[i];
+ ByteStream in(mFile->getData(slice.offset), slice.count);
+ iPoint2D size(width, slice.h);
+ iPoint2D pos(0, offY);
+ bitPerPixel = (int)((__int64)(slice.count * 8) / (slice.h * width));
+ try {
+ readUncompressedRaw(in, size, pos, width*bitPerPixel / 8, bitPerPixel,
true);
+ } catch (RawDecoderException e) {
+ if (i>0)
+ errors.push_back(_strdup(e.what()));
+ else
+ throw;
+ } catch (IOException e) {
+ if (i>0)
+ errors.push_back(_strdup(e.what()));
+ else
+ ThrowRDE("RAW decoder: IO error occurred in first slice, unable to
decode more. Error is: %s", e.what());
+ }
+ offY += slice.h;
+ }
+}
+
void RawDecoder::readUncompressedRaw(ByteStream &input, iPoint2D& size,
iPoint2D& offset, int inputPitch, int bitPerPixel, bool MSBOrder) {
uchar8* data = mRaw->getData();
uint32 outPitch = mRaw->pitch;
Modified: RawSpeed/RawDecoder.h
===================================================================
--- RawSpeed/RawDecoder.h 2010-11-14 08:04:51 UTC (rev 291)
+++ RawSpeed/RawDecoder.h 2010-11-14 12:37:27 UTC (rev 292)
@@ -6,6 +6,8 @@
#include "BitPumpMSB.h"
#include "BitPumpPlain.h"
#include "CameraMetaData.h"
+#include "TiffIFD.h"
+
/*
RawSpeed - RAW file decoder.
@@ -118,6 +120,9 @@
/* Remove all spaces at the end of a string */
void TrimSpaces( string& str);
+ /* Generic decompressor for uncompressed images */
+ void decodeUncompressed(TiffIFD *rawIFD);
+
/* The Raw input file to be decoded */
FileMap *mFile;
@@ -132,4 +137,13 @@
map<string,string> hints;
};
+class RawSlice {
+public:
+ RawSlice() { h = offset = count = 0;};
+ ~RawSlice() {};
+ uint32 h;
+ uint32 offset;
+ uint32 count;
+};
+
} // namespace RawSpeed
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit