16-bit tiff and png saving broken on big endian, Issue 2675

This commit is contained in:
Ingo
2015-02-22 23:36:28 +01:00
parent 4e8a326645
commit b724b616f2
3 changed files with 15 additions and 4 deletions

View File

@@ -802,11 +802,13 @@ int ImageIO::savePNG (Glib::ustring fname, int compression, volatile int bps) {
getScanline (i, row, bps);
if (bps==16) {
// convert to network byte order
#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
for (int j=0; j<width*6; j+=2) {
unsigned char tmp = row[j];
row[j] = row[j+1];
row[j+1] = tmp;
}
#endif
}
png_write_row (png, (png_byte*)row);
@@ -1053,7 +1055,11 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
if (size>0 && size<165530)
fwrite (buffer, size, 1, file);
#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
bool needsReverse = bps==16 && exifRoot->getOrder()==rtexif::MOTOROLA;
#else
bool needsReverse = bps==16 && exifRoot->getOrder()==rtexif::INTEL;
#endif
for (int i=0; i<height; i++) {
getScanline (i, linebuffer, bps);

View File

@@ -44,7 +44,7 @@ Interpreter stdInterpreter;
#define TAG_SUBFILETYPE 0x00fe
TagDirectory::TagDirectory ()
: attribs(ifdAttribs), order(INTEL), parent(NULL) {}
: attribs(ifdAttribs), order(HOSTORDER), parent(NULL) {}
TagDirectory::TagDirectory (TagDirectory* p, const TagAttrib* ta, ByteOrder border)
: attribs(ta), order(border), parent(p) {}
@@ -2244,7 +2244,7 @@ int ExifManager::createTIFFHeader (const TagDirectory* root, const rtengine::pro
// write tiff header
int offs = 0;
ByteOrder order = INTEL;
ByteOrder order = HOSTORDER;
if (root)
order = root->getOrder ();
sset2 ((unsigned short)order, buffer+offs, order); offs += 2;
@@ -2255,7 +2255,7 @@ int ExifManager::createTIFFHeader (const TagDirectory* root, const rtengine::pro
if (root)
cl = (const_cast<TagDirectory*>(root))->clone (NULL);
else
cl = new TagDirectory (NULL, ifdAttribs, INTEL);
cl = new TagDirectory (NULL, ifdAttribs, HOSTORDER);
// add tiff strip data
int rps = 8;

View File

@@ -44,6 +44,11 @@ enum ActionCode {
AC_INVALID=100, // invalid state
};
enum ByteOrder {INTEL=0x4949, MOTOROLA=0x4D4D};
#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
const enum ByteOrder HOSTORDER = INTEL;
#else
const enum ByteOrder HOSTORDER = MOTOROLA;
#endif
enum MNKind {NOMK, IFD, HEADERIFD, NIKON3, OLYMPUS2, FUJI,TABLESUBDIR};
bool extractLensInfo(std::string &fullname,double &minFocal, double &maxFocal, double &maxApertureAtMinFocal, double &maxApertureAtMaxFocal);
@@ -193,7 +198,7 @@ class Tag {
unsigned char* getValue () const { return value; }
signed char* getSignedValue () const { return reinterpret_cast<signed char*>(value); }
const TagAttrib* getAttrib () const { return attrib; }
inline ByteOrder getOrder () const { return parent ? parent->getOrder() : INTEL; }
inline ByteOrder getOrder () const { return parent ? parent->getOrder() : HOSTORDER; }
inline TagDirectory* getParent () const { return parent; }
int getValueSize () const { return valuesize; }
bool getOwnMemory () const { return allocOwnMemory; }