From 96f0c487681d710ffa9eb596bddabe24a1605cad Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 18 Feb 2008 09:01:20 +0000 Subject: [PATCH] removed duplicated and obsolete tiff translator git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23997 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/translators/tiff/BitReader.cpp | 99 -- src/add-ons/translators/tiff/BitReader.h | 72 - src/add-ons/translators/tiff/DecodeTree.cpp | 398 ----- src/add-ons/translators/tiff/DecodeTree.h | 77 - src/add-ons/translators/tiff/Jamfile | 22 - src/add-ons/translators/tiff/TIFFMain.cpp | 103 -- .../translators/tiff/TIFFTranslator.cpp | 1504 ----------------- src/add-ons/translators/tiff/TIFFTranslator.h | 160 -- src/add-ons/translators/tiff/TIFFView.cpp | 116 -- src/add-ons/translators/tiff/TIFFView.h | 51 - src/add-ons/translators/tiff/TIFFWindow.cpp | 69 - src/add-ons/translators/tiff/TIFFWindow.h | 48 - src/add-ons/translators/tiff/TiffField.cpp | 42 - src/add-ons/translators/tiff/TiffField.h | 141 -- src/add-ons/translators/tiff/TiffIfd.cpp | 273 --- src/add-ons/translators/tiff/TiffIfd.h | 104 -- src/add-ons/translators/tiff/TiffIfdList.cpp | 120 -- src/add-ons/translators/tiff/TiffIfdList.h | 62 - .../translators/tiff/TiffUintField.cpp | 257 --- src/add-ons/translators/tiff/TiffUintField.h | 57 - .../translators/tiff/TiffUnknownField.cpp | 42 - .../translators/tiff/TiffUnknownField.h | 43 - 22 files changed, 3860 deletions(-) delete mode 100644 src/add-ons/translators/tiff/BitReader.cpp delete mode 100644 src/add-ons/translators/tiff/BitReader.h delete mode 100644 src/add-ons/translators/tiff/DecodeTree.cpp delete mode 100644 src/add-ons/translators/tiff/DecodeTree.h delete mode 100644 src/add-ons/translators/tiff/Jamfile delete mode 100644 src/add-ons/translators/tiff/TIFFMain.cpp delete mode 100644 src/add-ons/translators/tiff/TIFFTranslator.cpp delete mode 100644 src/add-ons/translators/tiff/TIFFTranslator.h delete mode 100644 src/add-ons/translators/tiff/TIFFView.cpp delete mode 100644 src/add-ons/translators/tiff/TIFFView.h delete mode 100644 src/add-ons/translators/tiff/TIFFWindow.cpp delete mode 100644 src/add-ons/translators/tiff/TIFFWindow.h delete mode 100644 src/add-ons/translators/tiff/TiffField.cpp delete mode 100644 src/add-ons/translators/tiff/TiffField.h delete mode 100644 src/add-ons/translators/tiff/TiffIfd.cpp delete mode 100644 src/add-ons/translators/tiff/TiffIfd.h delete mode 100644 src/add-ons/translators/tiff/TiffIfdList.cpp delete mode 100644 src/add-ons/translators/tiff/TiffIfdList.h delete mode 100644 src/add-ons/translators/tiff/TiffUintField.cpp delete mode 100644 src/add-ons/translators/tiff/TiffUintField.h delete mode 100644 src/add-ons/translators/tiff/TiffUnknownField.cpp delete mode 100644 src/add-ons/translators/tiff/TiffUnknownField.h diff --git a/src/add-ons/translators/tiff/BitReader.cpp b/src/add-ons/translators/tiff/BitReader.cpp deleted file mode 100644 index 267936afe6..0000000000 --- a/src/add-ons/translators/tiff/BitReader.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/*****************************************************************************/ -// BitReader -// Written by Michael Wilber, OBOS Translation Kit Team -// -// BitReader.cpp -// -// Wrapper class for StreamBuffer to make it convenient to read 1 bit at -// a time -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include "BitReader.h" - -BitReader::BitReader(uint16 fillOrder, StreamBuffer *pstreambuf, bool binitialRead) -{ - SetTo(fillOrder, pstreambuf, binitialRead); -} - -BitReader::~BitReader() -{ - finitStatus = B_ERROR; - fpstreambuf = NULL; - fbitbuf = 0; - fcurrentbit = 0; -} - -status_t -BitReader::SetTo(uint16 fillOrder, StreamBuffer *pstreambuf, bool binitialRead) -{ - finitStatus = B_OK; - fnbytesRead = 0; - fbitbuf = 0; - fcurrentbit = 0; - fpstreambuf = pstreambuf; - ffillOrder = fillOrder; - if (ffillOrder != 1 && ffillOrder != 2) - finitStatus = B_BAD_VALUE; - else if (!fpstreambuf) - finitStatus = B_BAD_VALUE; - else if (binitialRead) - finitStatus = ReadByte(); - - return finitStatus; -} - -status_t -BitReader::NextBit() -{ - status_t result; - result = PeekBit(); - if (result >= 0) - fcurrentbit--; - - return result; -} - -status_t -BitReader::PeekBit() -{ - // if fcurrentbit is zero, read in next byte - if (!fcurrentbit && ReadByte() != B_OK) - return B_ERROR; - - if (ffillOrder == 1) - return (fbitbuf >> (fcurrentbit - 1)) & 1; - else - return (fbitbuf >> (8 - fcurrentbit)) & 1; -} - -status_t -BitReader::ReadByte() -{ - if (fpstreambuf->Read(&fbitbuf, 1) != 1) - return B_ERROR; - - fnbytesRead++; - fcurrentbit = 8; - return B_OK; -} diff --git a/src/add-ons/translators/tiff/BitReader.h b/src/add-ons/translators/tiff/BitReader.h deleted file mode 100644 index ce398996f7..0000000000 --- a/src/add-ons/translators/tiff/BitReader.h +++ /dev/null @@ -1,72 +0,0 @@ -/*****************************************************************************/ -// BitReader -// Written by Michael Wilber, OBOS Translation Kit Team -// -// BitReader.h -// -// Wrapper class for StreamBuffer to make it convenient to read 1 bit at -// a time -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - - -#ifndef BIT_READER_H -#define BIT_READER_H - -#include "StreamBuffer.h" - -class BitReader { -public: - // Setup the BitReader to read from the given stream with the given fill order - BitReader(uint16 fillOrder, StreamBuffer *pstreambuf, bool binitialRead = true); - ~BitReader(); - - // Change the BitReader to read from given stream with the given fill order - status_t SetTo(uint16 fillOrder, StreamBuffer *pstreambuf, bool binitialRead = true); - - status_t InitCheck() const { return finitStatus; }; - - uint32 BytesRead() const { return fnbytesRead; }; - uint32 BitsInBuffer() const { return fcurrentbit; }; - - // return the current bit and increment the position - // If the result is negative, an error occured - status_t NextBit(); - - // return the current bit without incrementing the position - // (if buffer is empty, will read next byte in StreamBuffer) - // If the result is negative, an error occured - status_t PeekBit(); - -private: - status_t ReadByte(); - - StreamBuffer *fpstreambuf; - status_t finitStatus; - uint32 fnbytesRead; - uint16 ffillOrder; - uint8 fbitbuf; - uint8 fcurrentbit; -}; - -#endif diff --git a/src/add-ons/translators/tiff/DecodeTree.cpp b/src/add-ons/translators/tiff/DecodeTree.cpp deleted file mode 100644 index 833c8c1477..0000000000 --- a/src/add-ons/translators/tiff/DecodeTree.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/*****************************************************************************/ -// DecodeTree -// Written by Michael Wilber, OBOS Translation Kit Team -// -// DecodeTree.cpp -// -// This object is used for fast decoding of Huffman encoded data -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include "DecodeTree.h" - -// Encodings used to populate -// the decode trees -const HuffmanEncoding g_encWhiteTerm[] = { - {0, 0x35, 8}, // "00110101" - {1, 0x07, 6}, // "000111" - {2, 0x07, 4}, // "0111" - {3, 0x08, 4}, // "1000" - {4, 0x0b, 4}, // "1011" - {5, 0x0c, 4}, // "1100" - {6, 0x0e, 4}, // "1110" - {7, 0x0f, 4}, // "1111" - {8, 0x13, 5}, // "10011" - {9, 0x14, 5}, // "10100" - {10, 0x07, 5}, // "00111" - {11, 0x08, 5}, // "01000" - {12, 0x08, 6}, // "001000" - {13, 0x03, 6}, // "000011" - {14, 0x34, 6}, // "110100" - {15, 0x35, 6}, // "110101" - {16, 0x2a, 6}, // "101010" - {17, 0x2b, 6}, // "101011" - {18, 0x27, 7}, // "0100111" - {19, 0x0c, 7}, // "0001100" - {20, 0x08, 7}, // "0001000" - {21, 0x17, 7}, // "0010111" - {22, 0x03, 7}, // "0000011" - {23, 0x04, 7}, // "0000100" - {24, 0x28, 7}, // "0101000" - {25, 0x2b, 7}, // "0101011" - {26, 0x13, 7}, // "0010011" - {27, 0x24, 7}, // "0100100" - {28, 0x18, 7}, // "0011000" - {29, 0x02, 8}, // "00000010" - {30, 0x03, 8}, // "00000011" - {31, 0x1a, 8}, // "00011010" - {32, 0x1b, 8}, // "00011011" - {33, 0x12, 8}, // "00010010" - {34, 0x13, 8}, // "00010011" - {35, 0x14, 8}, // "00010100" - {36, 0x15, 8}, // "00010101" - {37, 0x16, 8}, // "00010110" - {38, 0x17, 8}, // "00010111" - {39, 0x28, 8}, // "00101000" - {40, 0x29, 8}, // "00101001" - {41, 0x2a, 8}, // "00101010" - {42, 0x2b, 8}, // "00101011" - {43, 0x2c, 8}, // "00101100" - {44, 0x2d, 8}, // "00101101" - {45, 0x04, 8}, // "00000100" - {46, 0x05, 8}, // "00000101" - {47, 0x0a, 8}, // "00001010" - {48, 0x0b, 8}, // "00001011" - {49, 0x52, 8}, // "01010010" - {50, 0x53, 8}, // "01010011" - {51, 0x54, 8}, // "01010100" - {52, 0x55, 8}, // "01010101" - {53, 0x24, 8}, // "00100100" - {54, 0x25, 8}, // "00100101" - {55, 0x58, 8}, // "01011000" - {56, 0x59, 8}, // "01011001" - {57, 0x5a, 8}, // "01011010" - {58, 0x5b, 8}, // "01011011" - {59, 0x4a, 8}, // "01001010" - {60, 0x4b, 8}, // "01001011" - {61, 0x32, 8}, // "00110010" - {62, 0x33, 8}, // "00110011" - {63, 0x34, 8}, // "00110100" -}; // g_encWhiteTerm - -const HuffmanEncoding g_encWhiteMakeup[] = { - {64, 0x1b, 5}, // "11011" - {128, 0x12, 5}, // "10010" - {192, 0x17, 6}, // "010111" - {256, 0x37, 7}, // "0110111" - {320, 0x36, 8}, // "00110110" - {384, 0x37, 8}, // "00110111" - {448, 0x64, 8}, // "01100100" - {512, 0x65, 8}, // "01100101" - {576, 0x68, 8}, // "01101000" - {640, 0x67, 8}, // "01100111" - {704, 0xcc, 9}, // "011001100" - {768, 0xcd, 9}, // "011001101" - {832, 0xd2, 9}, // "011010010" - {896, 0xd3, 9}, // "011010011" - {960, 0xd4, 9}, // "011010100" - {1024, 0xd5, 9}, // "011010101" - {1088, 0xd6, 9}, // "011010110" - {1152, 0xd7, 9}, // "011010111" - {1216, 0xd8, 9}, // "011011000" - {1280, 0xd9, 9}, // "011011001" - {1344, 0xda, 9}, // "011011010" - {1408, 0xdb, 9}, // "011011011" - {1472, 0x98, 9}, // "010011000" - {1536, 0x99, 9}, // "010011001" - {1600, 0x9a, 9}, // "010011010" - {1664, 0x18, 6}, // "011000" - {1728, 0x9b, 9}, // "010011011" -}; // g_encWhiteMakeup - -const HuffmanEncoding g_encBlackTerm[] = { - {0, 0x37, 10}, // "0000110111" - {1, 0x02, 3}, // "010" - {2, 0x03, 2}, // "11" - {3, 0x02, 2}, // "10" - {4, 0x03, 3}, // "011" - {5, 0x03, 4}, // "0011" - {6, 0x02, 4}, // "0010" - {7, 0x03, 5}, // "00011" - {8, 0x05, 6}, // "000101" - {9, 0x04, 6}, // "000100" - {10, 0x04, 7}, // "0000100" - {11, 0x05, 7}, // "0000101" - {12, 0x07, 7}, // "0000111" - {13, 0x04, 8}, // "00000100" - {14, 0x07, 8}, // "00000111" - {15, 0x18, 9}, // "000011000" - {16, 0x17, 10}, // "0000010111" - {17, 0x18, 10}, // "0000011000" - {18, 0x08, 10}, // "0000001000" - {19, 0x67, 11}, // "00001100111" - {20, 0x68, 11}, // "00001101000" - {21, 0x6c, 11}, // "00001101100" - {22, 0x37, 11}, // "00000110111" - {23, 0x28, 11}, // "00000101000" - {24, 0x17, 11}, // "00000010111" - {25, 0x18, 11}, // "00000011000" - {26, 0xca, 12}, // "000011001010" - {27, 0xcb, 12}, // "000011001011" - {28, 0xcc, 12}, // "000011001100" - {29, 0xcd, 12}, // "000011001101" - {30, 0x68, 12}, // "000001101000" - {31, 0x69, 12}, // "000001101001" - {32, 0x6a, 12}, // "000001101010" - {33, 0x6b, 12}, // "000001101011" - {34, 0xd2, 12}, // "000011010010" - {35, 0xd3, 12}, // "000011010011" - {36, 0xd4, 12}, // "000011010100" - {37, 0xd5, 12}, // "000011010101" - {38, 0xd6, 12}, // "000011010110" - {39, 0xd7, 12}, // "000011010111" - {40, 0x6c, 12}, // "000001101100" - {41, 0x6d, 12}, // "000001101101" - {42, 0xda, 12}, // "000011011010" - {43, 0xdb, 12}, // "000011011011" - {44, 0x54, 12}, // "000001010100" - {45, 0x55, 12}, // "000001010101" - {46, 0x56, 12}, // "000001010110" - {47, 0x57, 12}, // "000001010111" - {48, 0x64, 12}, // "000001100100" - {49, 0x65, 12}, // "000001100101" - {50, 0x52, 12}, // "000001010010" - {51, 0x53, 12}, // "000001010011" - {52, 0x24, 12}, // "000000100100" - {53, 0x37, 12}, // "000000110111" - {54, 0x38, 12}, // "000000111000" - {55, 0x27, 12}, // "000000100111" - {56, 0x28, 12}, // "000000101000" - {57, 0x58, 12}, // "000001011000" - {58, 0x59, 12}, // "000001011001" - {59, 0x2b, 12}, // "000000101011" - {60, 0x2c, 12}, // "000000101100" - {61, 0x5a, 12}, // "000001011010" - {62, 0x66, 12}, // "000001100110" - {63, 0x67, 12}, // "000001100111" -}; // g_encBlackTerm - -const HuffmanEncoding g_encBlackMakeup[] = { - {64, 0x0f, 10}, // "0000001111" - {128, 0xc8, 12}, // "000011001000" - {192, 0xc9, 12}, // "000011001001" - {256, 0x5b, 12}, // "000001011011" - {320, 0x33, 12}, // "000000110011" - {384, 0x34, 12}, // "000000110100" - {448, 0x35, 12}, // "000000110101" - {512, 0x6c, 13}, // "0000001101100" - {576, 0x6d, 13}, // "0000001101101" - {640, 0x4a, 13}, // "0000001001010" - {704, 0x4b, 13}, // "0000001001011" - {768, 0x4c, 13}, // "0000001001100" - {832, 0x4d, 13}, // "0000001001101" - {896, 0x72, 13}, // "0000001110010" - {960, 0x73, 13}, // "0000001110011" - {1024, 0x74, 13}, // "0000001110100" - {1088, 0x75, 13}, // "0000001110101" - {1152, 0x76, 13}, // "0000001110110" - {1216, 0x77, 13}, // "0000001110111" - {1280, 0x52, 13}, // "0000001010010" - {1344, 0x53, 13}, // "0000001010011" - {1408, 0x54, 13}, // "0000001010100" - {1472, 0x55, 13}, // "0000001010101" - {1536, 0x5a, 13}, // "0000001011010" - {1600, 0x5b, 13}, // "0000001011011" - {1664, 0x64, 13}, // "0000001100100" - {1728, 0x65, 13}, // "0000001100101" -}; // g_encBlackMakeup - -const HuffmanEncoding g_encBothMakeup[] = { - {1792, 0x08, 11}, // "00000001000" - {1856, 0x0c, 11}, // "00000001100" - {1920, 0x0d, 11}, // "00000001101" - {1984, 0x12, 12}, // "000000010010" - {2048, 0x13, 12}, // "000000010011" - {2112, 0x14, 12}, // "000000010100" - {2176, 0x15, 12}, // "000000010101" - {2240, 0x16, 12}, // "000000010110" - {2304, 0x17, 12}, // "000000010111" - {2368, 0x1c, 12}, // "000000011100" - {2432, 0x1d, 12}, // "000000011101" - {2496, 0x1e, 12}, // "000000011110" - {2560, 0x1f, 12}, // "000000011111" -}; // g_encBothMakeup - - -DecodeTree::DecodeTree(bool bwhite) -{ - finitStatus = B_ERROR; - fptop = new DecodeNode; - if (fptop) { - fptop->value = -1; - fptop->branches[0] = NULL; - fptop->branches[1] = NULL; - - if (bwhite) - finitStatus = LoadWhiteEncodings(); - else - finitStatus = LoadBlackEncodings(); - } else - finitStatus = B_NO_MEMORY; -} - -void -destroy_node(DecodeNode *pnode) -{ - if (pnode->branches[0]) - destroy_node(pnode->branches[0]); - if (pnode->branches[1]) - destroy_node(pnode->branches[1]); - - delete pnode; -} -DecodeTree::~DecodeTree() -{ - if (fptop) { - destroy_node(fptop); - fptop = NULL; - } -} - -status_t -DecodeTree::LoadBlackEncodings() -{ - status_t result = B_ERROR; - - result = AddEncodings(g_encBlackTerm, - sizeof(g_encBlackTerm) / sizeof(HuffmanEncoding)); - if (result != B_OK) - return result; - - result = AddEncodings(g_encBlackMakeup, - sizeof(g_encBlackMakeup) / sizeof(HuffmanEncoding)); - if (result != B_OK) - return result; - - result = AddEncodings(g_encBothMakeup, - sizeof(g_encBothMakeup) / sizeof(HuffmanEncoding)); - - return result; -} - -status_t -DecodeTree::LoadWhiteEncodings() -{ - status_t result = B_ERROR; - - result = AddEncodings(g_encWhiteTerm, - sizeof(g_encWhiteTerm) / sizeof(HuffmanEncoding)); - if (result != B_OK) - return result; - - result = AddEncodings(g_encWhiteMakeup, - sizeof(g_encWhiteMakeup) / sizeof(HuffmanEncoding)); - if (result != B_OK) - return result; - - result = AddEncodings(g_encBothMakeup, - sizeof(g_encBothMakeup) / sizeof(HuffmanEncoding)); - - return result; -} - -status_t -DecodeTree::AddEncodings(const HuffmanEncoding *pencs, uint32 length) -{ - status_t result = B_ERROR; - for (uint32 i = 0; i < length; i++) { - result = AddEncoding(pencs[i].encoding, pencs[i].length, - pencs[i].value); - if (result != B_OK) - break; - } - - return result; -} - -status_t -DecodeTree::AddEncoding(uint16 encoding, uint8 length, uint16 value) -{ - if (!length || length > 16) - return B_BAD_VALUE; - - DecodeNode *pcurrent = fptop, *pnext = NULL; - uint8 bitsleft = length; - - while (bitsleft > 0) { - uint32 branch = (encoding >> (bitsleft - 1)) & 1; - - // if a new node needs to be allocated - if (!pcurrent->branches[branch]) { - pcurrent->branches[branch] = new DecodeNode; - pnext = pcurrent->branches[branch]; - if (!pnext) - return B_NO_MEMORY; - - pnext->value = -1; - pnext->branches[0] = NULL; - pnext->branches[1] = NULL; - - } else - // if a node exists - pnext = pcurrent->branches[branch]; - - if (bitsleft == 1) { - pnext->value = value; - return B_OK; - - } else { - pcurrent = pnext; - bitsleft--; - } - } - - return B_ERROR; -} - -status_t -DecodeTree::GetValue(BitReader &stream) const -{ - if (InitCheck() != B_OK) - return InitCheck(); - - status_t branch; - DecodeNode *pnode = fptop; - while (pnode) { - branch = stream.NextBit(); - if (branch < 0) - return branch; - - pnode = pnode->branches[branch]; - if (!pnode) - return B_ERROR; - else if (pnode->value > -1) - return pnode->value; - } - - return B_ERROR; -} diff --git a/src/add-ons/translators/tiff/DecodeTree.h b/src/add-ons/translators/tiff/DecodeTree.h deleted file mode 100644 index 6cdf7bf949..0000000000 --- a/src/add-ons/translators/tiff/DecodeTree.h +++ /dev/null @@ -1,77 +0,0 @@ -/*****************************************************************************/ -// DecodeTree -// Written by Michael Wilber, OBOS Translation Kit Team -// -// DecodeTree.h -// -// This object is used for fast decoding of Huffman encoded data -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef DECODE_TREE_H -#define DECODE_TREE_H - -#include -#include "BitReader.h" - -// structure used to populate -// the decode trees -struct HuffmanEncoding { - uint16 value; - uint8 encoding; - uint8 length; -}; - -// node used by the decode tree -struct DecodeNode { - int16 value; - DecodeNode *branches[2]; -}; - -class DecodeTree { -public: - DecodeTree(bool bwhite); - ~DecodeTree(); - - // returns B_OK if the tree was initialized without error, - // returns B_ERROR or B_NO_MEMORY if unable to initialize - status_t InitCheck() const { return finitStatus; }; - - // Decodes nbits bits from encdata, starting with the - // highest order bit. If successful, returns the corresponding - // value for the encdata and bitsread contains the - // number of bits from encdata that were decoded. If not successful, - // B_ERROR, B_NO_MEMORY or B_BAD_VALUE is returned - status_t GetValue(BitReader &stream) const; - -private: - status_t LoadBlackEncodings(); - status_t LoadWhiteEncodings(); - status_t AddEncodings(const HuffmanEncoding *pencs, uint32 length); - status_t AddEncoding(uint16 encoding, uint8 length, uint16 value); - - status_t finitStatus; - DecodeNode *fptop; -}; - -#endif diff --git a/src/add-ons/translators/tiff/Jamfile b/src/add-ons/translators/tiff/Jamfile deleted file mode 100644 index 241cd3d36c..0000000000 --- a/src/add-ons/translators/tiff/Jamfile +++ /dev/null @@ -1,22 +0,0 @@ -SubDir HAIKU_TOP src add-ons translators tiff ; - -# Include StreamBuffer code from shared directory -SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons translators shared ] ; - -Translator TIFFTranslator : - StreamBuffer.cpp - BitReader.cpp - DecodeTree.cpp - TiffField.cpp - TiffUintField.cpp - TiffUnknownField.cpp - TiffIfd.cpp - TiffIfdList.cpp - TIFFMain.cpp - TIFFTranslator.cpp - TIFFView.cpp - TIFFWindow.cpp - - : be translation - : true -; diff --git a/src/add-ons/translators/tiff/TIFFMain.cpp b/src/add-ons/translators/tiff/TIFFMain.cpp deleted file mode 100644 index 4b82d48068..0000000000 --- a/src/add-ons/translators/tiff/TIFFMain.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*****************************************************************************/ -// TIFFTranslator -// Written by Michael Wilber, OBOS Translation Kit Team -// -// Version: -// -// This translator opens and writes TIFF images. -// -// -// This application and all source files used in its construction, except -// where noted, are licensed under the MIT License, and have been written -// and are: -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include -#include -#include "TIFFTranslator.h" -#include "TIFFWindow.h" -#include "TIFFView.h" - -// --------------------------------------------------------------- -// main -// -// Creates a BWindow for displaying info about the TIFFTranslator -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -int -main() -{ - BApplication app("application/x-vnd.obos-tiff-translator"); - TIFFTranslator *ptranslator = new TIFFTranslator; - BView *view = NULL; - BRect rect(0, 0, 225, 175); - if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) { - BAlert *err = new BAlert("Error", - "Unable to create the TIFFTranslator view.", "OK"); - err->Go(); - return 1; - } - // release the translator even though I never really used it anyway - ptranslator->Release(); - ptranslator = NULL; - - TIFFWindow *wnd = new TIFFWindow(rect); - view->ResizeTo(rect.Width(), rect.Height()); - wnd->AddChild(view); - BPoint wndpt = B_ORIGIN; - { - BScreen scrn; - BRect frame = scrn.Frame(); - frame.InsetBy(10, 23); - // if the point is outside of the screen frame, - // use the mouse location to find a better point - if (!frame.Contains(wndpt)) { - uint32 dummy; - view->GetMouse(&wndpt, &dummy, false); - wndpt.x -= rect.Width() / 2; - wndpt.y -= rect.Height() / 2; - // clamp location to screen - if (wndpt.x < frame.left) - wndpt.x = frame.left; - if (wndpt.y < frame.top) - wndpt.y = frame.top; - if (wndpt.x > frame.right) - wndpt.x = frame.right; - if (wndpt.y > frame.bottom) - wndpt.y = frame.bottom; - } - } - wnd->MoveTo(wndpt); - wnd->Show(); - app.Run(); - - return 0; -} diff --git a/src/add-ons/translators/tiff/TIFFTranslator.cpp b/src/add-ons/translators/tiff/TIFFTranslator.cpp deleted file mode 100644 index ac26c387d3..0000000000 --- a/src/add-ons/translators/tiff/TIFFTranslator.cpp +++ /dev/null @@ -1,1504 +0,0 @@ -/*****************************************************************************/ -// TIFFTranslator -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFTranslator.cpp -// -// This BTranslator based object is for opening and writing -// TIFF images. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include -#include "TIFFTranslator.h" -#include "TIFFView.h" -#include "TiffIfd.h" -#include "TiffIfdList.h" -#include "StreamBuffer.h" -#include "BitReader.h" - -// The input formats that this translator supports. -translation_format gInputFormats[] = { - { - B_TRANSLATOR_BITMAP, - B_TRANSLATOR_BITMAP, - BBT_IN_QUALITY, - BBT_IN_CAPABILITY, - "image/x-be-bitmap", - "Be Bitmap Format (TIFFTranslator)" - }, - { - B_TIFF_FORMAT, - B_TRANSLATOR_BITMAP, - TIFF_IN_QUALITY, - TIFF_IN_CAPABILITY, - "image/tiff", - "TIFF image" - } -}; - -// The output formats that this translator supports. -translation_format gOutputFormats[] = { - { - B_TRANSLATOR_BITMAP, - B_TRANSLATOR_BITMAP, - BBT_OUT_QUALITY, - BBT_OUT_CAPABILITY, - "image/x-be-bitmap", - "Be Bitmap Format (TIFFTranslator)" - }, - { - B_TIFF_FORMAT, - B_TRANSLATOR_BITMAP, - TIFF_OUT_QUALITY, - TIFF_OUT_CAPABILITY, - "image/tiff", - "TIFF image" - } -}; - -// --------------------------------------------------------------- -// make_nth_translator -// -// Creates a TIFFTranslator object to be used by BTranslatorRoster -// -// Preconditions: -// -// Parameters: n, The translator to return. Since -// TIFFTranslator only publishes one -// translator, it only returns a -// TIFFTranslator if n == 0 -// -// you, The image_id of the add-on that -// contains code (not used). -// -// flags, Has no meaning yet, should be 0. -// -// Postconditions: -// -// Returns: NULL if n is not zero, -// a new TIFFTranslator if n is zero -// --------------------------------------------------------------- -BTranslator * -make_nth_translator(int32 n, image_id you, uint32 flags, ...) -{ - if (!n) - return new TIFFTranslator(); - else - return NULL; -} - -TiffDetails::TiffDetails() -{ - memset(this, 0, sizeof(TiffDetails)); -} - -TiffDetails::~TiffDetails() -{ - delete[] pstripOffsets; - delete[] pstripByteCounts; - delete[] pcolorMap; - - memset(this, 0, sizeof(TiffDetails)); -} - -// --------------------------------------------------------------- -// Constructor -// -// Sets up the version info and the name of the translator so that -// these values can be returned when they are requested. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFTranslator::TIFFTranslator() - : BTranslator() -{ - fpblackTree = NULL; - fpwhiteTree = NULL; - - strcpy(fName, "TIFF Images"); - sprintf(fInfo, "TIFF image translator v%d.%d.%d %s", - TIFF_TRANSLATOR_VERSION / 100, (TIFF_TRANSLATOR_VERSION / 10) % 10, - TIFF_TRANSLATOR_VERSION % 10, __DATE__); -} - -// --------------------------------------------------------------- -// Destructor -// -// Does nothing -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFTranslator::~TIFFTranslator() -{ - delete fpblackTree; - fpblackTree = NULL; - delete fpwhiteTree; - fpwhiteTree = NULL; -} - -// --------------------------------------------------------------- -// TranslatorName -// -// Returns the short name of the translator. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: a const char * to the short name of the translator -// --------------------------------------------------------------- -const char * -TIFFTranslator::TranslatorName() const -{ - return fName; -} - -// --------------------------------------------------------------- -// TranslatorInfo -// -// Returns a more verbose name for the translator than the one -// TranslatorName() returns. This usually includes version info. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: a const char * to the verbose name of the translator -// --------------------------------------------------------------- -const char * -TIFFTranslator::TranslatorInfo() const -{ - return fInfo; -} - -// --------------------------------------------------------------- -// TranslatorVersion -// -// Returns the integer representation of the current version of -// this translator. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -int32 -TIFFTranslator::TranslatorVersion() const -{ - return TIFF_TRANSLATOR_VERSION; -} - -// --------------------------------------------------------------- -// InputFormats -// -// Returns a list of input formats supported by this translator. -// -// Preconditions: -// -// Parameters: out_count, The number of input formats -// support is returned here. -// -// Postconditions: -// -// Returns: the list of input formats and the number of input -// formats through the out_count parameter, if out_count is NULL, -// NULL is returned -// --------------------------------------------------------------- -const translation_format * -TIFFTranslator::InputFormats(int32 *out_count) const -{ - if (out_count) { - *out_count = sizeof(gInputFormats) / - sizeof(translation_format); - return gInputFormats; - } else - return NULL; -} - -// --------------------------------------------------------------- -// OutputFormats -// -// Returns a list of output formats supported by this translator. -// -// Preconditions: -// -// Parameters: out_count, The number of output formats -// support is returned here. -// -// Postconditions: -// -// Returns: the list of output formats and the number of output -// formats through the out_count parameter, if out_count is NULL, -// NULL is returned -// --------------------------------------------------------------- -const translation_format * -TIFFTranslator::OutputFormats(int32 *out_count) const -{ - if (out_count) { - *out_count = sizeof(gOutputFormats) / - sizeof(translation_format); - return gOutputFormats; - } else - return NULL; -} - -// --------------------------------------------------------------- -// identify_bits_header -// -// Determines if the data in inSource is in the -// B_TRANSLATOR_BITMAP ('bits') format. If it is, it returns -// info about the data in inSource to outInfo and pheader. -// -// Preconditions: -// -// Parameters: inSource, The source of the image data -// -// outInfo, Information about the translator -// is copied here -// -// amtread, Amount of data read from inSource -// before this function was called -// -// read, Pointer to the data that was read -// in before this function was called -// -// pheader, The bits header is copied here after -// it is read in from inSource -// -// Postconditions: -// -// Returns: B_NO_TRANSLATOR, if the data does not look like -// bits format data -// -// B_ERROR, if the header data could not be converted to host -// format -// -// B_OK, if the data looks like bits data and no errors were -// encountered -// --------------------------------------------------------------- -status_t -identify_bits_header(BPositionIO *inSource, translator_info *outInfo, - ssize_t amtread, uint8 *read, TranslatorBitmap *pheader = NULL) -{ - TranslatorBitmap header; - - memcpy(&header, read, amtread); - // copy portion of header already read in - // read in the rest of the header - ssize_t size = sizeof(TranslatorBitmap) - amtread; - if (inSource->Read( - (reinterpret_cast (&header)) + amtread, size) != size) - return B_NO_TRANSLATOR; - - // convert to host byte order - if (swap_data(B_UINT32_TYPE, &header, sizeof(TranslatorBitmap), - B_SWAP_BENDIAN_TO_HOST) != B_OK) - return B_ERROR; - - // check if header values are reasonable - if (header.colors != B_RGB32 && - header.colors != B_RGB32_BIG && - header.colors != B_RGBA32 && - header.colors != B_RGBA32_BIG && - header.colors != B_RGB24 && - header.colors != B_RGB24_BIG && - header.colors != B_RGB16 && - header.colors != B_RGB16_BIG && - header.colors != B_RGB15 && - header.colors != B_RGB15_BIG && - header.colors != B_RGBA15 && - header.colors != B_RGBA15_BIG && - header.colors != B_CMAP8 && - header.colors != B_GRAY8 && - header.colors != B_GRAY1 && - header.colors != B_CMYK32 && - header.colors != B_CMY32 && - header.colors != B_CMYA32 && - header.colors != B_CMY24) - return B_NO_TRANSLATOR; - if (header.rowBytes * (header.bounds.Height() + 1) != header.dataSize) - return B_NO_TRANSLATOR; - - if (outInfo) { - outInfo->type = B_TRANSLATOR_BITMAP; - outInfo->group = B_TRANSLATOR_BITMAP; - outInfo->quality = BBT_IN_QUALITY; - outInfo->capability = BBT_IN_CAPABILITY; - strcpy(outInfo->name, "Be Bitmap Format (TIFFTranslator)"); - strcpy(outInfo->MIME, "image/x-be-bitmap"); - } - - if (pheader) { - pheader->magic = header.magic; - pheader->bounds = header.bounds; - pheader->rowBytes = header.rowBytes; - pheader->colors = header.colors; - pheader->dataSize = header.dataSize; - } - - return B_OK; -} - -// If this TIFF has unsupported features, -// return B_NO_TRANSLATOR, otherwise, -// return B_OK -status_t -check_tiff_fields(TiffIfd &ifd, TiffDetails *pdetails, bool bAllocArrays) -{ - if (!pdetails) - return B_BAD_VALUE; - - try { - // Extra Samples are not yet supported - if (ifd.HasField(TAG_EXTRA_SAMPLES)) - return B_NO_TRANSLATOR; - - // Only the default values are supported for the - // following fields. HasField is called so that - // if a field is not present, a TiffIfdFieldNotFoundException - // will not be thrown when GetUint is called. - // (If they are not present, that is fine, but if - // they are present and have a non-default value, - // that is a problem) - if (ifd.HasField(TAG_ORIENTATION) && - ifd.GetUint(TAG_ORIENTATION) != 1) - return B_NO_TRANSLATOR; - if (ifd.HasField(TAG_PLANAR_CONFIGURATION) && - ifd.GetUint(TAG_PLANAR_CONFIGURATION) != 1) - return B_NO_TRANSLATOR; - if (ifd.HasField(TAG_SAMPLE_FORMAT) && - ifd.GetUint(TAG_SAMPLE_FORMAT) != 1) - return B_NO_TRANSLATOR; - - // Copy fields useful to TIFFTranslator - uint32 width = ifd.GetUint(TAG_IMAGE_WIDTH); - uint32 height = ifd.GetUint(TAG_IMAGE_HEIGHT); - uint16 interpretation = ifd.GetUint(TAG_PHOTO_INTERPRETATION); - - uint32 compression; - if (!ifd.HasField(TAG_COMPRESSION)) - compression = COMPRESSION_NONE; - else - compression = ifd.GetUint(TAG_COMPRESSION); - - uint32 t4options = 0; - uint16 imageType = 0, bitsPerPixel = 0, fillOrder = 1; - switch (interpretation) { - // black and white or grayscale images - case PHOTO_WHITEZERO: - case PHOTO_BLACKZERO: - // default value for samples per pixel is 1 - if (ifd.HasField(TAG_SAMPLES_PER_PIXEL) && - ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 1) - return B_NO_TRANSLATOR; - - // Only 1D and fill byte boundary t4options are - // supported - if (ifd.HasField(TAG_T4_OPTIONS)) - t4options = ifd.GetUint(TAG_T4_OPTIONS); - if (t4options != 0 && t4options != T4_FILL_BYTE_BOUNDARY) - return B_NO_TRANSLATOR; - - // default value for bits per sample is 1 - if (!ifd.HasField(TAG_BITS_PER_SAMPLE) || - ifd.GetUint(TAG_BITS_PER_SAMPLE) == 1) { - bitsPerPixel = 1; - - if (compression != COMPRESSION_NONE && - compression != COMPRESSION_HUFFMAN && - compression != COMPRESSION_T4 && - compression != COMPRESSION_PACKBITS) - return B_NO_TRANSLATOR; - - if (ifd.HasField(TAG_FILL_ORDER)) { - fillOrder = ifd.GetUint(TAG_FILL_ORDER); - if (fillOrder != 1 && fillOrder != 2) - return B_NO_TRANSLATOR; - } - - } else if (ifd.GetUint(TAG_BITS_PER_SAMPLE) == 4 || - ifd.GetUint(TAG_BITS_PER_SAMPLE) == 8) { - bitsPerPixel = ifd.GetUint(TAG_BITS_PER_SAMPLE); - - if (ifd.HasField(TAG_FILL_ORDER) && - ifd.GetUint(TAG_FILL_ORDER) != 1) - return B_NO_TRANSLATOR; - if (compression != COMPRESSION_NONE && - compression != COMPRESSION_PACKBITS) - return B_NO_TRANSLATOR; - } else - return B_NO_TRANSLATOR; - - imageType = TIFF_BILEVEL; - - break; - - // Palette color images - case PHOTO_PALETTE: - if (ifd.HasField(TAG_FILL_ORDER) && - ifd.GetUint(TAG_FILL_ORDER) != 1) - return B_NO_TRANSLATOR; - if (compression != COMPRESSION_NONE && - compression != COMPRESSION_PACKBITS) - return B_NO_TRANSLATOR; - - // default value for samples per pixel is 1 - if (ifd.HasField(TAG_SAMPLES_PER_PIXEL) && - ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 1) - return B_NO_TRANSLATOR; - - bitsPerPixel = ifd.GetUint(TAG_BITS_PER_SAMPLE); - if (bitsPerPixel != 4 && bitsPerPixel != 8) - return B_NO_TRANSLATOR; - - // ensure that the color map is the expected length - if (ifd.GetCount(TAG_COLOR_MAP) != - (uint32) (3 * (1 << bitsPerPixel))) - return B_NO_TRANSLATOR; - - imageType = TIFF_PALETTE; - break; - - case PHOTO_RGB: - if (ifd.HasField(TAG_FILL_ORDER) && - ifd.GetUint(TAG_FILL_ORDER) != 1) - return B_NO_TRANSLATOR; - if (compression != COMPRESSION_NONE && - compression != COMPRESSION_PACKBITS) - return B_NO_TRANSLATOR; - - if (ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 3) - return B_NO_TRANSLATOR; - if (ifd.GetCount(TAG_BITS_PER_SAMPLE) != 3 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 1) != 8 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 2) != 8 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 3) != 8) - return B_NO_TRANSLATOR; - - imageType = TIFF_RGB; - break; - - case PHOTO_SEPARATED: - if (ifd.HasField(TAG_FILL_ORDER) && - ifd.GetUint(TAG_FILL_ORDER) != 1) - return B_NO_TRANSLATOR; - if (compression != COMPRESSION_NONE && - compression != COMPRESSION_PACKBITS) - return B_NO_TRANSLATOR; - - // CMYK (default ink set) - // is the only ink set supported - if (ifd.HasField(TAG_INK_SET) && - ifd.GetUint(TAG_INK_SET) != INK_SET_CMYK) - return B_NO_TRANSLATOR; - - if (ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 4) - return B_NO_TRANSLATOR; - if (ifd.GetCount(TAG_BITS_PER_SAMPLE) != 4 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 1) != 8 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 2) != 8 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 3) != 8 || - ifd.GetUint(TAG_BITS_PER_SAMPLE, 4) != 8) - return B_NO_TRANSLATOR; - - imageType = TIFF_CMYK; - break; - - default: - return B_NO_TRANSLATOR; - } - - uint32 rowsPerStrip, stripsPerImage; - if (!ifd.HasField(TAG_ROWS_PER_STRIP)) - rowsPerStrip = DEFAULT_ROWS_PER_STRIP; - else - rowsPerStrip = ifd.GetUint(TAG_ROWS_PER_STRIP); - if (rowsPerStrip == DEFAULT_ROWS_PER_STRIP) - stripsPerImage = 1; - else - stripsPerImage = (height + rowsPerStrip - 1) / rowsPerStrip; - - if (ifd.GetCount(TAG_STRIP_OFFSETS) != stripsPerImage || - ifd.GetCount(TAG_STRIP_BYTE_COUNTS) != stripsPerImage) - return B_NO_TRANSLATOR; - - // return read in details - pdetails->width = width; - pdetails->height = height; - pdetails->compression = compression; - pdetails->t4options = t4options; - pdetails->rowsPerStrip = rowsPerStrip; - pdetails->stripsPerImage = stripsPerImage; - pdetails->interpretation = interpretation; - pdetails->bitsPerPixel = bitsPerPixel; - pdetails->imageType = imageType; - pdetails->fillOrder = fillOrder; - - if (bAllocArrays) { - ifd.GetUint32Array(TAG_STRIP_OFFSETS, - &pdetails->pstripOffsets); - ifd.GetUint32Array(TAG_STRIP_BYTE_COUNTS, - &pdetails->pstripByteCounts); - - if (pdetails->imageType == TIFF_PALETTE) - ifd.GetAdjustedColorMap(&pdetails->pcolorMap); - } - - } catch (TiffIfdException) { - return B_NO_TRANSLATOR; - } - - return B_OK; -} - -// copy descriptive information about the TIFF image -// into strname -void -copy_tiff_name(char *strname, TiffDetails *pdetails, swap_action swp) -{ - if (!strname || !pdetails) - return; - - strcpy(strname, "TIFF image ("); - - // byte order - if (swp == B_SWAP_BENDIAN_TO_HOST) - strcat(strname, "Big, "); - else - strcat(strname, "Little, "); - - // image type - const char *strtype = NULL; - switch (pdetails->imageType) { - case TIFF_BILEVEL: - if (pdetails->bitsPerPixel == 1) - strtype = "Mono, "; - else - strtype = "Gray, "; - break; - case TIFF_PALETTE: - strtype = "Palette, "; - break; - case TIFF_RGB: - strtype = "RGB, "; - break; - case TIFF_CMYK: - strtype = "CMYK, "; - break; - default: - strtype = "??, "; - break; - } - strcat(strname, strtype); - - // compression - const char *strcomp = NULL; - switch (pdetails->compression) { - case COMPRESSION_NONE: - strcomp = "None)"; - break; - case COMPRESSION_HUFFMAN: - strcomp = "Huffman)"; - break; - case COMPRESSION_T4: - strcomp = "Group 3)"; - break; - case COMPRESSION_T6: - strcomp = "Group 4)"; - break; - case COMPRESSION_LZW: - strcomp = "LZW)"; - break; - case COMPRESSION_PACKBITS: - strcomp = "PackBits)"; - break; - default: - strcomp = "??)"; - break; - } - strcat(strname, strcomp); -} - -status_t -identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension, - translator_info *outInfo, ssize_t amtread, uint8 *read, swap_action swp, - TiffDetails *pdetails = NULL) -{ - if (amtread != 4) - return B_ERROR; - - uint32 firstIFDOffset = 0; - ssize_t nread = inSource->Read(&firstIFDOffset, 4); - if (nread != 4) { - // Unable to read first IFD offset - return B_NO_TRANSLATOR; - } - if (swap_data(B_UINT32_TYPE, &firstIFDOffset, - sizeof(uint32), swp) != B_OK) { - // swap_data() error - return B_ERROR; - } - TiffIfdList ifdlist(firstIFDOffset, *inSource, swp); - - status_t initcheck; - initcheck = ifdlist.InitCheck(); - - // Read in some fields in order to determine whether or not - // this particular TIFF image is supported by this translator - - // Check the required fields - if (initcheck == B_OK) { - - int32 document_count, document_index = 1; - document_count = ifdlist.GetCount(); - - if (ioExtension) { - // Add page count to ioExtension - ioExtension->RemoveName(DOCUMENT_COUNT); - ioExtension->AddInt32(DOCUMENT_COUNT, document_count); - - // Check if a document index has been specified - ioExtension->FindInt32(DOCUMENT_INDEX, &document_index); - if (document_index < 1 || document_index > document_count) - return B_NO_TRANSLATOR; - } - - // Identify the page the user asked for - TiffIfd *pifd = ifdlist.GetIfd(document_index - 1); - - bool bAllocArrays = true; - TiffDetails localdetails; - if (!pdetails) { - bAllocArrays = false; - pdetails = &localdetails; - } - status_t result; - result = check_tiff_fields(*pifd, pdetails, bAllocArrays); - - if (result == B_OK && outInfo) { - outInfo->type = B_TIFF_FORMAT; - outInfo->group = B_TRANSLATOR_BITMAP; - outInfo->quality = TIFF_IN_QUALITY; - outInfo->capability = TIFF_IN_CAPABILITY; - strcpy(outInfo->MIME, "image/tiff"); - - copy_tiff_name(outInfo->name, pdetails, swp); - } - - return result; - } - - if (initcheck != B_ERROR && initcheck != B_NO_MEMORY) - // return B_NO_TRANSLATOR if unexpected data was encountered - return B_NO_TRANSLATOR; - else - // return B_ERROR or B_NO_MEMORY - return initcheck; -} - -// --------------------------------------------------------------- -// Identify -// -// Examines the data from inSource and determines if it is in a -// format that this translator knows how to work with. -// -// Preconditions: -// -// Parameters: inSource, where the data to examine is -// -// inFormat, a hint about the data in inSource, -// it is ignored since it is only a hint -// -// ioExtension, configuration settings for the -// translator (not used) -// -// outInfo, information about what data is in -// inSource and how well this translator -// can handle that data is stored here -// -// outType, The format that the user wants -// the data in inSource to be -// converted to -// -// Postconditions: -// -// Returns: B_NO_TRANSLATOR, if this translator can't handle -// the data in inSource -// -// B_ERROR, if there was an error converting the data to the host -// format -// -// B_BAD_VALUE, if the settings in ioExtension are bad -// -// B_OK, if this translator understood the data and there were -// no errors found -// -// Other errors if BPositionIO::Read() returned an error value -// --------------------------------------------------------------- -status_t -TIFFTranslator::Identify(BPositionIO *inSource, - const translation_format *inFormat, BMessage *ioExtension, - translator_info *outInfo, uint32 outType) -{ - if (!outType) - outType = B_TRANSLATOR_BITMAP; - if (outType != B_TRANSLATOR_BITMAP && outType != B_TIFF_FORMAT) - return B_NO_TRANSLATOR; - - // Convert the magic numbers to the various byte orders so that - // I won't have to convert the data read in to see whether or not - // it is a supported type - uint32 nbits = B_TRANSLATOR_BITMAP; - if (swap_data(B_UINT32_TYPE, &nbits, sizeof(uint32), - B_SWAP_HOST_TO_BENDIAN) != B_OK) - return B_ERROR; - - // Read in the magic number and determine if it - // is a supported type - uint8 ch[4]; - if (inSource->Read(ch, 4) != 4) - return B_NO_TRANSLATOR; - - // Read settings from ioExtension - bool bheaderonly = false, bdataonly = false; - if (ioExtension) { - if (ioExtension->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderonly)) - // if failed, make sure bool is default value - bheaderonly = false; - if (ioExtension->FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataonly)) - // if failed, make sure bool is default value - bdataonly = false; - - if (bheaderonly && bdataonly) - // can't both "only write the header" and "only write the data" - // at the same time - return B_BAD_VALUE; - } - - uint32 n32ch; - memcpy(&n32ch, ch, sizeof(uint32)); - // if B_TRANSLATOR_BITMAP type - if (n32ch == nbits) - return identify_bits_header(inSource, outInfo, 4, ch); - - // Might be TIFF image - else { - // TIFF Byte Order / Magic - const uint8 kleSig[] = { 0x49, 0x49, 0x2a, 0x00 }; - const uint8 kbeSig[] = { 0x4d, 0x4d, 0x00, 0x2a }; - - swap_action swp; - if (memcmp(ch, kleSig, 4) == 0) { - swp = B_SWAP_LENDIAN_TO_HOST; - // Byte Order: little endian - } else if (memcmp(ch, kbeSig, 4) == 0) { - swp = B_SWAP_BENDIAN_TO_HOST; - // Byte Order: big endian - } else { - // If not a TIFF or a Be Bitmap image - // (invalid byte order value) - return B_NO_TRANSLATOR; - } - - return identify_tiff_header(inSource, ioExtension, outInfo, 4, ch, swp); - } -} - -void -tiff_to_bits(uint8 *ptiff, uint32 tifflen, uint8 *pbits, TiffDetails &details) -{ - uint8 *ptiffend = ptiff + tifflen; - - switch (details.imageType) { - case TIFF_BILEVEL: - if (details.bitsPerPixel == 1) { - // black and white - uint8 black[3] = { 0x00, 0x00, 0x00 }, - white[3] = { 0xFF, 0xFF, 0xFF }; - uint8 *colors[2]; - if (details.interpretation == PHOTO_WHITEZERO) { - colors[0] = white; - colors[1] = black; - } else { - colors[0] = black; - colors[1] = white; - } - - for (uint32 i = 0; i < details.width; i++) { - uint8 eightbits = (ptiff + (i / 8))[0]; - uint8 abit; - abit = (eightbits >> (7 - (i % 8))) & 1; - - memcpy(pbits + (i * 4), colors[abit], 3); - } - } else { - // grayscale - if (details.bitsPerPixel == 8) { - if (details.interpretation == PHOTO_WHITEZERO) { - for (uint32 i = 0; i < details.width; i++) { - memset(pbits, 255 - ptiff[i], 3); - pbits += 4; - } - } else { - for (uint32 i = 0; i < details.width; i++) { - memset(pbits, ptiff[i], 3); - pbits += 4; - } - } - } else if (details.bitsPerPixel == 4) { - const uint8 mask = 0x0f; - if (details.interpretation == PHOTO_WHITEZERO) { - for (uint32 i = 0; i < details.width; i++) { - uint8 values = (ptiff + (i / 2))[0]; - uint8 value = (values >> (4 * (1 - (i % 2)))) & mask; - memset(pbits, 255 - (value * 16), 3); - pbits += 4; - } - } else { - for (uint32 i = 0; i < details.width; i++) { - uint8 values = (ptiff + (i / 2))[0]; - uint8 value = (values >> (4 * (1 - (i % 2)))) & mask; - memset(pbits, (value * 16), 3); - pbits += 4; - } - } - } - } - - break; - - case TIFF_PALETTE: - { - // NOTE: All of the entries in the color map were - // divided by 256 before they were copied to pcolorMap. - // - // The first 3rd of the color map is made of the Red values, - // the second 3rd of the color map is made of the Green values, - // and the last 3rd of the color map is made of the Blue values. - if (details.bitsPerPixel == 8) { - for (uint32 i = 0; i < details.width; i++) { - pbits[2] = details.pcolorMap[ptiff[i]]; - pbits[1] = details.pcolorMap[256 + ptiff[i]]; - pbits[0] = details.pcolorMap[512 + ptiff[i]]; - - pbits += 4; - } - } else if (details.bitsPerPixel == 4) { - const uint8 mask = 0x0f; - for (uint32 i = 0; i < details.width; i++) { - uint8 indices = (ptiff + (i / 2))[0]; - uint8 index = (indices >> (4 * (1 - (i % 2)))) & mask; - - pbits[2] = details.pcolorMap[index]; - pbits[1] = details.pcolorMap[16 + index]; - pbits[0] = details.pcolorMap[32 + index]; - - pbits += 4; - } - } - break; - } - - case TIFF_RGB: - while (ptiff < ptiffend) { - pbits[2] = ptiff[0]; - pbits[1] = ptiff[1]; - pbits[0] = ptiff[2]; - - ptiff += 3; - pbits += 4; - } - break; - - case TIFF_CMYK: - { - while (ptiff < ptiffend) { - int32 comp; - comp = 255 - ptiff[0] - ptiff[3]; - pbits[2] = (comp < 0) ? 0 : comp; - - comp = 255 - ptiff[1] - ptiff[3]; - pbits[1] = (comp < 0) ? 0 : comp; - - comp = 255 - ptiff[2] - ptiff[3]; - pbits[0] = (comp < 0) ? 0 : comp; - - ptiff += 4; - pbits += 4; - } - break; - } - } -} - -// unpack the Packbits compressed data from -// pstreambuf and put it into tiffbuffer -ssize_t -unpack(StreamBuffer *pstreambuf, uint8 *tiffbuffer, uint32 tiffbufferlen) -{ - uint32 tiffwrit = 0, read = 0, len; - while (tiffwrit < tiffbufferlen) { - - uint8 uctrl; - if (pstreambuf->Read(&uctrl, 1) != 1) - return B_ERROR; - read++; - - int32 control; - control = static_cast(uctrl); - - // copy control + 1 bytes literally - if (control >= 0 && control <= 127) { - - len = control + 1; - if (tiffwrit + len > tiffbufferlen) - return B_ERROR; - if (pstreambuf->Read(tiffbuffer + tiffwrit, len) != - static_cast(len)) - return B_ERROR; - read += len; - - tiffwrit += len; - - // copy the next byte (-control) + 1 times - } else if (control >= -127 && control <= -1) { - - uint8 byt; - if (pstreambuf->Read(&byt, 1) != 1) - return B_ERROR; - read++; - - len = (-control) + 1; - if (tiffwrit + len > tiffbufferlen) - return B_ERROR; - memset(tiffbuffer + tiffwrit, byt, len); - - tiffwrit += len; - } - } - - return read; -} - -ssize_t -TIFFTranslator::decode_t4(BitReader &stream, TiffDetails &details, - uint8 *pbits, bool bfirstLine) -{ - if (bfirstLine) { - // determine number of fill bits - // (if that T4Option is set) - uint32 fillbits = 0; - if (details.t4options & T4_FILL_BYTE_BOUNDARY) { - fillbits = (12 - stream.BitsInBuffer()) % 8; - if (fillbits) - fillbits = 8 - fillbits; - } - // read in and verify end-of-line sequence - uint32 nzeros = 11 + fillbits; - while (nzeros--) { - if (stream.NextBit() != 0) { - debugger("EOL: expected zero bit"); - return B_ERROR; - } - } - if (stream.NextBit() != 1) { - debugger("EOL: expected one bit"); - return B_ERROR; - } - } - - const uint8 kblack = 0x00, kwhite = 0xff; - uint8 colors[2]; - if (details.interpretation == PHOTO_WHITEZERO) { - colors[0] = kwhite; - colors[1] = kblack; - } else { - colors[0] = kblack; - colors[1] = kwhite; - } - - uint32 pixelswrit = 0; - DecodeTree *ptrees[2] = {fpwhiteTree, fpblackTree}; - uint8 currentcolor = 0; - uint8 *pcurrentpixel = pbits; - status_t value = 0; - while (pixelswrit < details.width || value >= 64) { - value = ptrees[currentcolor]->GetValue(stream); - if (value < 0) { - debugger("value < 0"); - return B_ERROR; - } - - if (pixelswrit + value > details.width) { - debugger("gone past end of line"); - return B_ERROR; - } - pixelswrit += value; - - // covert run length to B_RGB32 pixels - uint32 pixelsleft = value; - while (pixelsleft--) { - memset(pcurrentpixel, colors[currentcolor], 3); - pcurrentpixel += 4; - } - - if (value < 64) - currentcolor = 1 - currentcolor; - } - - // determine number of fill bits - // (if that T4Option is set) - uint32 fillbits = 0; - if (details.t4options & T4_FILL_BYTE_BOUNDARY) { - fillbits = (12 - stream.BitsInBuffer()) % 8; - if (fillbits) - fillbits = 8 - fillbits; - } - // read in end-of-line sequence - uint32 ndontcare = 12 + fillbits; - status_t sbit = 0; - while (ndontcare--) { - sbit = stream.NextBit(); - if (sbit != 0 && sbit != 1) { - debugger("EOL: couldn't read all bits"); - return B_ERROR; - } - } - - return stream.BytesRead(); -} - -ssize_t -TIFFTranslator::decode_huffman(StreamBuffer *pstreambuf, TiffDetails &details, - uint8 *pbits) -{ - BitReader stream(details.fillOrder, pstreambuf); - if (stream.InitCheck() != B_OK) { - debugger("stream init error"); - return B_ERROR; - } - - const uint8 kblack = 0x00, kwhite = 0xff; - uint8 colors[2]; - if (details.interpretation == PHOTO_WHITEZERO) { - colors[0] = kwhite; - colors[1] = kblack; - } else { - colors[0] = kblack; - colors[1] = kwhite; - } - - uint32 pixelswrit = 0; - DecodeTree *ptrees[2] = {fpwhiteTree, fpblackTree}; - uint8 currentcolor = 0; - uint8 *pcurrentpixel = pbits; - status_t value = 0; - while (pixelswrit < details.width || value >= 64) { - value = ptrees[currentcolor]->GetValue(stream); - if (value < 0) { - debugger("value < 0"); - return B_ERROR; - } - - if (pixelswrit + value > details.width) { - debugger("gone past end of line"); - return B_ERROR; - } - pixelswrit += value; - - // covert run length to B_RGB32 pixels - uint32 pixelsleft = value; - while (pixelsleft--) { - memset(pcurrentpixel, colors[currentcolor], 3); - pcurrentpixel += 4; - } - - if (value < 64) - currentcolor = 1 - currentcolor; - } - - return stream.BytesRead(); -} - -status_t -TIFFTranslator::translate_from_tiff(BPositionIO *inSource, - BMessage *ioExtension, ssize_t amtread, uint8 *read, swap_action swp, - uint32 outType, BPositionIO *outDestination) -{ - // Can only output to bits for now - if (outType != B_TRANSLATOR_BITMAP) - return B_NO_TRANSLATOR; - - status_t result; - - TiffDetails details; - result = identify_tiff_header(inSource, ioExtension, NULL, - amtread, read, swp, &details); - if (result == B_OK) { - // If the TIFF is supported by this translator - - // If TIFF uses Huffman compression, load - // trees for decoding Huffman compression - if (details.compression == COMPRESSION_HUFFMAN || - details.compression == COMPRESSION_T4) { - result = LoadHuffmanTrees(); - if (result != B_OK) - return result; - } - - TranslatorBitmap bitsHeader; - bitsHeader.magic = B_TRANSLATOR_BITMAP; - bitsHeader.bounds.left = 0; - bitsHeader.bounds.top = 0; - bitsHeader.bounds.right = details.width - 1; - bitsHeader.bounds.bottom = details.height - 1; - bitsHeader.rowBytes = 4 * details.width; - bitsHeader.colors = B_RGB32; - bitsHeader.dataSize = bitsHeader.rowBytes * details.height; - - // write out Be's Bitmap header - if (swap_data(B_UINT32_TYPE, &bitsHeader, - sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN) != B_OK) - return B_ERROR; - outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap)); - - uint32 inbufferlen, outbufferlen; - outbufferlen = 4 * details.width; - switch (details.imageType) { - case TIFF_BILEVEL: - case TIFF_PALETTE: - { - uint32 pixelsPerByte = 8 / details.bitsPerPixel; - inbufferlen = (details.width / pixelsPerByte) + - ((details.width % pixelsPerByte) ? 1 : 0); - break; - } - case TIFF_RGB: - inbufferlen = 3 * details.width; - break; - - case TIFF_CMYK: - inbufferlen = 4 * details.width; - break; - - default: - // just to be safe - return B_NO_TRANSLATOR; - } - - uint8 *inbuffer = new uint8[inbufferlen], - *outbuffer = new uint8[outbufferlen]; - if (!inbuffer || !outbuffer) - return B_NO_MEMORY; - // set all channels to 0xff so that I won't have - // to set the alpha byte to 0xff every time - memset(outbuffer, 0xff, outbufferlen); - - // buffer for making reading compressed data - // fast and convenient - StreamBuffer *pstreambuf = NULL; - BitReader bitreader(details.fillOrder, pstreambuf, false); - // this creates an invalid bitreader, but it is - // initialized properly with the SetTo() call - if (details.compression != COMPRESSION_NONE) { - pstreambuf = new StreamBuffer(inSource, 2048, false); - if (pstreambuf->InitCheck() != B_OK) - return B_NO_MEMORY; - } - - bool bfirstLine = true; - for (uint32 i = 0; i < details.stripsPerImage; i++) { - uint32 read = 0; - - // If using compression, prepare streambuffer - // for reading - if (details.compression != COMPRESSION_NONE && - !pstreambuf->Seek(details.pstripOffsets[i])) - return B_NO_TRANSLATOR; - - if (details.compression == COMPRESSION_T4 && - bitreader.SetTo(details.fillOrder, pstreambuf) != B_OK) - return B_NO_TRANSLATOR; - - // Read / Write one line at a time for each - // line in the strip - while (read < details.pstripByteCounts[i]) { - - ssize_t ret = 0; - switch (details.compression) { - case COMPRESSION_NONE: - ret = inSource->ReadAt(details.pstripOffsets[i] + read, - inbuffer, inbufferlen); - if (ret != static_cast(inbufferlen)) - // break out of while loop - ret = -1; - break; - - case COMPRESSION_HUFFMAN: - ret = decode_huffman(pstreambuf, details, outbuffer); - if (ret < 1) - // break out of while loop - ret = -1; - break; - - case COMPRESSION_T4: - ret = decode_t4(bitreader, details, outbuffer, - bfirstLine); - if (ret < 1) - // break out of while loop - ret = -1; - else - ret -= read; - // unlike other decoders, decode_t4 retruns - // the total bytes read from the current - // strip - break; - - case COMPRESSION_PACKBITS: - ret = unpack(pstreambuf, inbuffer, inbufferlen); - if (ret < 1) - // break out of while loop - ret = -1; - break; - } - if (ret < 0) - break; - - read += ret; - if (details.compression != COMPRESSION_HUFFMAN && - details.compression != COMPRESSION_T4) - tiff_to_bits(inbuffer, inbufferlen, outbuffer, details); - outDestination->Write(outbuffer, outbufferlen); - bfirstLine = false; - } - // If while loop was broken... - if (read < details.pstripByteCounts[i]) { - debugger("while loop broken"); - break; - } - } - - // Clean up - if (pstreambuf) { - delete pstreambuf; - pstreambuf = NULL; - } - - delete[] inbuffer; - inbuffer = NULL; - delete[] outbuffer; - outbuffer = NULL; - - return B_OK; - - } else - return result; -} - -// --------------------------------------------------------------- -// Translate -// -// Translates the data in inSource to the type outType and stores -// the translated data in outDestination. -// -// Preconditions: -// -// Parameters: inSource, the data to be translated -// -// inInfo, hint about the data in inSource (not used) -// -// ioExtension, configuration options for the -// translator -// -// outType, the type to convert inSource to -// -// outDestination, where the translated data is -// put -// -// Postconditions: -// -// Returns: B_BAD_VALUE, if the options in ioExtension are bad -// -// B_NO_TRANSLATOR, if this translator doesn't understand the data -// -// B_ERROR, if there was an error allocating memory or converting -// data -// -// B_OK, if all went well -// --------------------------------------------------------------- -status_t -TIFFTranslator::Translate(BPositionIO *inSource, - const translator_info *inInfo, BMessage *ioExtension, - uint32 outType, BPositionIO *outDestination) -{ - if (!outType) - outType = B_TRANSLATOR_BITMAP; - if (outType != B_TRANSLATOR_BITMAP && outType != B_TIFF_FORMAT) - return B_NO_TRANSLATOR; - - // Convert the magic numbers to the various byte orders so that - // I won't have to convert the data read in to see whether or not - // it is a supported type - uint32 nbits = B_TRANSLATOR_BITMAP; - if (swap_data(B_UINT32_TYPE, &nbits, sizeof(uint32), - B_SWAP_HOST_TO_BENDIAN) != B_OK) - return B_ERROR; - - // Read in the magic number and determine if it - // is a supported type - uint8 ch[4]; - inSource->Seek(0, SEEK_SET); - if (inSource->Read(ch, 4) != 4) - return B_NO_TRANSLATOR; - - // Read settings from ioExtension - bool bheaderonly = false, bdataonly = false; - if (ioExtension) { - if (ioExtension->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderonly)) - // if failed, make sure bool is default value - bheaderonly = false; - if (ioExtension->FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataonly)) - // if failed, make sure bool is default value - bdataonly = false; - - if (bheaderonly && bdataonly) - // can't both "only write the header" and "only write the data" - // at the same time - return B_BAD_VALUE; - } - - uint32 n32ch; - memcpy(&n32ch, ch, sizeof(uint32)); - // if B_TRANSLATOR_BITMAP type - if (n32ch == nbits) - return B_NO_TRANSLATOR; - // Not implemented yet - - // Might be TIFF image - else { - // TIFF Byte Order / Magic - const uint8 kleSig[] = { 0x49, 0x49, 0x2a, 0x00 }; - const uint8 kbeSig[] = { 0x4d, 0x4d, 0x00, 0x2a }; - - swap_action swp; - if (memcmp(ch, kleSig, 4) == 0) { - swp = B_SWAP_LENDIAN_TO_HOST; - // Byte Order: little endian - } else if (memcmp(ch, kbeSig, 4) == 0) { - swp = B_SWAP_BENDIAN_TO_HOST; - // Byte Order: big endian - } else { - // If not a TIFF or a Be Bitmap image - // (invalid byte order value) - return B_NO_TRANSLATOR; - } - - return translate_from_tiff(inSource, ioExtension, 4, ch, swp, outType, - outDestination); - } -} - -// --------------------------------------------------------------- -// MakeConfigurationView -// -// Makes a BView object for configuring / displaying info about -// this translator. -// -// Preconditions: -// -// Parameters: ioExtension, configuration options for the -// translator -// -// outView, the view to configure the -// translator is stored here -// -// outExtent, the bounds of the view are -// stored here -// -// Postconditions: -// -// Returns: B_BAD_VALUE if outView or outExtent is NULL, -// B_NO_MEMORY if the view couldn't be allocated, -// B_OK if no errors -// --------------------------------------------------------------- -status_t -TIFFTranslator::MakeConfigurationView(BMessage *ioExtension, BView **outView, - BRect *outExtent) -{ - if (!outView || !outExtent) - return B_BAD_VALUE; - - TIFFView *view = new TIFFView(BRect(0, 0, 225, 175), - "TIFFTranslator Settings", B_FOLLOW_ALL, B_WILL_DRAW); - if (!view) - return B_NO_MEMORY; - - *outView = view; - *outExtent = view->Bounds(); - - return B_OK; -} - -// Initialize the Huffman decoding trees and -// verify that there were no initialization errors -status_t -TIFFTranslator::LoadHuffmanTrees() -{ - if (!fpblackTree) { - fpblackTree = new DecodeTree(false); - if (!fpblackTree) - return B_NO_MEMORY; - } - if (!fpwhiteTree) { - fpwhiteTree = new DecodeTree(true); - if (!fpwhiteTree) - return B_NO_MEMORY; - } - - if (fpblackTree->InitCheck() != B_OK) - return fpblackTree->InitCheck(); - - return fpwhiteTree->InitCheck(); -} - diff --git a/src/add-ons/translators/tiff/TIFFTranslator.h b/src/add-ons/translators/tiff/TIFFTranslator.h deleted file mode 100644 index acbec428ef..0000000000 --- a/src/add-ons/translators/tiff/TIFFTranslator.h +++ /dev/null @@ -1,160 +0,0 @@ -/*****************************************************************************/ -// TIFFTranslator -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFTranslator.h -// -// This BTranslator based object is for opening and writing -// TIFF images. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_TRANSLATOR_H -#define TIFF_TRANSLATOR_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "DecodeTree.h" - -// IO Extension Names: -#define DOCUMENT_COUNT "/documentCount" -#define DOCUMENT_INDEX "/documentIndex" - -#define TIFF_TRANSLATOR_VERSION 100 - -#define TIFF_IN_QUALITY 0.1 -#define TIFF_IN_CAPABILITY 0.1 -#define TIFF_OUT_QUALITY 0.6 -#define TIFF_OUT_CAPABILITY 0.2 - -#define BBT_IN_QUALITY 0.4 -#define BBT_IN_CAPABILITY 0.6 -#define BBT_OUT_QUALITY 0.4 -#define BBT_OUT_CAPABILITY 0.6 - -enum TIFF_IMAGE_TYPE { - TIFF_BILEVEL = 1, - TIFF_PALETTE, - TIFF_RGB, - TIFF_CMYK -}; - -// class for storing only the TIFF fields -// that are of interest to the TIFFTranslator -// -// The class is very minimal so that it is -// convenient to use, but cleans up after itself -class TiffDetails { -public: - TiffDetails(); - ~TiffDetails(); - - uint32 width; - uint32 height; - uint32 compression; - uint32 t4options; - uint32 rowsPerStrip; - uint32 stripsPerImage; - uint32 *pstripOffsets; - uint32 *pstripByteCounts; - uint8 *pcolorMap; - uint16 interpretation; - uint16 bitsPerPixel; - uint16 imageType; - uint16 fillOrder; -}; - -class TIFFTranslator : public BTranslator { -public: - TIFFTranslator(); - - virtual const char *TranslatorName() const; - // returns the short name of the translator - - virtual const char *TranslatorInfo() const; - // returns a verbose name/description for the translator - - virtual int32 TranslatorVersion() const; - // returns the version of the translator - - virtual const translation_format *InputFormats(int32 *out_count) - const; - // returns the input formats and the count of input formats - // that this translator supports - - virtual const translation_format *OutputFormats(int32 *out_count) - const; - // returns the output formats and the count of output formats - // that this translator supports - - virtual status_t Identify(BPositionIO *inSource, - const translation_format *inFormat, BMessage *ioExtension, - translator_info *outInfo, uint32 outType); - // determines whether or not this translator can convert the - // data in inSource to the type outType - - virtual status_t Translate(BPositionIO *inSource, - const translator_info *inInfo, BMessage *ioExtension, - uint32 outType, BPositionIO *outDestination); - // this function is the whole point of the Translation Kit, - // it translates the data in inSource to outDestination - // using the format outType - - virtual status_t MakeConfigurationView(BMessage *ioExtension, - BView **outView, BRect *outExtent); - // creates and returns the view for displaying information - // about this translator - -protected: - virtual ~TIFFTranslator(); - // this is protected because the object is deleted by the - // Release() function instead of being deleted directly by - // the user - -private: - status_t LoadHuffmanTrees(); - - ssize_t decode_huffman(StreamBuffer *pstreambuf, TiffDetails &details, - uint8 *pbits); - ssize_t decode_t4(BitReader &stream, TiffDetails &details, - uint8 *pbits, bool bfirstLine); - - status_t translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension, - ssize_t amtread, uint8 *read, swap_action swp, uint32 outType, - BPositionIO *outDestination); - - DecodeTree *fpblackTree; - DecodeTree *fpwhiteTree; - - char fName[30]; - char fInfo[100]; -}; - -#endif // #ifndef TIFF_TRANSLATOR_H diff --git a/src/add-ons/translators/tiff/TIFFView.cpp b/src/add-ons/translators/tiff/TIFFView.cpp deleted file mode 100644 index 684dec1411..0000000000 --- a/src/add-ons/translators/tiff/TIFFView.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*****************************************************************************/ -// TIFFView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFView.cpp -// -// This BView based object displays information about the TIFFTranslator. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include -#include "TIFFView.h" -#include "TIFFTranslator.h" - -// --------------------------------------------------------------- -// Constructor -// -// Sets up the view settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFView::TIFFView(const BRect &frame, const char *name, - uint32 resize, uint32 flags) - : BView(frame, name, resize, flags) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - SetLowColor(ViewColor()); -} - -// --------------------------------------------------------------- -// Destructor -// -// Does nothing -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFView::~TIFFView() -{ -} - -// --------------------------------------------------------------- -// Draw -// -// Draws information about the TIFFTranslator to this view. -// -// Preconditions: -// -// Parameters: area, not used -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -void -TIFFView::Draw(BRect area) -{ - SetFont(be_bold_font); - font_height fh; - GetFontHeight(&fh); - float xbold, ybold; - xbold = fh.descent + 1; - ybold = fh.ascent + fh.descent * 2 + fh.leading; - - char title[] = "OpenBeOS TIFF Image Translator"; - DrawString(title, BPoint(xbold, ybold)); - - SetFont(be_plain_font); - font_height plainh; - GetFontHeight(&plainh); - float yplain; - yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; - - char detail[100]; - sprintf(detail, "Version %d.%d.%d %s", - TIFF_TRANSLATOR_VERSION / 100, (TIFF_TRANSLATOR_VERSION / 10) % 10, - TIFF_TRANSLATOR_VERSION % 10, __DATE__); - DrawString(detail, BPoint(xbold, yplain + ybold)); -/* char copyright[] = "© 2003 OpenBeOS Project"; - DrawString(copyright, BPoint(xbold, yplain * 2 + ybold)); -*/ - char writtenby[] = "Written by the OBOS Translation Kit Team"; - DrawString(writtenby, BPoint(xbold, yplain * 7 + ybold)); -} diff --git a/src/add-ons/translators/tiff/TIFFView.h b/src/add-ons/translators/tiff/TIFFView.h deleted file mode 100644 index eea4f32ac3..0000000000 --- a/src/add-ons/translators/tiff/TIFFView.h +++ /dev/null @@ -1,51 +0,0 @@ -/*****************************************************************************/ -// TIFFView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFView.h -// -// This BView based object displays information about the TIFFTranslator. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFFVIEW_H -#define TIFFVIEW_H - -#include -#include -#include - -class TIFFView : public BView { -public: - TIFFView(const BRect &frame, const char *name, uint32 resize, - uint32 flags); - // sets up the view - - ~TIFFView(); - // does nothing - - virtual void Draw(BRect area); - // draws information about the TIFFTranslator -}; - -#endif // #ifndef TIFFVIEW_H diff --git a/src/add-ons/translators/tiff/TIFFWindow.cpp b/src/add-ons/translators/tiff/TIFFWindow.cpp deleted file mode 100644 index f1d4bb1104..0000000000 --- a/src/add-ons/translators/tiff/TIFFWindow.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*****************************************************************************/ -// TIFFWindow -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFWindow.cpp -// -// This BWindow based object is used to hold the TIFFView object when the -// user runs the TIFFTranslator as an application. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include "TIFFWindow.h" - -// --------------------------------------------------------------- -// Constructor -// -// Sets up the BWindow for holding a TIFFView -// -// Preconditions: -// -// Parameters: area, The bounds of the window -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFWindow::TIFFWindow(BRect area) - : BWindow(area, "TIFFTranslator", B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_NOT_ZOOMABLE) -{ -} - -// --------------------------------------------------------------- -// Destructor -// -// Posts a quit message so that the application is close properly -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -TIFFWindow::~TIFFWindow() -{ - be_app->PostMessage(B_QUIT_REQUESTED); -} diff --git a/src/add-ons/translators/tiff/TIFFWindow.h b/src/add-ons/translators/tiff/TIFFWindow.h deleted file mode 100644 index f4652f0070..0000000000 --- a/src/add-ons/translators/tiff/TIFFWindow.h +++ /dev/null @@ -1,48 +0,0 @@ -/*****************************************************************************/ -// TIFFWindow -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TIFFWindow.h -// -// This BWindow based object is used to hold the TIFFView object when the -// user runs the TIFFTranslator as an application. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFFWINDOW_H -#define TIFFWINDOW_H - -#include -#include -#include - -class TIFFWindow : public BWindow { -public: - TIFFWindow(BRect area); - // Sets up a BWindow with bounds area - - ~TIFFWindow(); - // Posts a quit message so that the application closes properly -}; - -#endif // #define TIFFWINDOW_H diff --git a/src/add-ons/translators/tiff/TiffField.cpp b/src/add-ons/translators/tiff/TiffField.cpp deleted file mode 100644 index b531faffde..0000000000 --- a/src/add-ons/translators/tiff/TiffField.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*****************************************************************************/ -// TiffField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffField.cpp -// -// This object is for storing TIFF fields -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include "TiffField.h" - -TiffField::TiffField(IFDEntry &entry) -{ - finitStatus = B_ERROR; - // responsibility of derived class to set this properly - - ftag = entry.tag; - ffieldType = entry.fieldType; - fcount = entry.count; -} diff --git a/src/add-ons/translators/tiff/TiffField.h b/src/add-ons/translators/tiff/TiffField.h deleted file mode 100644 index ef272fceee..0000000000 --- a/src/add-ons/translators/tiff/TiffField.h +++ /dev/null @@ -1,141 +0,0 @@ -/*****************************************************************************/ -// TiffField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffField.h -// -// This object is for storing TIFF fields -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_FIELD_H -#define TIFF_FIELD_H - -#include - -// TIFF field id numbers for fields that the -// TIFFTranslator needs to know about / use -// (not a complete list of all tags) -#define TAG_NEW_SUBFILE_TYPE 254 - #define NEW_SUBFILE_TYPE_REDUCED 1 - #define NEW_SUBFILE_TYPE_PAGE 2 - #define NEW_SUBFILE_TYPE_MASK 4 -#define TAG_SUBFILE_TYPE 255 - #define SUBFILE_TYPE_FULL 1 - #define SUBFILE_TYPE_REDUCED 2 - #define SUBFILE_TYPE_PAGE 3 -#define TAG_IMAGE_WIDTH 256 -#define TAG_IMAGE_HEIGHT 257 -#define TAG_BITS_PER_SAMPLE 258 -#define TAG_COMPRESSION 259 - #define COMPRESSION_NONE 1 - #define COMPRESSION_HUFFMAN 2 - #define COMPRESSION_T4 3 - #define COMPRESSION_T6 4 - #define COMPRESSION_LZW 5 - #define COMPRESSION_JPEG 6 - #define COMPRESSION_PACKBITS 32773 -#define TAG_PHOTO_INTERPRETATION 262 - #define PHOTO_WHITEZERO 0 - #define PHOTO_BLACKZERO 1 - #define PHOTO_RGB 2 - #define PHOTO_PALETTE 3 - #define PHOTO_MASK 4 - #define PHOTO_SEPARATED 5 -#define TAG_FILL_ORDER 266 -#define TAG_STRIP_OFFSETS 273 -#define TAG_ORIENTATION 274 -#define TAG_SAMPLES_PER_PIXEL 277 -#define TAG_ROWS_PER_STRIP 278 - #define DEFAULT_ROWS_PER_STRIP 4294967295UL -#define TAG_STRIP_BYTE_COUNTS 279 -#define TAG_PLANAR_CONFIGURATION 284 -#define TAG_T4_OPTIONS 292 - // (Also called Group3Options) - #define T4_2D 1 - #define T4_UNCOMPRESSED 2 - #define T4_FILL_BYTE_BOUNDARY 4 -#define TAG_T6_OPTIONS 293 - // (Also called Group4Options) -#define TAG_RESOLUTION_UNIT 296 -#define TAG_COLOR_MAP 320 -#define TAG_INK_SET 332 - #define INK_SET_CMYK 1 - #define INK_SET_NOT_CMYK 2 -#define TAG_EXTRA_SAMPLES 338 -#define TAG_SAMPLE_FORMAT 339 - -// Some types of data that can -// exist in a TIFF field -enum TIFF_ENTRY_TYPE { - TIFF_BYTE = 1, - TIFF_ASCII, - TIFF_SHORT, - TIFF_LONG, - TIFF_RATIONAL, - TIFF_SBYTE, - TIFF_UNDEFINED, - TIFF_SSHORT, - TIFF_SRATIONAL, - TIFF_FLOAT, - TIFF_DOUBLE -}; - -struct IFDEntry { - uint16 tag; - // uniquely identifies the field - uint16 fieldType; - // number, string, float, etc. - uint32 count; - // length / number of values - - // The actual value or the file offset - // where the actual value is located - union { - float floatval; - uint32 longval; - uint16 shortvals[2]; - uint8 bytevals[4]; - }; -}; - -class TiffField { -public: - TiffField(IFDEntry &entry); - virtual ~TiffField() {}; - - status_t InitCheck() { return finitStatus; }; - uint16 GetTag() { return ftag; }; - uint16 GetType() { return ffieldType; }; - uint32 GetCount() { return fcount; }; - -protected: - status_t finitStatus; - -private: - uint16 ftag; - uint16 ffieldType; - uint32 fcount; -}; - -#endif // #define TIFF_FIELD_H diff --git a/src/add-ons/translators/tiff/TiffIfd.cpp b/src/add-ons/translators/tiff/TiffIfd.cpp deleted file mode 100644 index c2248d40f0..0000000000 --- a/src/add-ons/translators/tiff/TiffIfd.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/*****************************************************************************/ -// TiffIfd -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffIfd.cpp -// -// This object is for storing a TIFF Image File Directory -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include "TiffIfd.h" -#include "TiffUintField.h" -#include "TiffUnknownField.h" - -void -TiffIfd::LoadFields(uint32 offset, BPositionIO &io, swap_action swp) -{ - if (io.ReadAt(offset, &ffieldCount, 2) != 2) { - finitStatus = B_IO_ERROR; - return; - } else { - if (swap_data(B_UINT16_TYPE, &ffieldCount, 2, swp) != B_OK) { - finitStatus = B_ERROR; - return; - } else { - fpfields = new TiffField *[ffieldCount]; - if (!fpfields) { - finitStatus = B_NO_MEMORY; - return; - } else { - memset(fpfields, 0, ffieldCount * sizeof(TiffField *)); - // set all pointers to TiffFields to NULL - - // Load TIFF IFD Entries - offset += 2; - uint16 i; - finitStatus = B_OK; - for (i = 0; i < ffieldCount; i++, offset += 12) { - IFDEntry entry; - - if (io.ReadAt(offset, &entry, 12) != 12) { - finitStatus = B_IO_ERROR; - return; - } - if (swap_data(B_UINT16_TYPE, &entry.tag, 2, swp) != B_OK) { - finitStatus = B_ERROR; - return; - } - if (swap_data(B_UINT16_TYPE, &entry.fieldType, 2, swp) != B_OK) { - finitStatus = B_ERROR; - return; - } - if (swap_data(B_UINT32_TYPE, &entry.count, 4, swp) != B_OK) { - finitStatus = B_ERROR; - return; - } - - // Create a TiffField based object to store the - // TIFF entry - switch (entry.fieldType) { - case TIFF_BYTE: - case TIFF_SHORT: - case TIFF_LONG: - fpfields[i] = new TiffUintField(entry, io, swp); - break; - - default: - fpfields[i] = new TiffUnknownField(entry); - break; - } - if (!fpfields[i]) { - finitStatus = B_NO_MEMORY; - return; - } - if (fpfields[i]->InitCheck() != B_OK) { - finitStatus = fpfields[i]->InitCheck(); - return; - } - } // for (i = 0; i < ffieldCount; i++, offset += 12) - - // Read address of next IFD entry - if (io.ReadAt(offset, &fnextIFDOffset, 4) != 4) { - finitStatus = B_IO_ERROR; - return; - } - if (swap_data(B_UINT32_TYPE, &fnextIFDOffset, 4, swp) != B_OK) { - finitStatus = B_ERROR; - return; - } - } - } - } -} - -TiffIfd::TiffIfd(uint32 offset, BPositionIO &io, swap_action swp) -{ - fpfields = NULL; - finitStatus = B_ERROR; - fnextIFDOffset = 0; - ffieldCount = 0; - - LoadFields(offset, io, swp); -} - -TiffIfd::~TiffIfd() -{ - for (uint16 i = 0; i < ffieldCount; i++) { - delete fpfields[i]; - fpfields[i] = NULL; - } - delete[] fpfields; - fpfields = NULL; - - ffieldCount = 0; - fnextIFDOffset = 0; -} - -bool -TiffIfd::HasField(uint16 tag) -{ - TiffField *pfield = GetField(tag); - if (pfield) - return true; - else - return false; -} - -uint32 -TiffIfd::GetCount(uint16 tag) -{ - TiffField *pfield = GetField(tag); - if (pfield) - return pfield->GetCount(); - else - throw TiffIfdFieldNotFoundException(); -} - -uint32 -TiffIfd::GetUint(uint16 tag, uint32 index) -{ - TiffField *pfield = GetField(tag); - if (pfield) { - - TiffUintField *puintField = NULL; - puintField = dynamic_cast(pfield); - if (puintField) { - - uint32 num; - status_t ret = puintField->GetUint(num, index); - if (ret == B_OK) - return num; - else if (ret == B_BAD_INDEX) - throw TiffIfdBadIndexException(); - else - throw TiffIfdUnexpectedTypeException(); - - } else - throw TiffIfdUnexpectedTypeException(); - } - - throw TiffIfdFieldNotFoundException(); -} - -uint32 -TiffIfd::GetAdjustedColorMap(uint8 **pout) -{ - TiffField *pfield = GetField(TAG_COLOR_MAP); - if (pfield) { - - TiffUintField *puintField = NULL; - puintField = dynamic_cast(pfield); - if (puintField) { - - uint32 count = puintField->GetCount(); - (*pout) = new uint8[count]; - uint8 *puints = (*pout); - if (!puints) - throw TiffIfdNoMemoryException(); - - for (uint32 i = 0; i < count; i++) { - uint32 num; - status_t ret = puintField->GetUint(num, i + 1); - if (ret == B_BAD_INDEX) - throw TiffIfdBadIndexException(); - else if (ret == B_BAD_TYPE) - throw TiffIfdUnexpectedTypeException(); - - puints[i] = num / 256; - } - - return count; - - } else - throw TiffIfdUnexpectedTypeException(); - } - - throw TiffIfdFieldNotFoundException(); -} - -uint32 -TiffIfd::GetUint32Array(uint16 tag, uint32 **pout) -{ - TiffField *pfield = GetField(tag); - if (pfield) { - - TiffUintField *puintField = NULL; - puintField = dynamic_cast(pfield); - if (puintField) { - - uint32 count = puintField->GetCount(); - (*pout) = new uint32[count]; - uint32 *puints = (*pout); - if (!puints) - throw TiffIfdNoMemoryException(); - - for (uint32 i = 0; i < count; i++) { - uint32 num; - status_t ret = puintField->GetUint(num, i + 1); - if (ret == B_BAD_INDEX) - throw TiffIfdBadIndexException(); - else if (ret == B_BAD_TYPE) - throw TiffIfdUnexpectedTypeException(); - - puints[i] = num; - } - - return count; - - } else - throw TiffIfdUnexpectedTypeException(); - } - - throw TiffIfdFieldNotFoundException(); -} - -TiffField * -TiffIfd::GetField(uint16 tag) -{ - for (uint16 i = 0; i < ffieldCount; i++) { - TiffField *pfield = fpfields[i]; - if (pfield) { - uint16 ltag = pfield->GetTag(); - if (tag == ltag) - return pfield; - else if (ltag > tag) - break; - } - } - - return NULL; -} - diff --git a/src/add-ons/translators/tiff/TiffIfd.h b/src/add-ons/translators/tiff/TiffIfd.h deleted file mode 100644 index c838169fbf..0000000000 --- a/src/add-ons/translators/tiff/TiffIfd.h +++ /dev/null @@ -1,104 +0,0 @@ -/*****************************************************************************/ -// TiffIfd -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffIfd.h -// -// This object is for storing a TIFF Image File Directory -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_IFD_H -#define TIFF_IFD_H - -#include -#include -#include "TiffField.h" -#include "TiffUintField.h" - -class TiffIfdException { -public: - TiffIfdException() { }; -}; -class TiffIfdFieldNotFoundException : public TiffIfdException { -public: - TiffIfdFieldNotFoundException() { }; -}; -class TiffIfdUnexpectedTypeException : public TiffIfdException { -public: - TiffIfdUnexpectedTypeException() { }; -}; -class TiffIfdBadIndexException : public TiffIfdException { -public: - TiffIfdBadIndexException() { }; -}; -class TiffIfdNoMemoryException : public TiffIfdException { -public: - TiffIfdNoMemoryException() { }; -}; - -class TiffIfd { -public: - TiffIfd(uint32 offset, BPositionIO &io, swap_action swp); - ~TiffIfd(); - status_t InitCheck() { return finitStatus; }; - - bool HasField(uint16 tag); - uint32 GetCount(uint16 tag); - // throws: TiffIfdFieldNotFoundException() - - uint32 GetNextIfdOffset() { return fnextIFDOffset; }; - - uint32 GetUint(uint16 tag, uint32 index = 0); - // index is the base one index for the desired - // number in the specified field. When index is the default - // value of zero: if the count is one, the - // first number will be returned, if it is not - // one, TiffIfdBadIndexException() will be thrown - // - // throws: TiffIfdFieldNotFoundException(), - // TiffIfdUnexpectedTypeException(), - // TiffIfdBadIndexException() - - uint32 GetAdjustedColorMap(uint8 **pout); - uint32 GetUint32Array(uint16 tag, uint32 **pout); - // copies all of the uints from tag to - // the pointer pointed to by pout - // and returns the number of uints copied - // - // throws: TiffIfdFieldNotFoundException(), - // TiffIfdUnexpectedTypeException(), - // TiffIfdBadIndexException() - // TiffIfdNoMemoryException() - -private: - void LoadFields(uint32 offset, BPositionIO &io, swap_action swp); - TiffField *GetField(uint16 tag); - - TiffField **fpfields; - status_t finitStatus; - uint32 fnextIFDOffset; - uint16 ffieldCount; -}; - -#endif // TIFF_IFD_H diff --git a/src/add-ons/translators/tiff/TiffIfdList.cpp b/src/add-ons/translators/tiff/TiffIfdList.cpp deleted file mode 100644 index d650705e1e..0000000000 --- a/src/add-ons/translators/tiff/TiffIfdList.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/*****************************************************************************/ -// TiffIfdList -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffIfdList.cpp -// -// This object is for storing all IFD entries from a TIFF file -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include "TiffIfdList.h" - -status_t -TiffIfdList::LoadIfds(uint32 offset, BPositionIO &io, swap_action swp) -{ - Empty(); - - TiffIfdNode *pnode = NULL; - while (offset) { - // Create new node at the end of the list - if (!fpfirst) { - fpfirst = new TiffIfdNode; - pnode = fpfirst; - } else { - pnode->pnext = new TiffIfdNode; - pnode = pnode->pnext; - } - if (!pnode) { - finitStatus = B_NO_MEMORY; - break; - } - - // Create new TiffIfd and check its status - pnode->pnext = NULL; - pnode->pifd = new TiffIfd(offset, io, swp); - if (!pnode->pifd) { - finitStatus = B_NO_MEMORY; - break; - } - if (pnode->pifd->InitCheck() != B_OK) { - finitStatus = pnode->pifd->InitCheck(); - break; - } - - offset = pnode->pifd->GetNextIfdOffset(); - fcount++; - } - - if (finitStatus != B_OK) - fcount = 0; - - return finitStatus; -} - -TiffIfdList::TiffIfdList(uint32 offset, BPositionIO &io, swap_action swp) -{ - fpfirst = NULL; - finitStatus = B_OK; - fcount = 0; - - LoadIfds(offset, io, swp); -} - -TiffIfdList::~TiffIfdList() -{ - Empty(); -} - -void -TiffIfdList::Empty() -{ - TiffIfdNode *pnode, *pdelme; - pnode = fpfirst; - - while (pnode) { - pdelme = pnode; - pnode = pnode->pnext; - - delete pdelme->pifd; - delete pdelme; - } - fpfirst = NULL; - fcount = 0; - finitStatus = B_OK; -} - -// index is zero based -TiffIfd * -TiffIfdList::GetIfd(int32 index) -{ - if (index < 0 || index >= fcount) - return NULL; - - TiffIfdNode *pnode = fpfirst; - while (index--) - pnode = pnode->pnext; - - return pnode->pifd; -} - diff --git a/src/add-ons/translators/tiff/TiffIfdList.h b/src/add-ons/translators/tiff/TiffIfdList.h deleted file mode 100644 index 564c71160e..0000000000 --- a/src/add-ons/translators/tiff/TiffIfdList.h +++ /dev/null @@ -1,62 +0,0 @@ -/*****************************************************************************/ -// TiffIfdList -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffIfdList.h -// -// This object is for storing all IFD entries from a TIFF file -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_IFD_LIST_H -#define TIFF_IFD_LIST_H - -#include -#include -#include "TiffIfd.h" - -struct TiffIfdNode { - TiffIfd *pifd; - TiffIfdNode *pnext; -}; - -class TiffIfdList { -public: - TiffIfdList(uint32 offset, BPositionIO &io, swap_action swp); - ~TiffIfdList(); - status_t InitCheck() { return finitStatus; }; - - status_t LoadIfds(uint32 offset, BPositionIO &io, swap_action swp); - void Empty(); - - int32 GetCount() { return fcount; }; - TiffIfd *GetIfd(int32 index); - // index is zero based - -private: - status_t finitStatus; - TiffIfdNode *fpfirst; - int32 fcount; -}; - -#endif // #ifndef TIFF_IFD_LIST_H diff --git a/src/add-ons/translators/tiff/TiffUintField.cpp b/src/add-ons/translators/tiff/TiffUintField.cpp deleted file mode 100644 index 0680dd58c9..0000000000 --- a/src/add-ons/translators/tiff/TiffUintField.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/*****************************************************************************/ -// TiffUintField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffUintField.cpp -// -// This object is for storing Unsigned Integer TIFF fields -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include -#include "TiffUintField.h" - -void -TiffUintField::LoadByte(IFDEntry &entry, BPositionIO &io, swap_action swp) -{ - // Make certain there is enough memory - // before trying to do anything else - fpByte = new uint8[entry.count]; - if (!fpByte) { - finitStatus = B_NO_MEMORY; - return; - } - - if (entry.count <= 4) { - // If all of the byte values can fit into the - // IFD entry value bytes - memcpy(fpByte, entry.bytevals, entry.count); - finitStatus = B_OK; - } else { - - // entry.count > 4, use longval to find offset for byte data - if (swap_data(B_UINT32_TYPE, &entry.longval, 4, swp) != B_OK) - finitStatus = B_ERROR; - else { - ssize_t read; - read = io.ReadAt(entry.longval, fpByte, entry.count); - if (read != static_cast(entry.count)) - finitStatus = B_IO_ERROR; - else - finitStatus = B_OK; - } - - } -} - -void -TiffUintField::LoadShort(IFDEntry &entry, BPositionIO &io, swap_action swp) -{ - // Make certain there is enough memory - // before trying to do anything else - fpShort = new uint16[entry.count]; - if (!fpShort) { - finitStatus = B_NO_MEMORY; - return; - } - - if (entry.count <= 2) { - // If all of the byte values can fit into the - // IFD entry value bytes - memcpy(fpShort, entry.shortvals, entry.count * 2); - finitStatus = B_OK; - } else { - - // entry.count > 2, use longval to find offset for short data - if (swap_data(B_UINT32_TYPE, &entry.longval, 4, swp) != B_OK) - finitStatus = B_ERROR; - else { - ssize_t read; - read = io.ReadAt(entry.longval, fpShort, entry.count * 2); - if (read != static_cast(entry.count) * 2) - finitStatus = B_IO_ERROR; - else - finitStatus = B_OK; - } - - } - - // If short values were successfully read in, swap them to - // the correct byte order - if (finitStatus == B_OK && - swap_data(B_UINT16_TYPE, fpShort, entry.count * 2, swp) != B_OK) - finitStatus = B_ERROR; -} - -void -TiffUintField::LoadLong(IFDEntry &entry, BPositionIO &io, swap_action swp) -{ - // Make certain there is enough memory - // before trying to do anything else - fpLong = new uint32[entry.count]; - if (!fpLong) { - finitStatus = B_NO_MEMORY; - return; - } - - if (entry.count == 1) { - fpLong[0] = entry.longval; - finitStatus = B_OK; - } else { - - // entry.count > 1, use longval to find offset for long data - if (swap_data(B_UINT32_TYPE, &entry.longval, 4, swp) != B_OK) - finitStatus = B_ERROR; - else { - ssize_t read; - read = io.ReadAt(entry.longval, fpLong, entry.count * 4); - if (read != static_cast(entry.count) * 4) - finitStatus = B_IO_ERROR; - else - finitStatus = B_OK; - } - - } - - // If long values were successfully read in, swap them to - // the correct byte order - if (finitStatus == B_OK && - swap_data(B_UINT32_TYPE, fpLong, entry.count * 4, swp) != B_OK) - finitStatus = B_ERROR; -} - -TiffUintField::TiffUintField(IFDEntry &entry, BPositionIO &io, swap_action swp) - : TiffField(entry) -{ - if (entry.count > 0) { - switch (entry.fieldType) { - case TIFF_BYTE: - fpByte = NULL; - LoadByte(entry, io, swp); - break; - - case TIFF_SHORT: - fpShort = NULL; - LoadShort(entry, io, swp); - break; - - case TIFF_LONG: - fpLong = NULL; - LoadLong(entry, io, swp); - break; - - default: - finitStatus = B_BAD_TYPE; - break; - } - } else - finitStatus = B_BAD_VALUE; -} - -TiffUintField::~TiffUintField() -{ - switch (GetType()) { - case TIFF_BYTE: - delete[] fpByte; - fpByte = NULL; - break; - case TIFF_SHORT: - delete[] fpShort; - fpShort = NULL; - break; - case TIFF_LONG: - delete[] fpLong; - fpLong = NULL; - break; - - default: - // if invalid type, should have never - // allocated any value, so there should - // be no value to delete - break; - } -} - -// --------------------------------------------------------------- -// GetUint -// -// Retrieves the number at the given index for this field. -// Some fields store a single number, others store an array of -// numbers. -// -// The index parameter has a default value of zero. When -// index is zero, there is special behavior: the first -// number is retrieved if this field has a count of 1. If -// the index is zero and the field's count is not 1, then -// B_BAD_INDEX will be returned. -// -// Preconditions: -// -// Parameters: out, where the desired uint is copied to -// -// index, one-based index for the desired value -// -// Postconditions: -// -// Returns: B_OK if the field was found and it is a TiffUintField -// based object, -// -// B_BAD_TYPE if the field was found BUT it was not a -// TiffUintField based object -// -// B_BAD_INDEX if a field with the given tag -// was not found -// --------------------------------------------------------------- -status_t -TiffUintField::GetUint(uint32 &out, uint32 index) -{ - if (finitStatus != B_OK) - return finitStatus; - - uint32 count = GetCount(); - if (index > count || (index == 0 && count != 1)) - return B_BAD_INDEX; - - status_t result = B_OK; - if (!index) - index = 1; - switch (GetType()) { - case TIFF_BYTE: - out = fpByte[index - 1]; - break; - - case TIFF_SHORT: - out = fpShort[index - 1]; - break; - - case TIFF_LONG: - out = fpLong[index - 1]; - break; - - default: - result = B_BAD_TYPE; - break; - } - - return result; -} diff --git a/src/add-ons/translators/tiff/TiffUintField.h b/src/add-ons/translators/tiff/TiffUintField.h deleted file mode 100644 index d75724f1bc..0000000000 --- a/src/add-ons/translators/tiff/TiffUintField.h +++ /dev/null @@ -1,57 +0,0 @@ -/*****************************************************************************/ -// TiffUintField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffUintField.h -// -// This object is for storing Unsigned Integer TIFF fields -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_UNIT_FIELD_H -#define TIFF_UNIT_FIELD_H - -#include -#include -#include "TiffField.h" - -class TiffUintField : public TiffField { -public: - TiffUintField(IFDEntry &entry, BPositionIO &io, swap_action swp); - virtual ~TiffUintField(); - - status_t GetUint(uint32 &out, uint32 index = 0); - -private: - void LoadByte(IFDEntry &entry, BPositionIO &io, swap_action swp); - void LoadShort(IFDEntry &entry, BPositionIO &io, swap_action swp); - void LoadLong(IFDEntry &entry, BPositionIO &io, swap_action swp); - - union { - uint8 *fpByte; - uint16 *fpShort; - uint32 *fpLong; - }; -}; - -#endif // #define TIFF_UNIT_FIELD_H diff --git a/src/add-ons/translators/tiff/TiffUnknownField.cpp b/src/add-ons/translators/tiff/TiffUnknownField.cpp deleted file mode 100644 index fbab2b9198..0000000000 --- a/src/add-ons/translators/tiff/TiffUnknownField.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*****************************************************************************/ -// TiffUnknownField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffUnknownField.cpp -// -// This object is for storing TIFF fields that the translator doesn't know -// or doesn't care about -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#include "TiffUnknownField.h" - -TiffUnknownField::TiffUnknownField(IFDEntry &entry) - : TiffField(entry) -{ - finitStatus = B_OK; -} - -TiffUnknownField::~TiffUnknownField() -{ -} diff --git a/src/add-ons/translators/tiff/TiffUnknownField.h b/src/add-ons/translators/tiff/TiffUnknownField.h deleted file mode 100644 index 4ca30ae1bc..0000000000 --- a/src/add-ons/translators/tiff/TiffUnknownField.h +++ /dev/null @@ -1,43 +0,0 @@ -/*****************************************************************************/ -// TiffUnknownField -// Written by Michael Wilber, OBOS Translation Kit Team -// -// TiffUnknownField.h -// -// This object is for storing TIFF fields that the translator doesn't know -// or doesn't care about -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ - -#ifndef TIFF_UNKNOWN_FIELD_H -#define TIFF_UNKNOWN_FIELD_H - -#include "TiffField.h" - -class TiffUnknownField : public TiffField { -public: - TiffUnknownField(IFDEntry &entry); - virtual ~TiffUnknownField(); -}; - -#endif // TIFF_UNKNOWN_FIELD_H