xref: /haiku/src/add-ons/translators/shared/BaseTranslator.h (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 /*****************************************************************************/
2 // BaseTranslator
3 // Written by Michael Wilber, Haiku Translation Kit Team
4 //
5 // BaseTranslator.h
6 //
7 // The BaseTranslator class implements functionality common to most
8 // Translators so that this functionality need not be implemented over and
9 // over in each Translator.
10 //
11 //
12 // Copyright (c) 2004  Haiku, Inc.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
32 
33 #ifndef BASE_TRANSLATOR_H
34 #define BASE_TRANSLATOR_H
35 
36 #include <Translator.h>
37 #include <TranslatorFormats.h>
38 #include <TranslationDefs.h>
39 #include <GraphicsDefs.h>
40 #include <InterfaceDefs.h>
41 #include <DataIO.h>
42 #include <ByteOrder.h>
43 #include <View.h>
44 #include "TranslatorSettings.h"
45 
46 #ifndef min
47 #define min(a,b) ((a < b) ? (a) : (b))
48 #endif
49 #ifndef max
50 #define max(a,b) ((a > b) ? (a) : (b))
51 #endif
52 
53 class BaseTranslator : public BTranslator {
54 public:
55 	BaseTranslator(const char *name, const char *info,
56 		const int32 version, const translation_format *inFormats,
57 		int32 inCount, const translation_format *outFormats, int32 outCount,
58 		const char *settingsFile, TranSetting *defaults, int32 defCount,
59 		uint32 tranGroup, uint32 tranType);
60 
61 	virtual const char *TranslatorName() const;
62 		// returns the short name of the translator
63 
64 	virtual const char *TranslatorInfo() const;
65 		// returns a verbose name/description for the translator
66 
67 	virtual int32 TranslatorVersion() const;
68 		// returns the version of the translator
69 
70 	virtual const translation_format *InputFormats(int32 *out_count)
71 		const;
72 		// returns the input formats and the count of input formats
73 		// that this translator supports
74 
75 	virtual const translation_format *OutputFormats(int32 *out_count)
76 		const;
77 		// returns the output formats and the count of output formats
78 		// that this translator supports
79 
80 	virtual status_t Identify(BPositionIO *inSource,
81 		const translation_format *inFormat, BMessage *ioExtension,
82 		translator_info *outInfo, uint32 outType);
83 		// determines whether or not this translator can convert the
84 		// data in inSource to the type outType
85 
86 	virtual status_t Translate(BPositionIO *inSource,
87 		const translator_info *inInfo, BMessage *ioExtension,
88 		uint32 outType, BPositionIO *outDestination);
89 		// this function is the whole point of the Translation Kit,
90 		// it translates the data in inSource to outDestination
91 		// using the format outType
92 
93 	virtual status_t GetConfigurationMessage(BMessage *ioExtension);
94 		// write the current state of the translator into
95 		// the supplied BMessage object
96 
97 	virtual status_t MakeConfigurationView(BMessage *ioExtension,
98 		BView **outView, BRect *outExtent);
99 		// creates and returns the view for displaying information
100 		// about this translator
101 
102 	TranslatorSettings *AcquireSettings();
103 
104 	// Functions to be implmemented by derived class
105 	virtual status_t DerivedIdentify(BPositionIO *inSource,
106 		const translation_format *inFormat, BMessage *ioExtension,
107 		translator_info *outInfo, uint32 outType);
108 
109 	virtual status_t DerivedTranslate(BPositionIO *inSource,
110 		const translator_info *inInfo, BMessage *ioExtension,
111 		uint32 outType, BPositionIO *outDestination, int32 baseType);
112 
113 	virtual status_t DerivedCanHandleImageSize(float width, float height) const;
114 
115 	virtual BView *NewConfigView(TranslatorSettings *settings);
116 
117 
118 protected:
119 	status_t BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
120 		uint32 &outType);
121 
122 	status_t BitsIdentify(BPositionIO *inSource,
123 		const translation_format *inFormat, BMessage *ioExtension,
124 		translator_info *outInfo, uint32 outType);
125 
126 	status_t identify_bits_header(BPositionIO *inSource,
127 		translator_info *outInfo, TranslatorBitmap *pheader = NULL);
128 
129 	status_t BitsTranslate(BPositionIO *inSource,
130 		const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
131 		BPositionIO *outDestination);
132 
133 	status_t translate_from_bits_to_bits(BPositionIO *inSource,
134 		uint32 outType, BPositionIO *outDestination);
135 
136 	virtual ~BaseTranslator();
137 		// this is protected because the object is deleted by the
138 		// Release() function instead of being deleted directly by
139 		// the user
140 
141 	TranslatorSettings *fSettings;
142 
143 private:
144 	int32 fVersion;
145 	char *fName;
146 	char *fInfo;
147 	const translation_format *fInputFormats;
148 	int32 fInputCount;
149 	const translation_format *fOutputFormats;
150 	int32 fOutputCount;
151 	uint32 fTranGroup;
152 	uint32 fTranType;
153 };
154 
155 void translate_direct_copy(BPositionIO *inSource, BPositionIO *outDestination);
156 
157 #endif // #ifndef BASE_TRANSLATOR_H
158 
159