2 * Copyright 2008, Jérôme Duval, korli@users.berlios.de. All rights reserved.
3 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
8 #include "PCXTranslator.h"
9 #include "ConfigView.h"
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "PCXTranslator"
20 #define kPCXMimeType "image/x-pcx"
23 // The input formats that this translator supports.
24 static const translation_format sInputFormats
[] = {
39 "Be Bitmap Format (PCXTranslator)"
43 // The output formats that this translator supports.
44 static const translation_format sOutputFormats
[] = {
59 "Be Bitmap Format (PCXTranslator)"
63 // Default settings for the Translator
64 static const TranSetting sDefaultSettings
[] = {
65 {B_TRANSLATOR_EXT_HEADER_ONLY
, TRAN_SETTING_BOOL
, false},
66 {B_TRANSLATOR_EXT_DATA_ONLY
, TRAN_SETTING_BOOL
, false}
69 const uint32 kNumInputFormats
= sizeof(sInputFormats
) / sizeof(translation_format
);
70 const uint32 kNumOutputFormats
= sizeof(sOutputFormats
) / sizeof(translation_format
);
71 const uint32 kNumDefaultSettings
= sizeof(sDefaultSettings
) / sizeof(TranSetting
);
74 PCXTranslator::PCXTranslator()
75 : BaseTranslator(B_TRANSLATE("PCX images"),
76 B_TRANSLATE("PCX image translator"),
77 PCX_TRANSLATOR_VERSION
,
78 sInputFormats
, kNumInputFormats
,
79 sOutputFormats
, kNumOutputFormats
,
80 "PCXTranslator_Settings",
81 sDefaultSettings
, kNumDefaultSettings
,
82 B_TRANSLATOR_BITMAP
, PCX_IMAGE_FORMAT
)
87 PCXTranslator::~PCXTranslator()
93 PCXTranslator::DerivedIdentify(BPositionIO
*stream
,
94 const translation_format
*format
, BMessage
*ioExtension
,
95 translator_info
*info
, uint32 outType
)
98 outType
= B_TRANSLATOR_BITMAP
;
99 if (outType
!= B_TRANSLATOR_BITMAP
&& outType
!= PCX_IMAGE_FORMAT
)
100 return B_NO_TRANSLATOR
;
104 if (PCX::identify(ioExtension
, *stream
, type
, bitsPerPixel
) != B_OK
)
105 return B_NO_TRANSLATOR
;
107 info
->type
= PCX_IMAGE_FORMAT
;
108 info
->group
= B_TRANSLATOR_BITMAP
;
109 info
->quality
= PCX_IN_QUALITY
;
110 info
->capability
= PCX_IN_CAPABILITY
;
111 snprintf(info
->name
, sizeof(info
->name
), B_TRANSLATE("PCX %lu bit image"),
113 strcpy(info
->MIME
, kPCXMimeType
);
120 PCXTranslator::DerivedTranslate(BPositionIO
*source
,
121 const translator_info
*info
, BMessage
*ioExtension
,
122 uint32 outType
, BPositionIO
*target
, int32 baseType
)
125 outType = B_TRANSLATOR_BITMAP;
126 if (outType != B_TRANSLATOR_BITMAP && outType != PCX_IMAGE_FORMAT)
127 return B_NO_TRANSLATOR;*/
132 if (outType != PCX_IMAGE_FORMAT)
133 return B_NO_TRANSLATOR;
135 // Source is in bits format - this has to be done here, because
136 // identify_bits_header() is a member of the BaseTranslator class...
137 TranslatorBitmap bitsHeader;
138 status_t status = identify_bits_header(source, NULL, &bitsHeader);
142 return PCX::convert_bits_to_pcx(ioExtension, *source, bitsHeader, *target);
147 // source is NOT in bits format
148 if (outType
!= B_TRANSLATOR_BITMAP
)
149 return B_NO_TRANSLATOR
;
151 return PCX::convert_pcx_to_bits(ioExtension
, *source
, *target
);
155 return B_NO_TRANSLATOR
;
161 PCXTranslator::NewConfigView(TranslatorSettings
*settings
)
163 return new ConfigView(BRect(0, 0, 225, 175));
171 make_nth_translator(int32 n
, image_id you
, uint32 flags
, ...)
176 return new PCXTranslator();