1 /************************************************************************
2 *
3 * dither.c, pseudo colour dithering for tmndecode (H.263 decoder)
4 * Copyright (C) 1995, 1996 Telenor R&D, Norway
5 *
6 * Contacts:
7 * Robert Danielsen <Robert.Danielsen@nta.no>
8 *
9 * Telenor Research and Development http://www.nta.no/brukere/DVC/
10 * P.O.Box 83 tel.: +47 63 84 84 00
11 * N-2007 Kjeller, Norway fax.: +47 63 81 00 76
12 *
13 * Copyright (C) 1997 University of BC, Canada
14 * Modified by: Michael Gallant <mikeg@ee.ubc.ca>
15 * Guy Cote <guyc@ee.ubc.ca>
16 * Berna Erol <bernae@ee.ubc.ca>
17 *
18 * Contacts:
19 * Michael Gallant <mikeg@ee.ubc.ca>
20 *
21 * UBC Image Processing Laboratory http://www.ee.ubc.ca/image
22 * 2356 Main Mall tel.: +1 604 822 4051
23 * Vancouver BC Canada V6T1Z4 fax.: +1 604 822 5949
24 *
25 ************************************************************************/
26
27 /* Disclaimer of Warranty
28 *
29 * These software programs are available to the user without any license fee
30 * or royalty on an "as is" basis. The University of British Columbia
31 * disclaims any and all warranties, whether express, implied, or
32 * statuary, including any implied warranties or merchantability or of
33 * fitness for a particular purpose. In no event shall the
34 * copyright-holder be liable for any incidental, punitive, or
35 * consequential damages of any kind whatsoever arising from the use of
36 * these programs.
37 *
38 * This disclaimer of warranty extends to the user of these programs and
39 * user's customers, employees, agents, transferees, successors, and
40 * assigns.
41 *
42 * The University of British Columbia does not represent or warrant that the
43 * programs furnished hereunder are free of infringement of any
44 * third-party patents.
45 *
46 * Commercial implementations of H.263, including shareware, are subject to
47 * royalty fees to patent holders. Many of these patents are general
48 * enough such that they are unavoidable regardless of implementation
49 * design.
50 *
51 */
52
53
54
55 /* based on mpeg2decode, (C) 1994, MPEG Software Simulation Group and
56 * mpeg2play, (C) 1994 Stefan Eckart <stefan@lis.e-technik.tu-muenchen.de>
57 *
58 */
59
60 #ifdef DISPLAY
61
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <X11/Xlib.h>
65 #include <X11/Xutil.h>
66 #include "config.h"
67 #include "tmndec.h"
68 #include "global.h"
69
70 extern unsigned char pixel[256];
71
72 static unsigned char ytab[16 * (256 + 16)];
73 static unsigned char uvtab[256 * 269 + 270];
74
75 /****************************************************************************
76
77 4x4 ordered dither
78
79 Threshold pattern:
80
81 0 8 2 10
82 12 4 14 6
83 3 11 1 9
84 15 7 13 5
85
86 ****************************************************************************/
87 void
88 ord4x4_dither_init (void)
89 {
90 int i, j, v;
91 unsigned char ctab[256 + 32];
92
93 for (i = 0; i < 256 + 16; i++)
94 {
95 v = (i - 8) >> 4;
96 if (v < 2)
97 v = 2;
98 else if (v > 14)
99 v = 14;
100 for (j = 0; j < 16; j++)
101 ytab[16 * i + j] = pixel[(v << 4) + j];
102 }
103
104 for (i = 0; i < 256 + 32; i++)
105 {
106 v = (i + 48 - 128) >> 5;
107 if (v < 0)
108 v = 0;
109 else if (v > 3)
110 v = 3;
111 ctab[i] = v;
112 }
113
114 for (i = 0; i < 255 + 15; i++)
115 for (j = 0; j < 255 + 15; j++)
116 uvtab[256 * i + j] = (ctab[i + 16] << 6) | (ctab[j + 16] << 4) | (ctab[i] << 2) | ctab[j];
117 }
118
119
120
121 void
122 ord4x4_dither_frame (unsigned char *src[], unsigned char *dst)
123 {
124 int i, j;
125 unsigned char *py = src[0];
126 unsigned char *pu = src[1];
127 unsigned char *pv = src[2];
128
129 int width, height, cwidth;
130
131 if (expand)
132 {
133 width = 2 * ref_coded_picture_width;
134 height = 2 * ref_coded_picture_height;
135 cwidth = 2 * ref_chrom_width;
136 } else
137 {
138 width = ref_coded_picture_width;
139 height = ref_coded_picture_height;
140 cwidth = ref_chrom_width;
141 }
142
143 for (j = 0; j < height; j += 4)
144 {
145 register unsigned int uv;
146
147 /* line j + 0 */
148 for (i = 0; i < width; i += 8)
149 {
150 uv = uvtab[(*pu++ << 8) | *pv++];
151 *dst++ = ytab[((*py++) << 4) | (uv & 15)];
152 *dst++ = ytab[((*py++ + 8) << 4) | (uv >> 4)];
153 uv = uvtab[((*pu++ << 8) | *pv++) + 1028];
154 *dst++ = ytab[((*py++ + 2) << 4) | (uv & 15)];
155 *dst++ = ytab[((*py++ + 10) << 4) | (uv >> 4)];
156 uv = uvtab[(*pu++ << 8) | *pv++];
157 *dst++ = ytab[((*py++) << 4) | (uv & 15)];
158 *dst++ = ytab[((*py++ + 8) << 4) | (uv >> 4)];
159 uv = uvtab[((*pu++ << 8) | *pv++) + 1028];
160 *dst++ = ytab[((*py++ + 2) << 4) | (uv & 15)];
161 *dst++ = ytab[((*py++ + 10) << 4) | (uv >> 4)];
162 }
163
164 pu -= cwidth;
165 pv -= cwidth;
166
167 /* line j + 1 */
168 for (i = 0; i < width; i += 8)
169 {
170 uv = uvtab[((*pu++ << 8) | *pv++) + 2056];
171 *dst++ = ytab[((*py++ + 12) << 4) | (uv >> 4)];
172 *dst++ = ytab[((*py++ + 4) << 4) | (uv & 15)];
173 uv = uvtab[((*pu++ << 8) | *pv++) + 3084];
174 *dst++ = ytab[((*py++ + 14) << 4) | (uv >> 4)];
175 *dst++ = ytab[((*py++ + 6) << 4) | (uv & 15)];
176 uv = uvtab[((*pu++ << 8) | *pv++) + 2056];
177 *dst++ = ytab[((*py++ + 12) << 4) | (uv >> 4)];
178 *dst++ = ytab[((*py++ + 4) << 4) | (uv & 15)];
179 uv = uvtab[((*pu++ << 8) | *pv++) + 3084];
180 *dst++ = ytab[((*py++ + 14) << 4) | (uv >> 4)];
181 *dst++ = ytab[((*py++ + 6) << 4) | (uv & 15)];
182 }
183
184 /* line j + 2 */
185 for (i = 0; i < width; i += 8)
186 {
187 uv = uvtab[((*pu++ << 8) | *pv++) + 1542];
188 *dst++ = ytab[((*py++ + 3) << 4) | (uv & 15)];
189 *dst++ = ytab[((*py++ + 11) << 4) | (uv >> 4)];
190 uv = uvtab[((*pu++ << 8) | *pv++) + 514];
191 *dst++ = ytab[((*py++ + 1) << 4) | (uv & 15)];
192 *dst++ = ytab[((*py++ + 9) << 4) | (uv >> 4)];
193 uv = uvtab[((*pu++ << 8) | *pv++) + 1542];
194 *dst++ = ytab[((*py++ + 3) << 4) | (uv & 15)];
195 *dst++ = ytab[((*py++ + 11) << 4) | (uv >> 4)];
196 uv = uvtab[((*pu++ << 8) | *pv++) + 514];
197 *dst++ = ytab[((*py++ + 1) << 4) | (uv & 15)];
198 *dst++ = ytab[((*py++ + 9) << 4) | (uv >> 4)];
199 }
200
201 pu -= cwidth;
202 pv -= cwidth;
203
204 /* line j + 3 */
205 for (i = 0; i < width; i += 8)
206 {
207 uv = uvtab[((*pu++ << 8) | *pv++) + 3598];
208 *dst++ = ytab[((*py++ + 15) << 4) | (uv >> 4)];
209 *dst++ = ytab[((*py++ + 7) << 4) | (uv & 15)];
210 uv = uvtab[((*pu++ << 8) | *pv++) + 2570];
211 *dst++ = ytab[((*py++ + 13) << 4) | (uv >> 4)];
212 *dst++ = ytab[((*py++ + 5) << 4) | (uv & 15)];
213 uv = uvtab[((*pu++ << 8) | *pv++) + 3598];
214 *dst++ = ytab[((*py++ + 15) << 4) | (uv >> 4)];
215 *dst++ = ytab[((*py++ + 7) << 4) | (uv & 15)];
216 uv = uvtab[((*pu++ << 8) | *pv++) + 2570];
217 *dst++ = ytab[((*py++ + 13) << 4) | (uv >> 4)];
218 *dst++ = ytab[((*py++ + 5) << 4) | (uv & 15)];
219 }
220 }
221 }
222 #endif
223
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.