From 03ad24c9c1a6a9896df6eb114d34c335436ce5c1 Mon Sep 17 00:00:00 2001 From: Gerasim Troeglazov <3dEyes@gmail.com> Date: Sat, 14 Dec 2013 12:02:53 +0000 Subject: [PATCH] PSDTranslator: Add indexed color mode --- src/add-ons/translators/psd/PSDLoader.cpp | 36 +++++++++++++++++-- src/add-ons/translators/psd/PSDLoader.h | 6 +++- src/add-ons/translators/psd/PSDTranslator.h | 2 +- .../translators/psd/PSDTranslator.rdef | 4 +-- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/add-ons/translators/psd/PSDLoader.cpp b/src/add-ons/translators/psd/PSDLoader.cpp index 04c954e3b7..b08bc20cac 100644 --- a/src/add-ons/translators/psd/PSDLoader.cpp +++ b/src/add-ons/translators/psd/PSDLoader.cpp @@ -37,8 +37,10 @@ PSDLoader::PSDLoader(BPositionIO *src) fDepth = _GetInt16FromStream(fStream); fColorFormat = _GetInt16FromStream(fStream); - // Skip mode data - _SkipStreamBlock(fStream, _GetInt32FromStream(fStream)); + fColorModeDataSize = _GetInt32FromStream(fStream); + fColorModeDataPos = fStream->Position(); + _SkipStreamBlock(fStream, fColorModeDataSize); + // Skip image resources _SkipStreamBlock(fStream, _GetInt32FromStream(fStream)); // Skip reserved data @@ -160,6 +162,10 @@ PSDLoader::_ColorFormat(void) if (fChannels >= 1) format = PSD_COLOR_FORMAT_DUOTONE; break; + case PSD_COLOR_MODE_INDEXED: + if (fChannels >= 1 && fColorModeDataSize >= 3) + format = PSD_COLOR_FORMAT_INDEXED; + break; default: break; }; @@ -275,6 +281,32 @@ PSDLoader::Decode(BPositionIO *target) target->Write(imageData[0], rowBytes); break; } + case PSD_COLOR_FORMAT_INDEXED: + { + int32 paletteSize = fColorModeDataSize / 3; + + uint8 *colorData = new uint8[fColorModeDataSize]; + fStream->Seek(fColorModeDataPos, SEEK_SET); + fStream->Read(colorData, fColorModeDataSize); + + uint8 *redPalette = colorData; + uint8 *greenPalette = colorData + paletteSize; + uint8 *bluePalette = colorData + paletteSize * 2; + uint8 *cCh = imageData[0]; + for (int h = 0; h < fHeight; h++) { + uint8 *ptr = lineData; + for (int w = 0; w < fWidth; w++) { + uint8 c = *cCh++; + *ptr++ = bluePalette[c]; + *ptr++ = greenPalette[c]; + *ptr++ = redPalette[c]; + *ptr++ = 255; + } + target->Write(lineData, fWidth * sizeof(uint32)); + } + delete colorData; + break; + } case PSD_COLOR_FORMAT_DUOTONE: case PSD_COLOR_FORMAT_GRAY: case PSD_COLOR_FORMAT_GRAY_A: diff --git a/src/add-ons/translators/psd/PSDLoader.h b/src/add-ons/translators/psd/PSDLoader.h index b9a8846511..76f2d672a5 100644 --- a/src/add-ons/translators/psd/PSDLoader.h +++ b/src/add-ons/translators/psd/PSDLoader.h @@ -53,7 +53,8 @@ enum psd_color_format { PSD_COLOR_FORMAT_CMYK_A, PSD_COLOR_FORMAT_LAB, PSD_COLOR_FORMAT_LAB_A, - PSD_COLOR_FORMAT_DUOTONE + PSD_COLOR_FORMAT_DUOTONE, + PSD_COLOR_FORMAT_INDEXED }; @@ -82,6 +83,9 @@ private: size_t fStreamSize; size_t fStreamPos; + size_t fColorModeDataSize; + size_t fColorModeDataPos; + int32 fSignature; int16 fVersion; int16 fChannels; diff --git a/src/add-ons/translators/psd/PSDTranslator.h b/src/add-ons/translators/psd/PSDTranslator.h index 38da193b7c..59f708ec7f 100644 --- a/src/add-ons/translators/psd/PSDTranslator.h +++ b/src/add-ons/translators/psd/PSDTranslator.h @@ -21,7 +21,7 @@ #define DOCUMENT_COUNT "/documentCount" #define DOCUMENT_INDEX "/documentIndex" -#define PSD_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 1, 1) +#define PSD_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 1, 2) #define PSD_IMAGE_FORMAT 'PSD ' #define PSD_IN_QUALITY 0.5 diff --git a/src/add-ons/translators/psd/PSDTranslator.rdef b/src/add-ons/translators/psd/PSDTranslator.rdef index 8aefc0fb93..5c500f6792 100644 --- a/src/add-ons/translators/psd/PSDTranslator.rdef +++ b/src/add-ons/translators/psd/PSDTranslator.rdef @@ -7,9 +7,9 @@ resource app_signature "application/x-vnd.Haiku-PSDTranslator"; resource app_version { major = 1, middle = 1, - minor = 0, + minor = 2, variety = 0, internal = 0, - short_info = "1.1.0", + short_info = "1.1.2", long_info = "Haiku PSDTranslator Add-Ons." };