Added support for the "/documentCount" and "/documentIndex" extension used

by the TIFF translator. Thanks again to BiPolar for the note about this.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11334 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-02-11 03:38:15 +00:00
parent 5fa46a457c
commit fbef8d31d3
4 changed files with 59 additions and 17 deletions
+43 -8
View File
@@ -5,7 +5,9 @@
// ToDo: This definitely needs to be worked over for endian issues
#include <ICO.h>
#include "ICO.h"
#include "ICOTranslator.h"
#include <ByteOrder.h>
#include <stdio.h>
@@ -481,7 +483,7 @@ convert_bits_to_data(TranslatorBitmap &bitsHeader, uint8 *bitsData, ico_dir_entr
status_t
ICO::identify(BPositionIO &stream, int32 &bitsPerPixel)
ICO::identify(BMessage *settings, BPositionIO &stream, int32 &bitsPerPixel)
{
// read in the header
@@ -496,6 +498,23 @@ ICO::identify(BPositionIO &stream, int32 &bitsPerPixel)
if (!header.IsValid())
return B_BAD_VALUE;
int32 iconIndex = 0;
if (settings) {
// Add page count to ioExtension
settings->RemoveName(kDocumentCount);
settings->AddInt32(kDocumentCount, header.entry_count);
// Check if a document index has been specified
if (settings->FindInt32(kDocumentIndex, &iconIndex) == B_OK)
iconIndex--;
else
iconIndex = 0;
if (iconIndex < 0 || iconIndex >= header.entry_count)
return B_NO_TRANSLATOR;
}
// read in directory entries
for (uint32 i = 0; i < header.entry_count; i++) {
@@ -522,7 +541,8 @@ ICO::identify(BPositionIO &stream, int32 &bitsPerPixel)
if (!bitmapHeader.IsValid())
return B_BAD_VALUE;
bitsPerPixel = bitmapHeader.bits_per_pixel;
if ((uint32)iconIndex == i)
bitsPerPixel = bitmapHeader.bits_per_pixel;
}
return B_OK;
@@ -533,7 +553,7 @@ ICO::identify(BPositionIO &stream, int32 &bitsPerPixel)
*/
status_t
ICO::convert_ico_to_bits(BPositionIO &source, BPositionIO &target)
ICO::convert_ico_to_bits(BMessage *settings, BPositionIO &source, BPositionIO &target)
{
ico_header header;
if (source.Read(&header, sizeof(ico_header)) != (ssize_t)sizeof(ico_header))
@@ -546,19 +566,33 @@ ICO::convert_ico_to_bits(BPositionIO &source, BPositionIO &target)
if (!header.IsValid())
return B_BAD_VALUE;
// read in first entry
int32 iconIndex = 0;
if (settings) {
// Check if a document index has been specified
if (settings->FindInt32(kDocumentIndex, &iconIndex) == B_OK)
iconIndex--;
else
iconIndex = 0;
if (iconIndex < 0 || iconIndex >= header.entry_count)
return B_BAD_VALUE;
}
// read in selected entry
ico_dir_entry entry;
if (source.Read(&entry, sizeof(ico_dir_entry)) != (ssize_t)sizeof(ico_dir_entry))
if (source.ReadAt(sizeof(ico_header) + sizeof(ico_dir_entry) * iconIndex,
&entry, sizeof(ico_dir_entry)) != (ssize_t)sizeof(ico_dir_entry))
return B_BAD_VALUE;
entry.SwapToHost();
source.Seek(entry.offset, SEEK_SET);
ico_bitmap_header bitmapHeader;
if (source.Read(&bitmapHeader, sizeof(ico_bitmap_header)) != (ssize_t)sizeof(ico_bitmap_header))
return B_BAD_VALUE;
entry.SwapToHost();
bitmapHeader.SwapToHost();
if (!bitmapHeader.IsValid())
@@ -609,7 +643,8 @@ ICO::convert_ico_to_bits(BPositionIO &source, BPositionIO &target)
status_t
ICO::convert_bits_to_ico(BPositionIO &source, TranslatorBitmap &bitsHeader, BPositionIO &target)
ICO::convert_bits_to_ico(BMessage *settings, BPositionIO &source,
TranslatorBitmap &bitsHeader, BPositionIO &target)
{
int32 width = bitsHeader.bounds.IntegerWidth() + 1;
int32 height = bitsHeader.bounds.IntegerHeight() + 1;
+6 -3
View File
@@ -10,6 +10,8 @@
#include <BufferIO.h>
#include <TranslatorFormats.h>
class BMessage;
namespace ICO {
@@ -77,9 +79,10 @@ struct rgba32_color {
};
extern status_t identify(BPositionIO &stream, int32 &bitsPerPixel);
extern status_t convert_ico_to_bits(BPositionIO &source, BPositionIO &target);
extern status_t convert_bits_to_ico(BPositionIO &source, TranslatorBitmap &bitsHeader, BPositionIO &target);
extern status_t identify(BMessage *settings, BPositionIO &stream, int32 &bitsPerPixel);
extern status_t convert_ico_to_bits(BMessage *settings, BPositionIO &source, BPositionIO &target);
extern status_t convert_bits_to_ico(BMessage *settings, BPositionIO &source,
TranslatorBitmap &bitsHeader, BPositionIO &target);
} // namespace ICO
@@ -13,8 +13,8 @@
#include <string.h>
#define READ_BUFFER_SIZE 2048
#define DATA_BUFFER_SIZE 64
const char *kDocumentCount = "/documentCount";
const char *kDocumentIndex = "/documentIndex";
// The input formats that this translator supports.
@@ -96,7 +96,7 @@ ICOTranslator::DerivedIdentify(BPositionIO *stream,
return B_NO_TRANSLATOR;
int32 bitsPerPixel;
if (ICO::identify(*stream, bitsPerPixel) != B_OK)
if (ICO::identify(ioExtension, *stream, bitsPerPixel) != B_OK)
return B_NO_TRANSLATOR;
info->type = ICO_IMAGE_FORMAT;
@@ -133,7 +133,7 @@ ICOTranslator::DerivedTranslate(BPositionIO *source,
if (status != B_OK)
return status;
return ICO::convert_bits_to_ico(*source, bitsHeader, *target);
return ICO::convert_bits_to_ico(ioExtension, *source, bitsHeader, *target);
}
case 0:
@@ -142,7 +142,7 @@ ICOTranslator::DerivedTranslate(BPositionIO *source,
if (outType != B_TRANSLATOR_BITMAP)
return B_NO_TRANSLATOR;
return ICO::convert_ico_to_bits(*source, *target);
return ICO::convert_ico_to_bits(ioExtension, *source, *target);
}
default:
@@ -18,7 +18,7 @@
#include <ByteOrder.h>
#define ICO_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0, 1, 0)
#define ICO_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0, 3, 0)
#define ICO_IMAGE_FORMAT 'ICO '
#define ICO_IN_QUALITY 0.5
@@ -55,4 +55,8 @@ class ICOTranslator : public BaseTranslator {
private:
};
// Extensions that ShowImage supports
extern const char *kDocumentCount;
extern const char *kDocumentIndex;
#endif /* ICO_TRANSLATOR_H */