* The identify algorithm will no longer accept compressions it doesn't know

anything about (fix for ticket #2628).
* Fixed TReadHelper::ReadShorts() which only read half of the data.
* Disabled the stuff for the old Canon format for now (didn't work yet anyway).
* Tried to add RAW unpacked mode, but it doesn't seem to work yet (tried with
  an Olympus RAW image) (and is therefore disabled, too).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28381 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-10-30 15:15:14 +00:00
parent 45d40b75b9
commit 082466120e
3 changed files with 91 additions and 22 deletions
+80 -15
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2007-2008, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Copyright 1997-2007, Dave Coffin, dcoffin a cybercom o net * Copyright 1997-2007, Dave Coffin, dcoffin a cybercom o net
@@ -23,8 +23,8 @@
//#define TRACE(x) printf x //#define TRACE(x) printf x
#define TRACE(x) #define TRACE(x)
//#define TAG(x) printf x //#define TAG(x...) printf(x)
#define TAG(x) #define TAG(x...)
#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31))
#define LIM(x,min,max) MAX(min,MIN(x,max)) #define LIM(x,min,max) MAX(min,MIN(x,max))
@@ -275,6 +275,21 @@ DCRaw::_FlipIndex(uint32 row, uint32 col, uint32 flip)
} }
bool
DCRaw::_SupportsCompression(image_data_info& image) const
{
switch (image.compression) {
//case COMPRESSION_NONE:
case COMPRESSION_OLD_JPEG:
case COMPRESSION_PACKBITS:
return true;
default:
return false;
}
}
bool bool
DCRaw::_IsCanon() const DCRaw::_IsCanon() const
{ {
@@ -296,6 +311,13 @@ DCRaw::_IsNikon() const
} }
bool
DCRaw::_IsOlympus() const
{
return !strncasecmp(fMeta.manufacturer, "Olympus", 7);
}
bool bool
DCRaw::_IsPentax() const DCRaw::_IsPentax() const
{ {
@@ -458,8 +480,8 @@ DCRaw::_ParseManufacturerTag(off_t baseOffset)
off_t nextOffset; off_t nextOffset;
tiff_tag tag; tiff_tag tag;
_ParseTIFFTag(baseOffset, tag, nextOffset); _ParseTIFFTag(baseOffset, tag, nextOffset);
TAG(("Manufacturer tag %u (type %u, length %lu)\n", tag.tag, tag.type, TAG("Manufacturer tag %u (type %u, length %lu)\n", tag.tag, tag.type,
tag.length)); tag.length);
if (strstr(fMeta.manufacturer, "PENTAX")) { if (strstr(fMeta.manufacturer, "PENTAX")) {
if (tag.tag == 0x1b) if (tag.tag == 0x1b)
@@ -695,8 +717,8 @@ DCRaw::_ParseEXIF(off_t baseOffset)
off_t nextOffset; off_t nextOffset;
tiff_tag tag; tiff_tag tag;
_ParseTIFFTag(baseOffset, tag, nextOffset); _ParseTIFFTag(baseOffset, tag, nextOffset);
TAG(("EXIF tag %u (type %u, length %lu)\n", tag.tag, tag.type, TAG("EXIF tag %u (type %u, length %lu)\n", tag.tag, tag.type,
tag.length)); tag.length);
switch (tag.tag) { switch (tag.tag) {
#if 0 #if 0
@@ -907,6 +929,16 @@ DCRaw::_FixupValues()
fInputWidth -= fLeftMargin; fInputWidth -= fLeftMargin;
} }
} }
// Olympus
if (_IsOlympus()) {
if (!strcmp(fMeta.model,"E-300") || !strcmp(fMeta.model,"E-500")) {
fInputWidth -= 20;
fMeta.maximum = 0xfc30;
//if (load_raw == &CLASS unpacked_load_raw) black = 0;
}
}
} }
@@ -2293,23 +2325,45 @@ DCRaw::_LosslessJPEGRow(struct jhead *jh, int jrow)
// #pragma mark - RAW loaders // #pragma mark - RAW loaders
void
DCRaw::_LoadRAWUnpacked(const image_data_info& image)
{
uint32 rawWidth = _Raw().width;
uint16* pixel = (uint16*)calloc(rawWidth, sizeof(uint16));
if (pixel == NULL)
return;
fRead.Seek((fTopMargin * rawWidth + fLeftMargin) * sizeof(uint16),
SEEK_CUR);
for (uint32 row = 0; row < fInputHeight; row++) {
fRead.NextShorts(pixel, rawWidth);
for (uint32 column = 0; column < fInputWidth; column++) {
_Bayer(column, row) = pixel[column];
}
}
free(pixel);
}
/*! This is, for example, used in PENTAX RAW images /*! This is, for example, used in PENTAX RAW images
*/ */
void void
DCRaw::_LoadRAWPacked12(const image_data_info& image) DCRaw::_LoadRAWPacked12(const image_data_info& image)
{ {
uint32 rawWidth = _Raw().width; uint32 rawWidth = _Raw().width;
uint32 column, row;
_InitDecodeBits(); _InitDecodeBits();
for (row = 0; row < fInputHeight; row++) { for (uint32 row = 0; row < fInputHeight; row++) {
for (column = 0; column < fInputWidth; column++) { for (uint32 column = 0; column < fInputWidth; column++) {
//uint16 bits = _GetDecodeBits(12); //uint16 bits = _GetDecodeBits(12);
_Bayer(column, row) = _GetDecodeBits(12); _Bayer(column, row) = _GetDecodeBits(12);
//fImageData[((row) >> fShrink)*fOutputWidth + ((column) >> fShrink)][FC(row,column)] = bits; //fImageData[((row) >> fShrink)*fOutputWidth + ((column) >> fShrink)][FC(row,column)] = bits;
} }
for (column = fInputWidth * 3 / 2; column < rawWidth; column++) { for (uint32 column = fInputWidth * 3 / 2; column < rawWidth; column++) {
_GetDecodeBits(8); _GetDecodeBits(8);
} }
} }
@@ -2577,13 +2631,22 @@ DCRaw::_LoadRAWLosslessJPEG(const image_data_info& image)
void void
DCRaw::_LoadRAW(const image_data_info& image) DCRaw::_LoadRAW(const image_data_info& image)
{ {
#if 0
if (_IsCanon()) { if (_IsCanon()) {
if (fIsTIFF) if (fIsTIFF)
_LoadRAWLosslessJPEG(image);
else else
_LoadRAWCanonCompressed(image); _LoadRAWCanonCompressed(image);
} else { } else
#endif
{
switch (image.compression) { switch (image.compression) {
case COMPRESSION_NONE:
_LoadRAWUnpacked(image);
break;
case COMPRESSION_OLD_JPEG:
_LoadRAWLosslessJPEG(image);
//_LoadRAWCanonCompressed(image);
break;
case COMPRESSION_PACKBITS: case COMPRESSION_PACKBITS:
_LoadRAWPacked12(image); _LoadRAWPacked12(image);
break; break;
@@ -2792,7 +2855,7 @@ DCRaw::_ParseTIFFImageFileDirectory(off_t baseOffset, uint32 offset)
off_t nextOffset; off_t nextOffset;
tiff_tag tag; tiff_tag tag;
_ParseTIFFTag(baseOffset, tag, nextOffset); _ParseTIFFTag(baseOffset, tag, nextOffset);
TAG(("TIFF tag: %u\n", tag.tag)); TAG("TIFF tag: %u\n", tag.tag);
switch (tag.tag) { switch (tag.tag) {
#if 0 #if 0
@@ -3325,7 +3388,9 @@ DCRaw::_ParseTIFF(off_t baseOffset)
if (maxSamples < fImages[i].samples) if (maxSamples < fImages[i].samples)
maxSamples = fImages[i].samples; maxSamples = fImages[i].samples;
if (fImages[i].compression != 6 || fImages[i].samples != 3) { if ((fImages[i].compression != COMPRESSION_OLD_JPEG
|| fImages[i].samples != 3)
&& _SupportsCompression(fImages[i])) {
fImages[i].is_raw = true; fImages[i].is_raw = true;
if (fRawIndex < 0 || fImages[i].width * fImages[i].height if (fRawIndex < 0 || fImages[i].width * fImages[i].height
+7 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2007-2008, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef RAW_H #ifndef RAW_H
@@ -51,8 +51,9 @@ struct image_data_info {
bool is_raw; bool is_raw;
}; };
#define COMPRESSION_PACKBITS 32773 #define COMPRESSION_NONE 1
/* Macintosh RLE */ #define COMPRESSION_OLD_JPEG 6 // Old JPEG (before 6.0)
#define COMPRESSION_PACKBITS 32773 // Macintosh RLE
typedef void (*monitor_hook)(const char* message, float percentage, void* data); typedef void (*monitor_hook)(const char* message, float percentage, void* data);
@@ -84,9 +85,11 @@ class DCRaw {
uint16& _Bayer(int32 column, int32 row); uint16& _Bayer(int32 column, int32 row);
int32 _FilterCoefficient(int32 column, int32 row); int32 _FilterCoefficient(int32 column, int32 row);
int32 _FlipIndex(uint32 row, uint32 col, uint32 flip); int32 _FlipIndex(uint32 row, uint32 col, uint32 flip);
bool _SupportsCompression(image_data_info& info) const;
bool _IsCanon() const; bool _IsCanon() const;
bool _IsKodak() const; bool _IsKodak() const;
bool _IsNikon() const; bool _IsNikon() const;
bool _IsOlympus() const;
bool _IsPentax() const; bool _IsPentax() const;
bool _IsSamsung() const; bool _IsSamsung() const;
@@ -119,6 +122,7 @@ class DCRaw {
void _LosslessJPEGRow(struct jhead *jh, int jrow); void _LosslessJPEGRow(struct jhead *jh, int jrow);
// RAW Loader // RAW Loader
void _LoadRAWUnpacked(const image_data_info& image);
void _LoadRAWPacked12(const image_data_info& info); void _LoadRAWPacked12(const image_data_info& info);
void _MakeCanonDecoder(uint32 table); void _MakeCanonDecoder(uint32 table);
bool _CanonHasLowBits(); bool _CanonHasLowBits();
+4 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2007, Haiku, Inc. All rights reserved. * Copyright 2004-2008, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef READ_HELPER_H #ifndef READ_HELPER_H
@@ -160,13 +160,13 @@ class TReadHelper {
inline void inline void
NextShorts(uint16* data, size_t length) NextShorts(uint16* data, size_t length)
{ {
fError = fStream.Read(data, length); fError = fStream.Read(data, length * 2);
if (fError < (ssize_t)length) if (fError < (ssize_t)length * 2)
fError = B_ERROR; fError = B_ERROR;
if (fError >= B_OK) { if (fError >= B_OK) {
if (IsSwapping()) if (IsSwapping())
swap_data(B_INT16_TYPE, data, length, B_SWAP_ALWAYS); swap_data(B_INT16_TYPE, data, length * 2, B_SWAP_ALWAYS);
return; return;
} }