/[projet1]/public/pc/tools/osdk/main/pictconv/sources/oric_converter.h
Defence Force logotype

Contents of /public/pc/tools/osdk/main/pictconv/sources/oric_converter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1260 - (show annotations)
Sat Feb 14 20:26:49 2015 UTC (4 years, 7 months ago) by dbug
File MIME type: text/plain
File size: 9532 byte(s)
PictConv 0.21
- Added support for 32bit picture, to handle things like masking/opacity in the picture formats
- The -a1 mode will generate bytes with null value for blocks of 6 pixels with transparent alpha values (only active in monochrome or AIC conversion modes)
- Added the -f7 conversion mode for Oric pictures using the AIC coloring method.

1 #ifndef ORIC_CONVERTER_H
2 #define ORIC_CONVERTER_H
3
4 #include "hires.h"
5
6 // This utility macro is used to define the set of all binary operations on an enum.
7 // This makes it possible to do type-safe boolean operations without having to duplicate
8 // the ugly syntax everywhere.
9 //-->> BINARYENUM
10 #ifndef BINARYENUM
11 #define BINARYENUM(T) \
12 inline T& operator++(T& e1) {e1 = (T)((int)(e1)+1);return e1;} \
13 inline T operator++(T& e1,int) {T old(e1);e1 = (T)((int)(e1)+1);return old;} \
14 inline T operator~(const T e1) {return (T)(~(int)e1);} \
15 inline T operator|(const T e1,const T e2) {return (T)((int)e1|(int)e2);} \
16 inline T operator&( const T e1, const T e2 ){return (T)((int)e1&(int)e2);} \
17 inline T operator^( const T e1, const T e2 ){return (T)((int)e1^(int)e2);} \
18 inline T operator-( const T e1, const T e2 ){return (T)((int)e1-(int)e2);} \
19 inline T operator+( const T e1, const T e2 ){return (T)((int)e1+(int)e2);} \
20 inline T& operator |= (T& lhs,T rhs) {lhs=lhs|rhs;return lhs;} \
21 inline T& operator &= (T& lhs,T rhs) {lhs=lhs&rhs;return lhs;} \
22 inline T& operator ^= (T& lhs,T rhs) {lhs=lhs^rhs;return lhs;}
23 #endif
24 // <<-- BINARYENUM
25
26
27 enum ORIC_COLOR
28 { // BGR
29 ORIC_COLOR_BLACK, // 000
30 ORIC_COLOR_RED, // 001
31 ORIC_COLOR_GREEN, // 010
32 ORIC_COLOR_YELLOW, // 011
33 ORIC_COLOR_BLUE, // 100
34 ORIC_COLOR_MAGENTA, // 101
35 ORIC_COLOR_CYAN, // 110
36 ORIC_COLOR_WHITE, // 111
37 _ORIC_COLOR_LAST_,
38 ORIC_COLOR_OPAQUE =0,
39 ORIC_COLOR_TRANSPARENT=8
40 };
41
42 BINARYENUM(ORIC_COLOR)
43
44
45 class BlocOf6
46 {
47 public:
48 BlocOf6()
49 {
50 Clear();
51 }
52
53 void Clear()
54 {
55 color_count=0;
56 colors[0]=ORIC_COLOR_BLACK;
57 colors[1]=ORIC_COLOR_BLACK;
58 value=0;
59 }
60
61 bool AddColor(ORIC_COLOR color)
62 {
63 bool error_in_bloc=false;
64
65 value<<=1;
66
67 // Check if it's already present in the color map
68 switch (color_count)
69 {
70 case 0:
71 color_count++;
72 colors[0]=color;
73 colors[1]=color; // To avoid later tests
74 break;
75
76 case 1:
77 if (colors[0]!=color)
78 {
79 // one more color
80 color_count++;
81 colors[1]=color;
82 value|=1;
83 }
84 break;
85
86 case 2:
87 if (colors[0]!=color)
88 {
89 if (colors[1]==color)
90 {
91 // second color
92 value|=1;
93 }
94 else
95 {
96 // color overflow !!!
97 color_count++;
98
99 error_in_bloc=true;
100 }
101 }
102 break;
103 }
104 return error_in_bloc;
105 }
106
107 bool UsePalette(ORIC_COLOR paperColor,ORIC_COLOR inkColor)
108 {
109 switch (color_count)
110 {
111 case 1: // Only one color is used in this block
112 if (colors[0]==paperColor)
113 {
114 // We already have the right paper color, nothing to do
115 return true;
116 }
117 if (colors[0]==inkColor)
118 {
119 // This block uses the ink color, need to invert the bit mask
120 value^=1+2+4+8+16+32;
121 return true;
122 }
123 if (colors[0]==(paperColor^7))
124 {
125 // This block uses the inverted paper color, need to invert video it
126 value|=128;
127 return true;
128 }
129 if (colors[0]==(inkColor^7))
130 {
131 // This block uses the ink color, need to invert both the bit mask and the invert video bit
132 value^=1+2+4+8+16+32;
133 value|=128;
134 return true;
135 }
136 break;
137
138 case 2: // Two colors are used in this block
139 if ( (colors[0]==paperColor) && (colors[1]==inkColor) )
140 {
141 // We already have the right paper and ink colors, nothing to do
142 return true;
143 }
144 if ( (colors[0]==inkColor) && (colors[1]==paperColor) )
145 {
146 // The paper and ink values are inverted, we need to invert the bit mask
147 value^=1+2+4+8+16+32;
148 return true;
149 }
150 if ( (colors[0]==(paperColor^7)) && (colors[1]==(inkColor^7)) )
151 {
152 // This block uses the inverted paper color, need to invert video it
153 value|=128;
154 return true;
155 }
156 if ( (colors[0]==(inkColor^7)) && (colors[1]==(paperColor^7)) )
157 {
158 // This block uses the ink color, need to invert both the bit mask and the invert video bit
159 value^=1+2+4+8+16+32;
160 value|=128;
161 return true;
162 }
163 break;
164
165 default:
166 // Not the right number of colors, can't do anything about it
167 return false;
168 }
169
170 return true;
171 }
172
173 public:
174 unsigned char color_count; ///< Number of colors in the block (1, 2 or invalid)
175 ORIC_COLOR colors[2]; ///< The two first color found by order of appearance
176 unsigned char value; ///< The bitmap that associate each color to each bit, and possibly the inverse video flag if enabled
177 };
178
179
180
181 class GeneratedBuffer
182 {
183 public:
184 GeneratedBuffer() :
185 m_buffer(0),
186 m_buffer_size(0),
187 m_buffer_width(0),
188 m_buffer_height(0),
189 m_buffer_cols(0)
190 {
191 }
192
193 ~GeneratedBuffer()
194 {
195 delete[] m_buffer;
196 }
197
198
199 void SetBufferSize(int width,int height)
200 {
201 m_buffer_width =width;
202 m_buffer_height =height;
203 m_buffer_cols =(width+5)/6;
204 m_buffer_size =m_buffer_height*m_buffer_cols;
205
206 delete[] m_buffer;
207 m_buffer=new unsigned char[m_buffer_size];
208 }
209
210
211
212 void ClearBuffer(bool setBit6)
213 {
214 //
215 // Fill the screen with a neutral value (64=white space for hires)
216 //
217 unsigned char fillValue;
218 if (setBit6)
219 {
220 fillValue=64;
221 }
222 else
223 {
224 fillValue=0;
225 }
226 for (unsigned int i=0;i<m_buffer_size;i++)
227 {
228 m_buffer[i]=fillValue;
229 }
230 }
231
232 virtual unsigned char *GetBufferData() { return m_buffer; }
233 virtual unsigned int GetBufferSize() { return m_buffer_size; }
234
235 unsigned int get_buffer_width() const { return m_buffer_width; }
236 unsigned int get_buffer_height() const { return m_buffer_height; }
237
238 void SetName(const std::string& name) { m_Name=name; }
239 const std::string& GetName() const { return m_Name; }
240
241 public:
242 std::string m_Name;
243 unsigned char* m_buffer;
244 unsigned int m_buffer_size;
245 unsigned int m_buffer_width;
246 unsigned int m_buffer_height;
247 int m_buffer_cols;
248 };
249
250
251 class OricPictureConverter : public PictureConverter
252 {
253 friend class PictureConverter;
254
255 public:
256 enum FORMAT
257 {
258 FORMAT_MONOCHROM, // -f0 / -f0z
259 FORMAT_COLORED, // -f1
260 FORMAT_RGB, // -f2
261 FORMAT_TWILIGHTE_MASK, // -f3
262 FORMAT_RB, // -f4
263 FORMAT_CHARMAP, // -f5
264 FORMAT_SAM_HOCEVAR, // -f6
265 FORMAT_AIC, // -f7
266 _FORMAT_MAX_
267 };
268
269 public:
270 virtual int GetFormat() const { return (int)m_format; }
271 virtual bool SetFormat(int format) { m_format=(FORMAT)format;return m_format<_FORMAT_MAX_; }
272
273 virtual int GetPaletteMode() const { return 0; }
274 virtual bool SetPaletteMode(int paletteMode) { return paletteMode==0; }
275
276 virtual int GetTransparencyMode() const { return m_transparency; }
277 virtual bool SetTransparencyMode(int transparencyMode) { m_transparency=(TRANSPARENCY)transparencyMode;return m_transparency<_TRANSPARENCY_MAX_; }
278
279 virtual bool Convert(const ImageContainer& sourcePicture);
280 virtual bool TakeSnapShot(ImageContainer& sourcePicture);
281
282 virtual void SaveToFile(long handle,int output_format);
283
284 bool get_bit6() { return m_flag_setbit6; }
285 void set_bit6(bool flag_value) { m_flag_setbit6=flag_value; }
286
287 void convert_monochrom(const ImageContainer& sourcePicture);
288 void convert_colored(const ImageContainer& sourcePicture);
289 void convert_rgb(const ImageContainer& sourcePicture);
290 void convert_rb(const ImageContainer& sourcePicture);
291 void convert_twilighte_mask(const ImageContainer& sourcePicture);
292 void convert_charmap(const ImageContainer& sourcePicture);
293 void convert_sam_hocevar(const ImageContainer& sourcePicture);
294 void convert_aic(const ImageContainer& sourcePicture);
295
296 ORIC_COLOR convert_pixel_monochrom(const ImageContainer& sourcePicture,unsigned int x,unsigned int y);
297 ORIC_COLOR convert_pixel_rgb(const ImageContainer& sourcePicture,unsigned int x,unsigned int y);
298 ORIC_COLOR convert_pixel_rb(const ImageContainer& sourcePicture,unsigned int x,unsigned int y);
299
300 void save_header(long handle,int adress_begin);
301
302 virtual unsigned char *GetBufferData() { return m_Buffer.GetBufferData(); }
303 virtual unsigned int GetBufferSize() { return m_Buffer.GetBufferSize(); }
304
305 virtual unsigned char *GetSecondaryBufferData() { return m_SecondaryBuffer.GetBufferData(); }
306 virtual unsigned int GetSecondaryBufferSize() { return m_SecondaryBuffer.GetBufferSize(); }
307
308 unsigned int get_buffer_width() { return m_Buffer.get_buffer_width(); }
309 unsigned int get_buffer_height() { return m_Buffer.get_buffer_height(); }
310
311 protected:
312 OricPictureConverter();
313 virtual ~OricPictureConverter();
314
315 private:
316 GeneratedBuffer m_Buffer;
317 GeneratedBuffer m_SecondaryBuffer;
318
319 FORMAT m_format;
320 ORIC_COLOR m_PaletteAIC[2][2]; ///< [even/odd scanline[paper/ink color]
321
322 bool m_flag_setbit6;
323 };
324
325 #endif

  ViewVC Help
Powered by ViewVC 1.1.26