BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / translators / pcx / PCXTranslator.cpp
blob7881288a5a4b0a96c0bd9fa6f46193448822a9c6
1 /*
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.
5 */
8 #include "PCXTranslator.h"
9 #include "ConfigView.h"
10 #include "PCX.h"
12 #include <Catalog.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.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[] = {
26 PCX_IMAGE_FORMAT,
27 B_TRANSLATOR_BITMAP,
28 PCX_IN_QUALITY,
29 PCX_IN_CAPABILITY,
30 kPCXMimeType,
31 "PCX image"
32 }/*,
34 B_TRANSLATOR_BITMAP,
35 B_TRANSLATOR_BITMAP,
36 BITS_IN_QUALITY,
37 BITS_IN_CAPABILITY,
38 "image/x-be-bitmap",
39 "Be Bitmap Format (PCXTranslator)"
40 },*/
43 // The output formats that this translator supports.
44 static const translation_format sOutputFormats[] = {
45 /*{
46 PCX_IMAGE_FORMAT,
47 B_TRANSLATOR_BITMAP,
48 PCX_OUT_QUALITY,
49 PCX_OUT_CAPABILITY,
50 kPCXMimeType,
51 "PCX image"
52 },*/
54 B_TRANSLATOR_BITMAP,
55 B_TRANSLATOR_BITMAP,
56 BITS_OUT_QUALITY,
57 BITS_OUT_CAPABILITY,
58 "image/x-be-bitmap",
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()
92 status_t
93 PCXTranslator::DerivedIdentify(BPositionIO *stream,
94 const translation_format *format, BMessage *ioExtension,
95 translator_info *info, uint32 outType)
97 if (!outType)
98 outType = B_TRANSLATOR_BITMAP;
99 if (outType != B_TRANSLATOR_BITMAP && outType != PCX_IMAGE_FORMAT)
100 return B_NO_TRANSLATOR;
102 int32 bitsPerPixel;
103 uint8 type;
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"),
112 bitsPerPixel);
113 strcpy(info->MIME, kPCXMimeType);
115 return B_OK;
119 status_t
120 PCXTranslator::DerivedTranslate(BPositionIO *source,
121 const translator_info *info, BMessage *ioExtension,
122 uint32 outType, BPositionIO *target, int32 baseType)
124 /*if (!outType)
125 outType = B_TRANSLATOR_BITMAP;
126 if (outType != B_TRANSLATOR_BITMAP && outType != PCX_IMAGE_FORMAT)
127 return B_NO_TRANSLATOR;*/
129 switch (baseType) {
130 /*case 1:
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);
139 if (status != B_OK)
140 return status;
142 return PCX::convert_bits_to_pcx(ioExtension, *source, bitsHeader, *target);
145 case 0:
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);
154 default:
155 return B_NO_TRANSLATOR;
160 BView *
161 PCXTranslator::NewConfigView(TranslatorSettings *settings)
163 return new ConfigView(BRect(0, 0, 225, 175));
167 // #pragma mark -
170 BTranslator *
171 make_nth_translator(int32 n, image_id you, uint32 flags, ...)
173 if (n != 0)
174 return NULL;
176 return new PCXTranslator();