Author: post
Date: 2009-08-06 17:24:55 +0200 (Thu, 06 Aug 2009)
New Revision: 99
Modified:
RawSpeed/DngDecoder.cpp
RawSpeed/DngDecoderSlices.cpp
RawSpeed/DngDecoderSlices.h
RawSpeed/RawSpeed.cpp
Log:
- Fixed DNG loader to load out-of-camera Pentax/Leica DNGs.
- Fixed Uncompressed DNG byte order.
Modified: RawSpeed/DngDecoder.cpp
===================================================================
--- RawSpeed/DngDecoder.cpp 2009-08-06 14:48:14 UTC (rev 98)
+++ RawSpeed/DngDecoder.cpp 2009-08-06 15:24:55 UTC (rev 99)
@@ -94,9 +94,12 @@
int compression = raw->getEntry(COMPRESSION)->getShort();
if (mRaw->isCFA) {
- if (raw->getEntry(CFALAYOUT)->getShort() != 1)
- ThrowRDE("DNG Decoder: Unsupported CFA Layout.");
+ // Check if layout is OK, if present
+ if (raw->hasEntry(CFALAYOUT))
+ if (raw->getEntry(CFALAYOUT)->getShort() != 1)
+ ThrowRDE("DNG Decoder: Unsupported CFA Layout.");
+
const unsigned short* pDim =
raw->getEntry(CFAREPEATPATTERNDIM)->getShortArray(); // Get the size
const unsigned char* cPat = raw->getEntry(CFAPATTERN)->getData();
// Does NOT contain dimensions as some documents state
/*
@@ -184,7 +187,7 @@
ByteStream in(mFile->getData(slice.offset),slice.count);
iPoint2D size(width,slice.h);
iPoint2D pos(0,slice.offsetY);
- readUncompressedRaw(in,size,pos,width*bps/8,bps,true);
+ readUncompressedRaw(in,size,pos,width*bps/8,bps,false);
}
} catch (TiffParserException) {
@@ -199,47 +202,62 @@
}
mRaw->createData();
- guint tilew = raw->getEntry(TILEWIDTH)->getInt();
- guint tileh = raw->getEntry(TILELENGTH)->getInt();
- guint tilesX = (mRaw->dim.x + tilew -1) / tilew;
- guint tilesY = (mRaw->dim.y + tileh -1) / tileh;
- guint nTiles = tilesX*tilesY;
+ DngDecoderSlices slices(mFile, mRaw);
+ if (raw->hasEntry(TILEOFFSETS)) {
+ guint tilew = raw->getEntry(TILEWIDTH)->getInt();
+ guint tileh = raw->getEntry(TILELENGTH)->getInt();
+ guint tilesX = (mRaw->dim.x + tilew -1) / tilew;
+ guint tilesY = (mRaw->dim.y + tileh -1) / tileh;
+ guint nTiles = tilesX*tilesY;
- TiffEntry *TEoffsets = raw->getEntry(TILEOFFSETS);
- const guint* offsets = TEoffsets->getIntArray();
+ TiffEntry *TEoffsets = raw->getEntry(TILEOFFSETS);
+ const guint* offsets = TEoffsets->getIntArray();
- TiffEntry *TEcounts = raw->getEntry(TILEBYTECOUNTS);
- const guint* counts = TEcounts->getIntArray();
+ TiffEntry *TEcounts = raw->getEntry(TILEBYTECOUNTS);
+ const guint* counts = TEcounts->getIntArray();
- if (TEoffsets->count != TEcounts->count || TEoffsets->count != nTiles)
- ThrowRDE("DNG Decoder: Tile count mismatch: offsets:%u count:%u,
calculated:%u",TEoffsets->count,TEcounts->count, nTiles );
+ if (TEoffsets->count != TEcounts->count || TEoffsets->count !=
nTiles)
+ ThrowRDE("DNG Decoder: Tile count mismatch: offsets:%u count:%u,
calculated:%u",TEoffsets->count,TEcounts->count, nTiles );
+
+ slices.mFixLjpeg = mFixLjpeg;
- DngDecoderSlices slices(mFile, mRaw);
- slices.mFixLjpeg = mFixLjpeg;
+ for (guint y=0; y< tilesY; y++) {
+ for (guint x=0; x< tilesX; x++) {
+ DngSliceElement e(offsets[x+y*tilesX], counts[x+y*tilesX],
tilew*x, tileh*y);
+ slices.addSlice(e);
+ }
+ }
+ } else { // Strips
+ TiffEntry *TEoffsets = raw->getEntry(STRIPOFFSETS);
+ TiffEntry *TEcounts = raw->getEntry(STRIPBYTECOUNTS);
- for (guint y=0; y< tilesY; y++) { // This loop is obvious for
threading, as tiles are independent
- for (guint x=0; x< tilesX; x++) {
- DngSliceElement e(offsets[x+y*tilesX], counts[x+y*tilesX],
tilew*x, tileh*y);
- slices.addSlice(e);
+ const guint* offsets = TEoffsets->getIntArray();
+ const guint* counts = TEcounts->getIntArray();
+ guint yPerSlice = raw->getEntry(ROWSPERSTRIP)->getInt();
+
+ if (TEcounts->count != TEoffsets->count) {
+ ThrowRDE("DNG Decoder: Byte count number does not match strip
size: count:%u, stips:%u ",TEcounts->count, TEoffsets->count);
}
+
+ guint offY = 0;
+ for (guint s = 0; s<TEcounts->count; s++) {
+ DngSliceElement e(offsets[s], counts[s], 0, offY);
+ offY +=yPerSlice;
+
+ if (mFile->isValid(e.byteOffset+e.byteCount)) // Only decode if
size is valid
+ slices.addSlice(e);
+ }
}
+ guint nSlices = slices.size();
slices.startDecoding();
+
if (!slices.errors.empty())
errors = slices.errors;
- if (errors.size()>=nTiles)
+
+ if (errors.size() >= nSlices)
ThrowRDE("DNG Decoding: Too many errors encountered. Giving
up.\nFirst Error:%s",errors[0]);
} catch (TiffParserException e) {
- TiffEntry *offsets = raw->getEntry(STRIPOFFSETS);
- TiffEntry *counts = raw->getEntry(STRIPBYTECOUNTS);
-
- if (offsets->count != 1) {
- ThrowRDE("DNG Decoder: Multiple Strips found: %u",offsets->count);
- }
- if (counts->count != offsets->count) {
- ThrowRDE("DNG Decoder: Byte count number does not match strip size:
count:%u, stips:%u ",counts->count, offsets->count);
- }
-
- ThrowRDE("DNG Decoder: Unsupported format:\n%s", e.what());
+ ThrowRDE("DNG Decoder: Unsupported format, tried strips and
tiles:\n%s", e.what());
}
} else {
ThrowRDE("DNG Decoder: Unknown compression: %u",compression);
@@ -279,24 +297,27 @@
}
mRaw->whitePoint = raw->getEntry(WHITELEVEL)->getInt();
- const gushort *blackdim =
raw->getEntry(BLACKLEVELREPEATDIM)->getShortArray();
- int black = 65536;
- if (blackdim[0] != 0 && blackdim[1] != 0) {
- if (raw->hasEntry(BLACKLEVELDELTAV)) {
- const guint *blackarray = raw->getEntry(BLACKLEVEL)->getIntArray();
- int blackbase = blackarray[0] / blackarray[1];
- const gint *blackarrayv = (const
gint*)raw->getEntry(BLACKLEVELDELTAV)->getIntArray();
- for (int i = 0; i < new_size.y; i++)
- black = MIN(black, blackbase + blackarrayv[i*2] / blackarrayv[i*2+1]);
+ int black = -1; // Estimate, if no blacklevel
+ if (raw->hasEntry(BLACKLEVELREPEATDIM)) {
+ black = 65536;
+ const gushort *blackdim =
raw->getEntry(BLACKLEVELREPEATDIM)->getShortArray();
+ if (blackdim[0] != 0 && blackdim[1] != 0) {
+ if (raw->hasEntry(BLACKLEVELDELTAV)) {
+ const guint *blackarray = raw->getEntry(BLACKLEVEL)->getIntArray();
+ int blackbase = blackarray[0] / blackarray[1];
+ const gint *blackarrayv = (const
gint*)raw->getEntry(BLACKLEVELDELTAV)->getIntArray();
+ for (int i = 0; i < new_size.y; i++)
+ black = MIN(black, blackbase + blackarrayv[i*2] /
blackarrayv[i*2+1]);
+ } else {
+ const guint *blackarray = raw->getEntry(BLACKLEVEL)->getIntArray();
+ if (blackarray[1])
+ black = blackarray[0] / blackarray[1];
+ else
+ black = 0;
+ }
} else {
- const guint *blackarray = raw->getEntry(BLACKLEVEL)->getIntArray();
- if (blackarray[1])
- black = blackarray[0] / blackarray[1];
- else
- black = 0;
+ black = 0;
}
- } else {
- black = 0;
}
mRaw->blackLevel = black;
return mRaw;
Modified: RawSpeed/DngDecoderSlices.cpp
===================================================================
--- RawSpeed/DngDecoderSlices.cpp 2009-08-06 14:48:14 UTC (rev 98)
+++ RawSpeed/DngDecoderSlices.cpp 2009-08-06 15:24:55 UTC (rev 99)
@@ -86,3 +86,8 @@
}
}
}
+
+int DngDecoderSlices::size()
+{
+ return (int)slices.size();
+}
\ No newline at end of file
Modified: RawSpeed/DngDecoderSlices.h
===================================================================
--- RawSpeed/DngDecoderSlices.h 2009-08-06 14:48:14 UTC (rev 98)
+++ RawSpeed/DngDecoderSlices.h 2009-08-06 15:24:55 UTC (rev 99)
@@ -57,6 +57,7 @@
void addSlice(DngSliceElement slice);
void startDecoding();
void decodeSlice(DngDecoderThread* t);
+ int size();
queue<DngSliceElement> slices;
vector<DngDecoderThread*> threads;
FileMap *mFile;
Modified: RawSpeed/RawSpeed.cpp
===================================================================
--- RawSpeed/RawSpeed.cpp 2009-08-06 14:48:14 UTC (rev 98)
+++ RawSpeed/RawSpeed.cpp 2009-08-06 15:24:55 UTC (rev 99)
@@ -107,6 +107,7 @@
int wmain(int argc, _TCHAR* argv[])
{
+ if (1) { // for memory detection
#ifdef _USE_GFL_
GFL_ERROR err;
err = gflLibraryInit();
@@ -119,7 +120,26 @@
//meta.dumpXML();
// OpenFile(FileReader(L"..\\testimg\\dng\\Panasonic_LX3(300109).dng"),&meta);
//OpenFile(FileReader(L"..\\testimg\\Panasonic_LX3.rw2"),&meta);
- OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D.cr2"),&meta);
+/*
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\K7FARI0200.DNG"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\K7FARI6400.DNG"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\K7hMULTII0200.DNG"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\K7hVFAO.DNG"),&meta);*/
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\Leica_M8.dng"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\camera_dngs\\Leica_M_8.dng"),&meta);
+
+/*
+ OpenFile(FileReader(L"..\\testimg\\Canon_5DMk2-sRaw2.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_5DMk2-sRaw1.CR2"),&meta);
+
OpenFile(FileReader(L"..\\testimg\\Canon_EOS_5D_Mk2-ISO100_sRAW1.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D-1.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D-2.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D-3.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D-4.cr2"),&meta);
+ */
+// OpenFile(FileReader(L"..\\testimg\\kp.CR2"),&meta);
+
+/*
OpenFile(FileReader(L"..\\testimg\\kp.CR2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Canon_EOS_1Ds_Mk2.cr2"),&meta);
OpenFile(FileReader(L"..\\testimg\\5d.CR2"),&meta);
@@ -156,6 +176,7 @@
OpenFile(FileReader(L"..\\testimg\\Sony_DSLR-A900-2.arw"),&meta);
OpenFile(FileReader(L"..\\testimg\\Sony_DSLR-A900.arw"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\nikon_coolpix_p6000_05.nrw"),&meta);
OpenFile(FileReader(L"..\\testimg\\Nikon_D1.nef"),&meta);
OpenFile(FileReader(L"..\\testimg\\Nikon_D100-backhigh.nef"),&meta);
OpenFile(FileReader(L"..\\testimg\\Nikon_D200_compressed-1.nef"),&meta);
@@ -207,6 +228,8 @@
OpenFile(FileReader(L"..\\testimg\\Olympus_E520.orf"),&meta);
OpenFile(FileReader(L"..\\testimg\\Olympus_SP350.orf"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Nikon-D3XFARI0100.NEF"),&meta);
+
OpenFile(FileReader(L"..\\testimg\\dng\\5d-raw.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\5d.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\CANON-EOS10-linear.dng"),&meta);
@@ -344,6 +367,7 @@
OpenFile(FileReader(L"..\\testimg\\dng\\Sony_DSLR-A350.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\Sony_DSLR-A900-2.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\Sony_DSLR-A900.dng"),&meta);
+*/
OpenFile(FileReader(L"..\\testimg\\dng\\uncompressed.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\uncompressed2.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\dng\\uncompressed3.dng"),&meta);
@@ -353,6 +377,7 @@
#ifdef _USE_GFL_
gflLibraryExit();
#endif
+ } // Dump objects
_CrtDumpMemoryLeaks();
return 0;
}
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit