File: ccvt_misc.c

package info (click to toggle)
squeak-vm 1%3A4.10.2.2614%2B20120917~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,144 kB
  • sloc: ansic: 72,193; objc: 5,494; sh: 3,061; asm: 1,533; cpp: 449; pascal: 372; makefile: 300; awk: 103; cs: 11
file content (195 lines) | stat: -rw-r--r-- 5,029 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*  CCVT: ColourConVerT: simple library for converting colourspaces
    Copyright (C) 2002 Nemosoft Unv.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    For questions, remarks, patches, etc. for this program, the author can be
    reached at nemosoft@smcc.demon.nl.
*/

/* This file contains CCVT functions that aren't available in assembly yet
   (or are not worth programming)
 */

/* 
 * $Log: ccvt_misc.c,v $
 * Revision 1.7  2003/01/02 04:10:19  nemosoft
 * Adding ''upside down" conversion to rgb/bgr routines
 *
 * Revision 1.6  2002/12/03 23:29:11  nemosoft
 * *** empty log message ***
 *
 * Revision 1.5  2002/12/03 23:27:41  nemosoft
 * fixing log messages (gcc 3.2 complaining)
 *
   Revision 1.4  2002/12/03 22:29:07  nemosoft
   Fixing up FTP stuff and some video

   Revision 1.3  2002/11/03 22:46:25  nemosoft
   Adding various RGB to RGB functions.
   Adding proper copyright header too.
 */


#include "ccvt.h"
#include "ccvt_types.h"


/* YUYV: two Y's and one U/V */
void ccvt_yuyv_rgb32(int width, int height, const void *src, void *dst)
{


}


void ccvt_yuyv_bgr32(int width, int height, const void *src, void *dst)
{
   const unsigned char *s;
   PIXTYPE_bgr32 *d;
   int l, c;
   int r, g, b, cr, cg, cb, y1, y2;
   
   l = height;
   s = src;
   d = dst;
   while (l--) {
      c = width >> 2;
      while (c--) {
         y1 = *s++;
         cb = ((*s - 128) * 454) >> 8;
         cg = (*s++ - 128) * 88;
         y2 = *s++;
         cr = ((*s - 128) * 359) >> 8;
         cg = (cg + (*s++ - 128) * 183) >> 8;

         r = y1 + cr;
         b = y1 + cb;
         g = y1 - cg;
         SAT(r);
         SAT(g);
         SAT(b);               
         d->b = b;	
         d->g = g;           
         d->r = r;          
         d++;             
         r = y2 + cr;
         b = y2 + cb;
         g = y2 - cg;
         SAT(r);
         SAT(g);
         SAT(b);               
         d->b = b;
         d->g = g;           
         d->r = r;          
         d++;             
      }
   }
   
}

void ccvt_yuyv_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv)
{
   int n, l, j;
   const unsigned char *s1, *s2;
   unsigned char *dy, *du, *dv;
   
   dy = (unsigned char *)dsty;
   du = (unsigned char *)dstu;
   dv = (unsigned char *)dstv;
   s1 = (unsigned char *)src;
   s2 = s1; // keep pointer
   n = width * height;
   for (; n > 0; n--) {
      *dy = *s1;
      dy++;
      s1 += 2;
   }
   
   /* Two options here: average U/V values, or skip every second row */
   s1 = s2; // restore pointer
   s1++; // point to U
   for (l = 0; l < height; l += 2) {
      s2 = s1 + width * 2; // odd line
      for (j = 0; j < width; j += 2) {
         *du = (*s1 + *s2) / 2;
         du++;
         s1 += 2;
         s2 += 2;
         *dv = (*s1 + *s2) / 2;
         dv++;
         s1 += 2;
         s2 += 2;
      }
      s1 = s2;
   }
}

/* RGB/BGR to RGB/BGR */

#define RGBBGR_BODY24(TIN, TOUT) \
void ccvt_ ## TIN ## _ ## TOUT (int width, int height, const void *const src, void *const dst) \
{ \
   const PIXTYPE_ ## TIN *in = src; \
   PIXTYPE_ ## TOUT *out = dst; \
   int l, c, stride = 0; \
   \
   if (height < 0) { stride = width; height = -height; } \
   out += ((height - 1) * width); \
   stride *= 2; \
   for (l = 0; l < height; l++) { \
      for (c = 0; c < width; c++) { \
         out->r = in->r; \
         out->g = in->g; \
         out->b = in->b; \
         in++; \
         out++; \
      } \
      out -= stride; \
   } \
}

#define RGBBGR_BODY32(TIN, TOUT) \
void ccvt_ ## TIN ## _ ## TOUT (int width, int height, const void *const src, void *const dst) \
{ \
   const PIXTYPE_ ## TIN *in = src; \
   PIXTYPE_ ## TOUT *out = dst; \
   int l, c, stride = 0; \
   \
   if (height < 0) { stride = width; height = -height; } \
   out += ((height - 1) * width); \
   stride *= 2; \
   for (l = 0; l < height; l++) { \
      for (c = 0; c < width; c++) { \
         out->r = in->r; \
         out->g = in->g; \
         out->b = in->b; \
         out->z = 0; \
         in++; \
         out++; \
      } \
      out -= stride; \
   } \
}

RGBBGR_BODY32(bgr24, bgr32)
RGBBGR_BODY32(bgr24, rgb32)
RGBBGR_BODY32(rgb24, bgr32)
RGBBGR_BODY32(rgb24, rgb32)

RGBBGR_BODY24(bgr32, bgr24)
RGBBGR_BODY24(bgr32, rgb24)
RGBBGR_BODY24(rgb32, bgr24)
RGBBGR_BODY24(rgb32, rgb24)