2 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 #include "ICOTranslator.h"
16 #include "ConfigView.h"
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "ICOTranslator"
24 const char *kDocumentCount
= "/documentCount";
25 const char *kDocumentIndex
= "/documentIndex";
27 #define kICOMimeType "image/vnd.microsoft.icon"
28 #define kICOName "Windows icon"
29 // I'm lazy - structure initializers don't like const variables...
32 // The input formats that this translator supports.
33 static const translation_format sInputFormats
[] = {
48 "Be Bitmap Format (ICOTranslator)"
52 // The output formats that this translator supports.
53 static const translation_format sOutputFormats
[] = {
68 "Be Bitmap Format (ICOTranslator)"
72 // Default settings for the Translator
73 static const TranSetting sDefaultSettings
[] = {
74 {B_TRANSLATOR_EXT_HEADER_ONLY
, TRAN_SETTING_BOOL
, false},
75 {B_TRANSLATOR_EXT_DATA_ONLY
, TRAN_SETTING_BOOL
, false}
78 const uint32 kNumInputFormats
= sizeof(sInputFormats
) / sizeof(translation_format
);
79 const uint32 kNumOutputFormats
= sizeof(sOutputFormats
) / sizeof(translation_format
);
80 const uint32 kNumDefaultSettings
= sizeof(sDefaultSettings
) / sizeof(TranSetting
);
83 ICOTranslator::ICOTranslator()
84 : BaseTranslator(B_TRANSLATE("Windows icons"),
85 B_TRANSLATE("Windows icon translator"),
86 ICO_TRANSLATOR_VERSION
,
87 sInputFormats
, kNumInputFormats
,
88 sOutputFormats
, kNumOutputFormats
,
89 "ICOTranslator_Settings",
90 sDefaultSettings
, kNumDefaultSettings
,
91 B_TRANSLATOR_BITMAP
, ICO_IMAGE_FORMAT
)
96 ICOTranslator::~ICOTranslator()
102 ICOTranslator::DerivedIdentify(BPositionIO
*stream
,
103 const translation_format
*format
, BMessage
*ioExtension
,
104 translator_info
*info
, uint32 outType
)
107 outType
= B_TRANSLATOR_BITMAP
;
108 if (outType
!= B_TRANSLATOR_BITMAP
&& outType
!= ICO_IMAGE_FORMAT
)
109 return B_NO_TRANSLATOR
;
113 if (ICO::identify(ioExtension
, *stream
, type
, bitsPerPixel
) != B_OK
)
114 return B_NO_TRANSLATOR
;
116 info
->type
= ICO_IMAGE_FORMAT
;
117 info
->group
= B_TRANSLATOR_BITMAP
;
118 info
->quality
= ICO_IN_QUALITY
;
119 info
->capability
= ICO_IN_CAPABILITY
;
120 snprintf(info
->name
, sizeof(info
->name
),
121 B_TRANSLATE("Windows %s %ld bit image"),
122 type
== ICO::kTypeIcon
? B_TRANSLATE("Icon") : B_TRANSLATE("Cursor"),
124 strcpy(info
->MIME
, kICOMimeType
);
131 ICOTranslator::DerivedTranslate(BPositionIO
*source
,
132 const translator_info
*info
, BMessage
*ioExtension
,
133 uint32 outType
, BPositionIO
*target
, int32 baseType
)
136 outType
= B_TRANSLATOR_BITMAP
;
137 if (outType
!= B_TRANSLATOR_BITMAP
&& outType
!= ICO_IMAGE_FORMAT
)
138 return B_NO_TRANSLATOR
;
143 if (outType
!= ICO_IMAGE_FORMAT
)
144 return B_NO_TRANSLATOR
;
146 // Source is in bits format - this has to be done here, because
147 // identify_bits_header() is a member of the BaseTranslator class...
148 TranslatorBitmap bitsHeader
;
149 status_t status
= identify_bits_header(source
, NULL
, &bitsHeader
);
153 return ICO::convert_bits_to_ico(ioExtension
, *source
, bitsHeader
, *target
);
158 // source is NOT in bits format
159 if (outType
!= B_TRANSLATOR_BITMAP
)
160 return B_NO_TRANSLATOR
;
162 return ICO::convert_ico_to_bits(ioExtension
, *source
, *target
);
166 return B_NO_TRANSLATOR
;
172 ICOTranslator::DerivedCanHandleImageSize(float width
, float height
) const
174 if (!ICO::is_valid_size((int)width
) || !ICO::is_valid_size((int)height
))
175 return B_NO_TRANSLATOR
;
181 ICOTranslator::NewConfigView(TranslatorSettings
*settings
)
183 return new ConfigView();
191 make_nth_translator(int32 n
, image_id you
, uint32 flags
, ...)
196 return new ICOTranslator();