1693
|
1
|
|
2 #include <stdlib.h>
|
|
3 #include <stdio.h>
|
|
4
|
|
5 #include "../../config.h"
|
|
6 #ifdef xHAVE_MMX
|
|
7 #include "../../main/libvo/mmx.h"
|
|
8 #include "../../main/libvo/fastmemcpy.h"
|
|
9 #endif
|
|
10 #include "wsconv.h"
|
|
11
|
|
12 wsTConvFunc wsConvFunc = NULL;
|
|
13
|
|
14 // ---
|
|
15
|
|
16 #define COPY_RGB_24(src,dst) dst[0]=src[0];dst[1]=src[1];dst[2]=src[2]
|
|
17
|
|
18 #define SWAP_RGB_24(src,dst) dst[1]=src[0];dst[1]=src[1];dst[2]=src[0]
|
|
19
|
|
20 void BGR8880_to_RGB555_c( unsigned char * in_pixels, unsigned char * out_pixels, int num_pixels)
|
|
21 {
|
|
22 unsigned short pixel;
|
|
23 int i;
|
|
24 for(i = 0; i < num_pixels; i++)
|
|
25 {
|
|
26 PACK_RGB15(in_pixels[0],in_pixels[1],in_pixels[2],pixel);
|
|
27 *(unsigned short*)out_pixels = pixel;
|
|
28 in_pixels += 4;
|
|
29 out_pixels += 2;
|
|
30 }
|
|
31 }
|
|
32
|
|
33 void BGR8880_to_BGR555_c( unsigned char * in_pixels, unsigned char * out_pixels, int num_pixels)
|
|
34 {
|
|
35 unsigned short pixel;
|
|
36 int i;
|
|
37 for(i = 0; i < num_pixels; i++)
|
|
38 {
|
|
39 PACK_RGB15(in_pixels[2],in_pixels[1],in_pixels[0],pixel);
|
|
40 *(unsigned short*)out_pixels = pixel;
|
|
41 in_pixels += 4;
|
|
42 out_pixels += 2;
|
|
43 }
|
|
44 }
|
|
45
|
|
46 void BGR8880_to_RGB565_c( unsigned char * in_pixels, unsigned char * out_pixels, int num_pixels)
|
|
47 {
|
|
48 unsigned short pixel;
|
|
49 int i;
|
|
50 for(i = 0; i < num_pixels; i++)
|
|
51 {
|
|
52 PACK_RGB16(in_pixels[0],in_pixels[1],in_pixels[2],pixel);
|
|
53 *(unsigned short*)out_pixels = pixel;
|
|
54 in_pixels += 4;
|
|
55 out_pixels += 2;
|
|
56 }
|
|
57 }
|
|
58
|
|
59 void BGR8880_to_BGR565_c( unsigned char * in_pixels, unsigned char * out_pixels, int num_pixels)
|
|
60 {
|
|
61 unsigned short pixel;
|
|
62 int i;
|
|
63 for(i = 0; i < num_pixels; i++)
|
|
64 {
|
|
65 PACK_RGB16(in_pixels[2],in_pixels[1],in_pixels[0],pixel);
|
|
66 *(unsigned short*)out_pixels = pixel;
|
|
67 in_pixels += 4;
|
|
68 out_pixels += 2;
|
|
69 }
|
|
70 }
|
|
71
|
|
72 void BGR8880_to_RGB888_c( unsigned char * in_pixels, unsigned char * out_pixels,int num_pixels )
|
|
73 {
|
|
74 int i;
|
|
75 for(i = 0; i < num_pixels; i++)
|
|
76 {
|
|
77 COPY_RGB_24(in_pixels,out_pixels);
|
|
78 in_pixels += 4;
|
|
79 out_pixels += 3;
|
|
80 }
|
|
81 }
|
|
82
|
|
83 void BGR8880_to_BGR888_c( unsigned char * in_pixels, unsigned char * out_pixels,int num_pixels )
|
|
84 {
|
|
85 int i;
|
|
86 for(i = 0; i < num_pixels; i++)
|
|
87 {
|
|
88 SWAP_RGB_24(in_pixels,out_pixels);
|
|
89 in_pixels += 4;
|
|
90 out_pixels += 3;
|
|
91 }
|
|
92 }
|
|
93
|
|
94 void BGR8880_to_BGR8880_c( unsigned char * in_pixels, unsigned char * out_pixels,int num_pixels )
|
|
95 {
|
|
96 int i;
|
|
97 for(i = 0; i < num_pixels; i++)
|
|
98 {
|
|
99 SWAP_RGB_24(in_pixels,out_pixels);
|
|
100 in_pixels += 4;
|
|
101 out_pixels += 4;
|
|
102 }
|
|
103 }
|
|
104
|
|
105 void BGR8880_to_RGB8880_c( unsigned char * in_pixels, unsigned char * out_pixels,int num_pixels )
|
|
106 { memcpy( out_pixels,in_pixels,num_pixels * 4 ); }
|
|
107
|
|
108 /*
|
|
109
|
|
110 unsigned char * map_5_to_8[32];
|
|
111 unsigned char * map_6_to_8[64];
|
|
112
|
|
113 #define POINTER_TO_GUINT16(a) *((unsigned short*)a)
|
|
114 #define RGB16_TO_R(pixel) map_5_to_8[pixel & RGB16_LOWER_MASK]
|
|
115 #define RGB16_TO_G(pixel) map_6_to_8[(pixel & RGB16_MIDDLE_MASK)>>5]
|
|
116 #define RGB16_TO_B(pixel) map_5_to_8[(pixel & RGB16_UPPER_MASK)>>11]
|
|
117 #define RGB16_LOWER_MASK 0x001f
|
|
118 #define RGB16_MIDDLE_MASK 0x07e0
|
|
119 #define RGB16_UPPER_MASK 0xf800
|
|
120
|
|
121 void RGB565_to_RGB888_c( unsigned char * in_pixels, unsigned char * out_pixels,int num_pixels)
|
|
122 {
|
|
123 unsigned short in_pixel;
|
|
124 int i;
|
|
125 for(i = 0; i < num_pixels; i++)
|
|
126 {
|
|
127 in_pixel = POINTER_TO_GUINT16(in_pixels);
|
|
128 out_pixels[0] = RGB16_TO_R(in_pixel);
|
|
129 out_pixels[1] = RGB16_TO_G(in_pixel);
|
|
130 out_pixels[2] = RGB16_TO_B(in_pixel);
|
|
131 in_pixels += 2;
|
|
132 out_pixels += 3;
|
|
133 }
|
|
134 }
|
|
135
|
|
136 */
|
|
137
|
|
138 // ---
|
|
139
|
|
140 #ifdef xHAVE_MMX
|
|
141
|
|
142 #define LOAD_32(in) movq_m2r(*in, mm0); in += 8;\
|
|
143 movq_m2r(*in, mm1); in += 8
|
|
144
|
|
145 #define PACK_32_TO_24 movq_r2r(mm0, mm2);\
|
|
146 pand_m2r(rgb32_l_mask,mm0);\
|
|
147 pand_m2r(rgb32_u_mask,mm2);\
|
|
148 psrlq_i2r(8, mm2);\
|
|
149 por_r2r(mm2,mm0);\
|
|
150 movq_r2r(mm1, mm2);\
|
|
151 pand_m2r(rgb32_l_mask,mm1);\
|
|
152 pand_m2r(rgb32_u_mask,mm2);\
|
|
153 psrlq_i2r(8, mm2);\
|
|
154 por_r2r(mm2,mm1);
|
|
155
|
|
156 #define WRITE_24(out) movq_r2m(mm0, *out); out+=6;\
|
|
157 movq_r2m(mm1, *out); out+=6;
|
|
158
|
|
159 #define WRITE_16(out) movq_r2m(mm0, *out); out+=8;
|
|
160
|
|
161 static mmx_t rgb32_l_mask; // Mask for the lower of 2 RGB24 pixels
|
|
162 static mmx_t rgb32_u_mask; // Mask for the upper of 2 RGB24 pixels
|
|
163
|
|
164 static mmx_t rgb32_r_mask; // Mask for the reds of 2 RGB32 pixels
|
|
165 static mmx_t rgb32_g_mask; // Mask for the greens of 2 RGB32 pixels
|
|
166 static mmx_t rgb32_b_mask; // Mask for the blues of 2 RGB32 pixels
|
|
167
|
|
168 static mmx_t lower_dword_mask; // Mask for the lower doublewords
|
|
169 static mmx_t upper_dword_mask; // Mask for the upper doublewords
|
|
170
|
|
171 void BGR8880_to_RGB888_mmx(unsigned char * in_pixels,unsigned char * out_pixels,int num_pixels)
|
|
172 {
|
|
173 int imax = num_pixels/4;
|
|
174 int i;
|
|
175
|
|
176 for(i = 0; i < imax; i++)
|
|
177 {
|
|
178 LOAD_32(in_pixels);
|
|
179 PACK_32_TO_24;
|
|
180 WRITE_24(out_pixels);
|
|
181 }
|
|
182 emms();
|
|
183 }
|
|
184
|
|
185 #endif
|
|
186
|
|
187 // ---
|
|
188
|
|
189 void initConverter( void )
|
|
190 {
|
|
191 #ifdef xHAVE_MMX
|
|
192 // int i;
|
|
193
|
|
194 // for(i = 0; i < 64; i++) map_6_to_8[i] = (unsigned char)((float)i/63.0*255.0+0.5);
|
|
195 // for(i = 0; i < 32; i++) map_5_to_8[i] = (unsigned char)((float)i/31.0*255.0+0.5);
|
|
196
|
|
197 rgb32_l_mask.q = 0x0000000000FFFFFFLL; // Mask for the lower of 2 RGB32 pixels
|
|
198 rgb32_u_mask.q = 0x00FFFFFF00000000LL; // Mask for the upper of 2 RGB32 pixels
|
|
199
|
|
200 rgb32_r_mask.q = 0x000000FF000000FFLL; // Mask for the reds of 2 RGB32 pixels
|
|
201 rgb32_g_mask.q = 0x0000FF000000FF00LL; // Mask for the greens of 2 RGB32 pixels
|
|
202 rgb32_b_mask.q = 0x00FF000000FF0000LL; // Mask for the blues of 2 RGB32 pixels
|
|
203 #endif
|
|
204 } |