1 /*
2    Generic format conversion routines for the HERMES library
3    Copyright (c) 1998 Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
4    This source code is licensed under the GNU LGPL
5 
6    Please refer to the file COPYING.LIB contained in the distribution for
7    licensing conditions
8 */
9 
10 #include "HermConf.h"
11 #include "HeadC.h"
12 #include "Debug.h"
13 
14 // ***********************************************
15 // ******** The Generic Conversion Macros ********
16 // ***********************************************
17 
18 #define CG_VARS() int32 s_pixel; \
19         unsigned int count; \
20         char8 *source=iface->s_pixels; \
21 	char8 *dest=iface->d_pixels; \
22 	int32 sc = iface->s_colorkey; \
23 	int32 dc = iface->d_colorkey; \
24 	int32 d_pixel;
25 
26 // Define the general macro
27 // src_read_macro = READxx
28 // dest_write_macro = WRITEyy
29 // src_byte_inc = xx/8
30 // dest_byte_inc = yy/8
31 // convert_rgb_macro = Macro to convert the RGB eg CONVERT_RGB
32 // dest_read_macro = READyy
33 #define CG_STANDARD(src_read_macro, dest_write_macro, src_byte_inc, dest_byte_inc, convert_rgb_macro, dest_read_macro) \
34 	do { \
35 		count=iface->s_width; \
36 		do { \
37 			s_pixel = src_read_macro(source); \
38 			d_pixel = dest_read_macro(source); \
39 			if ( (s_pixel != sc) && (d_pixel == dc ) ) \
40 			{ \
41 				dest_write_macro(dest, (convert_rgb_macro(s_pixel))); \
42 			} \
43 			source+=src_byte_inc; \
44 			dest+=dest_byte_inc; \
45 		} while(--count); \
46         	source+=iface->s_add; \
47         	dest+=iface->d_add; \
48         } while (--iface->s_height);
49 
50 // ***********************************************
51 // ******** The Stretch Conversion Macros ********
52 // ***********************************************
53 
54 #define CG_S_VARS() int32 s_pixel; \
55         unsigned int count; \
56         char8 *source=iface->s_pixels; \
57 	char8 *dest=iface->d_pixels; \
58         unsigned int dy=(iface->s_height<<16)/iface->d_height; \
59         unsigned int dx=(iface->s_width<<16)/iface->d_width; \
60         unsigned int y=0,x; \
61 	int32 sc = iface->s_colorkey; \
62 	int32 dc = iface->d_colorkey; \
63 	int32 d_pixel;
64 
65 // Define the general macro
66 // src_read_macro = READxx
67 // dest_write_macro = WRITEyy
68 // src_byte_inc = xx/8
69 // dest_byte_inc = yy/8
70 // convert_rgb_macro = Macro to convert the RGB eg CONVERT_RGB
71 // dest_read_macro = READyy
72 #define CG_S_STANDARD(src_read_macro, dest_write_macro, src_byte_inc, dest_byte_inc, convert_rgb_macro, dest_read_macro) \
73 	do { \
74 		count=iface->d_width; \
75 		x = 0; \
76 		do { \
77 			s_pixel = src_read_macro(source + (x>>16)); \
78 			d_pixel = dest_read_macro(source + (x>>16)); \
79 			if ( (s_pixel != sc) && (d_pixel == dc ) ) \
80 			{ \
81 				dest_write_macro(dest, (convert_rgb_macro(s_pixel))); \
82 			} \
83 			x+=dx; \
84 			dest+=dest_byte_inc; \
85 		} while(--count); \
86         	dest+=iface->d_add; \
87         	y+=dy; \
88         	source+=(y>>16)*iface->s_pitch; \
89 	        y &= 0xffff; \
90         } while (--iface->d_height);
91 
92 // **************************************************
93 // ******** The Generic Conversion Functions ********
94 // **************************************************
95 
ConvertC_Generic32_C_Generic32_C_Blit(HermesConverterInterface * iface)96 void ConvertC_Generic32_C_Generic32_C_Blit(HermesConverterInterface *iface)
97 {
98   CG_IDENTICAL( READ32, WRITE32, 4, READ32 )
99 }
100 
ConvertC_Generic32_C_Generic24_C_Blit(HermesConverterInterface * iface)101 void ConvertC_Generic32_C_Generic24_C_Blit(HermesConverterInterface *iface)
102 {
103   CG_NORMAL( READ32, WRITE24, 4, 3, READ24 )
104 }
105 
ConvertC_Generic32_C_Generic16_C_Blit(HermesConverterInterface * iface)106 void ConvertC_Generic32_C_Generic16_C_Blit(HermesConverterInterface *iface)
107 {
108   CG_NORMAL( READ32, WRITE16, 4, 2, READ16 )
109 }
110 
ConvertC_Generic32_C_Generic8_C_Blit(HermesConverterInterface * iface)111 void ConvertC_Generic32_C_Generic8_C_Blit(HermesConverterInterface *iface)
112 {
113   CG_NORMAL( READ32, WRITE8, 4, 1, READ8 )
114 }
115 
ConvertC_Generic24_C_Generic32_C_Blit(HermesConverterInterface * iface)116 void ConvertC_Generic24_C_Generic32_C_Blit(HermesConverterInterface *iface)
117 {
118   CG_NORMAL( READ24, WRITE32, 3, 4, READ32 )
119 }
120 
ConvertC_Generic24_C_Generic24_C_Blit(HermesConverterInterface * iface)121 void ConvertC_Generic24_C_Generic24_C_Blit(HermesConverterInterface *iface)
122 {
123   CG_IDENTICAL( READ24, WRITE24, 3, READ24 )
124 }
125 
ConvertC_Generic24_C_Generic16_C_Blit(HermesConverterInterface * iface)126 void ConvertC_Generic24_C_Generic16_C_Blit(HermesConverterInterface *iface)
127 {
128   CG_NORMAL( READ24, WRITE16, 3, 2, READ16 )
129 }
130 
ConvertC_Generic24_C_Generic8_C_Blit(HermesConverterInterface * iface)131 void ConvertC_Generic24_C_Generic8_C_Blit(HermesConverterInterface *iface)
132 {
133   CG_NORMAL( READ24, WRITE8, 3, 1, READ8 )
134 }
135 
ConvertC_Generic16_C_Generic32_C_Blit(HermesConverterInterface * iface)136 void ConvertC_Generic16_C_Generic32_C_Blit(HermesConverterInterface *iface)
137 {
138   CG_NORMAL( READ16, WRITE32, 2, 4, READ32 )
139 }
140 
ConvertC_Generic16_C_Generic24_C_Blit(HermesConverterInterface * iface)141 void ConvertC_Generic16_C_Generic24_C_Blit(HermesConverterInterface *iface)
142 {
143   CG_NORMAL( READ16, WRITE24, 2, 3, READ24 )
144 }
145 
ConvertC_Generic16_C_Generic16_C_Blit(HermesConverterInterface * iface)146 void ConvertC_Generic16_C_Generic16_C_Blit(HermesConverterInterface *iface)
147 {
148   CG_IDENTICAL( READ16, WRITE16, 2, READ16 )
149 }
150 
ConvertC_Generic16_C_Generic8_C_Blit(HermesConverterInterface * iface)151 void ConvertC_Generic16_C_Generic8_C_Blit(HermesConverterInterface *iface)
152 {
153   CG_NORMAL( READ16, WRITE8, 2, 1, READ8 )
154 }
155 
156 // **************************************************
157 // ******** The Stretch Conversion Functions ********
158 // **************************************************
159 
ConvertC_Generic32_C_Generic32_C_S_Blit(HermesConverterInterface * iface)160 void ConvertC_Generic32_C_Generic32_C_S_Blit(HermesConverterInterface *iface)
161 {
162   CG_S_IDENTICAL( READ32, WRITE32, 4, READ32 )
163 }
164 
ConvertC_Generic32_C_Generic24_C_S_Blit(HermesConverterInterface * iface)165 void ConvertC_Generic32_C_Generic24_C_S_Blit(HermesConverterInterface *iface)
166 {
167   CG_S_NORMAL( READ32, WRITE24, 4, 3, READ24 )
168 }
169 
ConvertC_Generic32_C_Generic16_C_S_Blit(HermesConverterInterface * iface)170 void ConvertC_Generic32_C_Generic16_C_S_Blit(HermesConverterInterface *iface)
171 {
172   CG_S_NORMAL( READ32, WRITE16, 4, 2, READ16 )
173 }
174 
ConvertC_Generic32_C_Generic8_C_S_Blit(HermesConverterInterface * iface)175 void ConvertC_Generic32_C_Generic8_C_S_Blit(HermesConverterInterface *iface)
176 {
177   CG_S_NORMAL( READ32, WRITE8, 4, 1, READ8 )
178 }
179 
ConvertC_Generic24_C_Generic32_C_S_Blit(HermesConverterInterface * iface)180 void ConvertC_Generic24_C_Generic32_C_S_Blit(HermesConverterInterface *iface)
181 {
182   CG_S_NORMAL( READ24, WRITE32, 3, 4, READ32 )
183 }
184 
ConvertC_Generic24_C_Generic24_C_S_Blit(HermesConverterInterface * iface)185 void ConvertC_Generic24_C_Generic24_C_S_Blit(HermesConverterInterface *iface)
186 {
187   CG_S_IDENTICAL( READ24, WRITE24, 3, READ24 )
188 }
189 
ConvertC_Generic24_C_Generic16_C_S_Blit(HermesConverterInterface * iface)190 void ConvertC_Generic24_C_Generic16_C_S_Blit(HermesConverterInterface *iface)
191 {
192   CG_S_NORMAL( READ24, WRITE16, 3, 2, READ16 )
193 }
194 
ConvertC_Generic24_C_Generic8_C_S_Blit(HermesConverterInterface * iface)195 void ConvertC_Generic24_C_Generic8_C_S_Blit(HermesConverterInterface *iface)
196 {
197   CG_S_NORMAL( READ24, WRITE8, 3, 1, READ8 )
198 }
199 
ConvertC_Generic16_C_Generic32_C_S_Blit(HermesConverterInterface * iface)200 void ConvertC_Generic16_C_Generic32_C_S_Blit(HermesConverterInterface *iface)
201 {
202   CG_S_NORMAL( READ16, WRITE32, 2, 4, READ32 )
203 }
204 
ConvertC_Generic16_C_Generic24_C_S_Blit(HermesConverterInterface * iface)205 void ConvertC_Generic16_C_Generic24_C_S_Blit(HermesConverterInterface *iface)
206 {
207   CG_S_NORMAL( READ16, WRITE24, 2, 3, READ24 )
208 }
209 
ConvertC_Generic16_C_Generic16_C_S_Blit(HermesConverterInterface * iface)210 void ConvertC_Generic16_C_Generic16_C_S_Blit(HermesConverterInterface *iface)
211 {
212   CG_S_IDENTICAL( READ16, WRITE16, 2, READ16 )
213 }
214 
ConvertC_Generic16_C_Generic8_C_S_Blit(HermesConverterInterface * iface)215 void ConvertC_Generic16_C_Generic8_C_S_Blit(HermesConverterInterface *iface)
216 {
217   CG_S_NORMAL( READ16, WRITE8, 2, 1, READ8 )
218 }
219