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