xref: /haiku/src/add-ons/translators/webp/WebPTranslator.h (revision 002f37b0cca92e4cf72857c72ac95db5a8b09615)
1 /*
2  * Copyright 2010, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Philippe Houdoin
7  */
8 #ifndef WEBP_TRANSLATOR_H
9 #define WEBP_TRANSLATOR_H
10 
11 
12 #include <ByteOrder.h>
13 #include <DataIO.h>
14 #include <File.h>
15 #include <fs_attr.h>
16 #include <GraphicsDefs.h>
17 #include <InterfaceDefs.h>
18 #include <TranslationDefs.h>
19 #include <Translator.h>
20 #include <TranslatorFormats.h>
21 
22 #include "BaseTranslator.h"
23 
24 #define WEBP_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0,2,0)
25 #define WEBP_IMAGE_FORMAT	'WebP'
26 
27 #define WEBP_SETTING_QUALITY		"quality"
28 #define WEBP_SETTING_PRESET			"preset"
29 #define WEBP_SETTING_SHARPNESS		"sharpness"
30 #define WEBP_SETTING_METHOD			"method"
31 #define WEBP_SETTING_PREPROCESSING	"preprocessing"
32 
33 
34 #define WEBP_IN_QUALITY 0.90
35 #define WEBP_IN_CAPABILITY 0.90
36 
37 #define WEBP_OUT_QUALITY 0.90
38 #define WEBP_OUT_CAPABILITY 0.5
39 
40 #define BITS_IN_QUALITY 0.8
41 #define BITS_IN_CAPABILITY 0.6
42 
43 #define BITS_OUT_QUALITY 0.5
44 #define BITS_OUT_CAPABILITY 0.4
45 
46 
47 struct WebPPicture;
48 
49 
50 class WebPTranslator : public BaseTranslator {
51 public:
52 							WebPTranslator();
53 
54 	virtual status_t 		DerivedIdentify(BPositionIO* stream,
55 								const translation_format* format,
56 								BMessage* settings, translator_info* info,
57 								uint32 outType);
58 
59 	virtual status_t 		DerivedTranslate(BPositionIO* stream,
60 								const translator_info* info,
61 								BMessage* settings, uint32 outType,
62 								BPositionIO* target, int32 baseType);
63 
64 	virtual BView*			NewConfigView(TranslatorSettings* settings);
65 
66 protected:
67 	virtual 				~WebPTranslator();
68 		// this is protected because the object is deleted by the
69 		// Release() function instead of being deleted directly by
70 		// the user
71 
72 private:
73 			status_t		_TranslateFromBits(BPositionIO* stream,
74 								BMessage* settings, uint32 outType,
75 								BPositionIO* target);
76 
77 			status_t		_TranslateFromWebP(BPositionIO* stream,
78 								BMessage* settings, uint32 outType,
79 								BPositionIO* target);
80 
81 	static	int 			_EncodedWriter(const uint8_t* data,
82 								size_t dataSize,
83 								const WebPPicture* const picture);
84 };
85 
86 
87 #endif // #ifndef WEBP_TRANSLATOR_H
88