Anti-Grain Geometry Tutorial
agg_color_conv_rgb16.h
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 //
16 // This part of the library has been sponsored by
17 // Liberty Technology Systems, Inc., visit http://lib-sys.com
18 //
19 // Liberty Technology Systems, Inc. is the provider of
20 // PostScript and PDF technology for software developers.
21 //
22 //----------------------------------------------------------------------------
23 //
24 // A set of functors used with color_conv(). See file agg_color_conv.h
25 // These functors can convert images with up to 8 bits per component.
26 // Use convertors in the following way:
27 //
28 // agg::color_conv(dst, src, agg::color_conv_XXXX_to_YYYY());
29 //----------------------------------------------------------------------------
30 
31 #ifndef AGG_COLOR_CONV_RGB16_INCLUDED
32 #define AGG_COLOR_CONV_RGB16_INCLUDED
33 
34 #include "agg_basics.h"
35 #include "agg_color_conv.h"
36 
37 namespace agg
38 {
39 
40  //-------------------------------------------------color_conv_gray16_to_gray8
42  {
43  public:
44  void operator () (int8u* dst,
45  const int8u* src,
46  unsigned width) const
47  {
48  int16u* s = (int16u*)src;
49  do
50  {
51  *dst++ = *s++ >> 8;
52  }
53  while(--width);
54  }
55  };
56 
57 
58  //-----------------------------------------------------color_conv_rgb24_rgb48
59  template<int I1, int I3> class color_conv_rgb24_rgb48
60  {
61  public:
62  void operator () (int8u* dst,
63  const int8u* src,
64  unsigned width) const
65  {
66  int16u* d = (int16u*)dst;
67  do
68  {
69  *d++ = (src[I1] << 8) | src[I1];
70  *d++ = (src[1] << 8) | src[1] ;
71  *d++ = (src[I3] << 8) | src[I3];
72  src += 3;
73  }
74  while(--width);
75  }
76  };
77 
82 
83 
84  //-----------------------------------------------------color_conv_rgb24_rgb48
85  template<int I1, int I3> class color_conv_rgb48_rgb24
86  {
87  public:
88  void operator () (int8u* dst,
89  const int8u* src,
90  unsigned width) const
91  {
92  const int16u* s = (const int16u*)src;
93  do
94  {
95  *dst++ = s[I1] >> 8;
96  *dst++ = s[1] >> 8;
97  *dst++ = s[I3] >> 8;
98  s += 3;
99  }
100  while(--width);
101  }
102  };
103 
108 
109 
110  //----------------------------------------------color_conv_rgbAAA_rgb24
111  template<int R, int B> class color_conv_rgbAAA_rgb24
112  {
113  public:
114  void operator () (int8u* dst,
115  const int8u* src,
116  unsigned width) const
117  {
118  do
119  {
120  int32u rgb = *(int32u*)src;
121  dst[R] = int8u(rgb >> 22);
122  dst[1] = int8u(rgb >> 12);
123  dst[B] = int8u(rgb >> 2);
124  src += 4;
125  dst += 3;
126  }
127  while(--width);
128  }
129  };
130 
135 
136 
137  //----------------------------------------------color_conv_rgbBBA_rgb24
138  template<int R, int B> class color_conv_rgbBBA_rgb24
139  {
140  public:
141  void operator () (int8u* dst,
142  const int8u* src,
143  unsigned width) const
144  {
145  do
146  {
147  int32u rgb = *(int32u*)src;
148  dst[R] = int8u(rgb >> 24);
149  dst[1] = int8u(rgb >> 13);
150  dst[B] = int8u(rgb >> 2);
151  src += 4;
152  dst += 3;
153  }
154  while(--width);
155  }
156  };
157 
160 
161 
162  //----------------------------------------------color_conv_bgrABB_rgb24
163  template<int B, int R> class color_conv_bgrABB_rgb24
164  {
165  public:
166  void operator () (int8u* dst,
167  const int8u* src,
168  unsigned width) const
169  {
170  do
171  {
172  int32u bgr = *(int32u*)src;
173  dst[R] = int8u(bgr >> 3);
174  dst[1] = int8u(bgr >> 14);
175  dst[B] = int8u(bgr >> 24);
176  src += 4;
177  dst += 3;
178  }
179  while(--width);
180  }
181  };
182 
185 
186 
187  //-------------------------------------------------color_conv_rgba64_rgba32
188  template<int I1, int I2, int I3, int I4> class color_conv_rgba64_rgba32
189  {
190  public:
191  void operator () (int8u* dst,
192  const int8u* src,
193  unsigned width) const
194  {
195  do
196  {
197  *dst++ = int8u(((int16u*)src)[I1] >> 8);
198  *dst++ = int8u(((int16u*)src)[I2] >> 8);
199  *dst++ = int8u(((int16u*)src)[I3] >> 8);
200  *dst++ = int8u(((int16u*)src)[I4] >> 8);
201  src += 8;
202  }
203  while(--width);
204  }
205  };
206 
207  //------------------------------------------------------------------------
208  typedef color_conv_rgba64_rgba32<0,1,2,3> color_conv_rgba64_to_rgba32; //----color_conv_rgba64_to_rgba32
209  typedef color_conv_rgba64_rgba32<0,1,2,3> color_conv_argb64_to_argb32; //----color_conv_argb64_to_argb32
210  typedef color_conv_rgba64_rgba32<0,1,2,3> color_conv_bgra64_to_bgra32; //----color_conv_bgra64_to_bgra32
211  typedef color_conv_rgba64_rgba32<0,1,2,3> color_conv_abgr64_to_abgr32; //----color_conv_abgr64_to_abgr32
212  typedef color_conv_rgba64_rgba32<0,3,2,1> color_conv_argb64_to_abgr32; //----color_conv_argb64_to_abgr32
213  typedef color_conv_rgba64_rgba32<3,2,1,0> color_conv_argb64_to_bgra32; //----color_conv_argb64_to_bgra32
214  typedef color_conv_rgba64_rgba32<1,2,3,0> color_conv_argb64_to_rgba32; //----color_conv_argb64_to_rgba32
215  typedef color_conv_rgba64_rgba32<3,0,1,2> color_conv_bgra64_to_abgr32; //----color_conv_bgra64_to_abgr32
216  typedef color_conv_rgba64_rgba32<3,2,1,0> color_conv_bgra64_to_argb32; //----color_conv_bgra64_to_argb32
217  typedef color_conv_rgba64_rgba32<2,1,0,3> color_conv_bgra64_to_rgba32; //----color_conv_bgra64_to_rgba32
218  typedef color_conv_rgba64_rgba32<3,2,1,0> color_conv_rgba64_to_abgr32; //----color_conv_rgba64_to_abgr32
219  typedef color_conv_rgba64_rgba32<3,0,1,2> color_conv_rgba64_to_argb32; //----color_conv_rgba64_to_argb32
220  typedef color_conv_rgba64_rgba32<2,1,0,3> color_conv_rgba64_to_bgra32; //----color_conv_rgba64_to_bgra32
221  typedef color_conv_rgba64_rgba32<0,3,2,1> color_conv_abgr64_to_argb32; //----color_conv_abgr64_to_argb32
222  typedef color_conv_rgba64_rgba32<1,2,3,0> color_conv_abgr64_to_bgra32; //----color_conv_abgr64_to_bgra32
223  typedef color_conv_rgba64_rgba32<3,2,1,0> color_conv_abgr64_to_rgba32; //----color_conv_abgr64_to_rgba32
224 
225 
226 
227  //--------------------------------------------color_conv_rgb24_rgba64
228  template<int I1, int I2, int I3, int A> class color_conv_rgb24_rgba64
229  {
230  public:
231  void operator () (int8u* dst,
232  const int8u* src,
233  unsigned width) const
234  {
235  int16u* d = (int16u*)dst;
236  do
237  {
238  d[I1] = (src[0] << 8) | src[0];
239  d[I2] = (src[1] << 8) | src[1];
240  d[I3] = (src[2] << 8) | src[2];
241  d[A] = 65535;
242  d += 4;
243  src += 3;
244  }
245  while(--width);
246  }
247  };
248 
249 
250  //------------------------------------------------------------------------
251  typedef color_conv_rgb24_rgba64<1,2,3,0> color_conv_rgb24_to_argb64; //----color_conv_rgb24_to_argb64
252  typedef color_conv_rgb24_rgba64<3,2,1,0> color_conv_rgb24_to_abgr64; //----color_conv_rgb24_to_abgr64
253  typedef color_conv_rgb24_rgba64<2,1,0,3> color_conv_rgb24_to_bgra64; //----color_conv_rgb24_to_bgra64
254  typedef color_conv_rgb24_rgba64<0,1,2,3> color_conv_rgb24_to_rgba64; //----color_conv_rgb24_to_rgba64
255  typedef color_conv_rgb24_rgba64<3,2,1,0> color_conv_bgr24_to_argb64; //----color_conv_bgr24_to_argb64
256  typedef color_conv_rgb24_rgba64<1,2,3,0> color_conv_bgr24_to_abgr64; //----color_conv_bgr24_to_abgr64
257  typedef color_conv_rgb24_rgba64<0,1,2,3> color_conv_bgr24_to_bgra64; //----color_conv_bgr24_to_bgra64
258  typedef color_conv_rgb24_rgba64<2,1,0,3> color_conv_bgr24_to_rgba64; //----color_conv_bgr24_to_rgba64
259 
260 
261  template<int R, int B> class color_conv_rgb24_gray16
262  {
263  public:
264  void operator () (int8u* dst,
265  const int8u* src,
266  unsigned width) const
267  {
268  int16u* d = (int16u*)dst;
269  do
270  {
271  *d++ = src[R]*77 + src[1]*150 + src[B]*29;
272  src += 3;
273  }
274  while(--width);
275  }
276  };
277 
280 
281 
282 }
283 
284 
285 #endif
Definition: agg_arc.cpp:24