ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.16 by root, Wed Jul 20 02:26:46 2005 UTC vs.
Revision 1.31 by root, Wed Feb 15 08:08:37 2006 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <string.h>
6#include <setjmp.h>
7
8#include <magic.h>
9
10#include <jpeglib.h>
11#include <glib.h>
12#include <gtk/gtk.h>
5#include <gdk-pixbuf/gdk-pixbuf.h> 13#include <gdk-pixbuf/gdk-pixbuf.h>
6 14
7#include <gperl.h> 15#include <gperl.h>
8#include <gtk2perl.h> 16#include <gtk2perl.h>
9 17
10#define IW 80 18#define IW 80 /* MUST match Schnauer.pm! */
19#define IH 60 /* MUST match Schnauer.pm! */
11 20
12#define RAND (seed = (seed + 7141) * 54773 % 134456) 21#define RAND (seed = (seed + 7141) * 54773 % 134456)
13 22
14#define LINELENGTH 240 23#define LINELENGTH 240
15 24
16#define ELLIPSIS "\xe2\x80\xa6" 25#define ELLIPSIS "\xe2\x80\xa6"
26
27struct jpg_err_mgr
28{
29 struct jpeg_error_mgr err;
30 jmp_buf setjmp_buffer;
31};
32
33static void
34cv_error_exit (j_common_ptr cinfo)
35{
36 longjmp (((struct jpg_err_mgr *)cinfo->err)->setjmp_buffer, 99);
37}
38
39static void
40cv_error_output (j_common_ptr cinfo)
41{
42 return;
43}
44
45static void
46rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b,
47 unsigned int *h, unsigned int *s, unsigned int *v)
48{
49 unsigned int mx = r; if (g > mx) mx = g; if (b > mx) mx = b;
50 unsigned int mn = r; if (g < mn) mn = g; if (b < mn) mn = b;
51 unsigned int delta = mx - mn;
52
53 *v = mx;
54
55 *s = mx ? delta * 255 / mx : 0;
56
57 if (delta == 0)
58 *h = 0;
59 else
60 {
61 if (r == mx)
62 *h = ((int)g - (int)b) * 255 / (int)(delta * 3);
63 else if (g == mx)
64 *h = ((int)b - (int)r) * 255 / (int)(delta * 3) + 52;
65 else if (b == mx)
66 *h = ((int)r - (int)g) * 255 / (int)(delta * 3) + 103;
67
68 *h &= 255;
69 }
70}
17 71
18static guint32 a85_val; 72static guint32 a85_val;
19static guint a85_cnt; 73static guint a85_cnt;
20static guchar a85_buf[LINELENGTH], *a85_ptr; 74static guchar a85_buf[LINELENGTH], *a85_ptr;
21 75
68 *a85_ptr++ = '\n'; 122 *a85_ptr++ = '\n';
69 123
70 PerlIO_write (fp, a85_buf, a85_ptr - a85_buf); 124 PerlIO_write (fp, a85_buf, a85_ptr - a85_buf);
71} 125}
72 126
73static void
74rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b,
75 unsigned int *h, unsigned int *s, unsigned int *v)
76{
77 unsigned int mx = r; if (g > mx) mx = g; if (b > mx) mx = b;
78 unsigned int mn = r; if (g < mn) mn = g; if (b < mn) mn = b;
79 unsigned int delta = mx - mn;
80
81 *v = mx;
82
83 *s = mx ? delta * 255 / mx : 0;
84
85 if (delta == 0)
86 *h = 0;
87 else
88 {
89 if (r == mx)
90 *h = ((int)g - (int)b) * 255 / (int)(delta * 3);
91 else if (g == mx)
92 *h = ((int)b - (int)r) * 255 / (int)(delta * 3) + 52;
93 else if (b == mx)
94 *h = ((int)r - (int)g) * 255 / (int)(delta * 3) + 103;
95
96 *h &= 255;
97 }
98}
99
100///////////////////////////////////////////////////////////////////////////// 127/////////////////////////////////////////////////////////////////////////////
101 128
102MODULE = Gtk2::CV PACKAGE = Gtk2::CV 129MODULE = Gtk2::CV PACKAGE = Gtk2::CV
103 130
104PROTOTYPES: ENABLE 131PROTOTYPES: ENABLE
105 132
133# missing function in perl. really :)
134int
135common_prefix_length (a, b)
136 unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg);
137 unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg);
138 CODE:
139 RETVAL = 0;
140
141 while (*a == *b && *a)
142 {
143 RETVAL += (*a & 0xc0) != 0x80;
144 a++, b++;
145 }
146
147 OUTPUT:
148 RETVAL
149
150const char *
151magic (const char *path)
152 CODE:
153{
154 static magic_t cookie;
155
156 if (!cookie)
157 {
158 cookie = magic_open (MAGIC_MIME);
159
160 if (cookie)
161 magic_load (cookie, 0);
162 else
163 XSRETURN_UNDEF;
164 }
165
166 RETVAL = magic_file (cookie, path);
167}
168 OUTPUT:
169 RETVAL
170
171# missing in Gtk2 perl module
172
173gboolean
174gdk_net_wm_supports (GdkAtom property)
175 CODE:
176#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
177 RETVAL = gdk_net_wm_supports (property);
178#else
179 RETVAL = 0;
180#endif
181 OUTPUT:
182 RETVAL
183
106GdkPixbuf_noinc * 184GdkPixbuf_noinc *
107transpose (GdkPixbuf *pb) 185dealpha_expose (GdkPixbuf *pb)
108 CODE: 186 CODE:
109{ 187{
110 int w = gdk_pixbuf_get_width (pb); 188 int w = gdk_pixbuf_get_width (pb);
111 int h = gdk_pixbuf_get_height (pb); 189 int h = gdk_pixbuf_get_height (pb);
112 int bpp = gdk_pixbuf_get_n_channels (pb); 190 int bpp = gdk_pixbuf_get_n_channels (pb);
113 int x, y, i; 191 int x, y, i;
114 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 192 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
115 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 193 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
116 194
117 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); 195 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
118 196
119 dst = gdk_pixbuf_get_pixels (RETVAL); 197 dst = gdk_pixbuf_get_pixels (RETVAL);
120 dstr = gdk_pixbuf_get_rowstride (RETVAL); 198 dstr = gdk_pixbuf_get_rowstride (RETVAL);
121 199
122 for (y = 0; y < h; y++)
123 for (x = 0; x < w; x++) 200 for (x = 0; x < w; x++)
201 for (y = 0; y < h; y++)
124 for (i = 0; i < bpp; i++) 202 for (i = 0; i < 3; i++)
125 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; 203 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
126} 204}
127 OUTPUT: 205 OUTPUT:
128 RETVAL 206 RETVAL
129 207
130GdkPixbuf_noinc * 208GdkPixbuf_noinc *
131flop (GdkPixbuf *pb) 209rotate (GdkPixbuf *pb, int angle)
132 CODE: 210 CODE:
133{ 211 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
134 int w = gdk_pixbuf_get_width (pb); 212 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
135 int h = gdk_pixbuf_get_height (pb); 213 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
136 int bpp = gdk_pixbuf_get_n_channels (pb); 214 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
137 int x, y, i; 215 : angle);
138 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 216 OUTPUT:
139 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 217 RETVAL
140 218
141 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h); 219GdkPixbuf_noinc *
220load_jpeg (SV *path, int thumbnail=0)
221 CODE:
222{
223 struct jpeg_decompress_struct cinfo;
224 struct jpg_err_mgr jerr;
225 guchar *data;
226 int rs;
227 FILE *fp;
228 volatile GdkPixbuf *pb = 0;
142 229
230 RETVAL = 0;
231
232 fp = fopen (SvPVbyte_nolen (path), "rb");
233
234 if (!fp)
235 XSRETURN_UNDEF;
236
237 cinfo.err = jpeg_std_error (&jerr.err);
238
239 jerr.err.error_exit = cv_error_exit;
240 jerr.err.output_message = cv_error_output;
241
242 if ((rs = setjmp (jerr.setjmp_buffer)))
243 {
244 fclose (fp);
245 jpeg_destroy_decompress (&cinfo);
246
247 if (pb)
248 g_object_unref ((gpointer)pb);
249
250 XSRETURN_UNDEF;
251 }
252
253 jpeg_create_decompress (&cinfo);
254
255 jpeg_stdio_src (&cinfo, fp);
256 jpeg_read_header (&cinfo, TRUE);
257
258 cinfo.dct_method = JDCT_DEFAULT;
259 cinfo.do_fancy_upsampling = FALSE; /* worse quality, but nobody compained so far, and gdk-pixbuf does the same */
260 cinfo.do_block_smoothing = FALSE;
261 cinfo.out_color_space = JCS_RGB;
262 cinfo.quantize_colors = FALSE;
263
264 cinfo.scale_num = 1;
265 cinfo.scale_denom = 1;
266
267 jpeg_calc_output_dimensions (&cinfo);
268
269 if (thumbnail)
270 {
271 cinfo.dct_method = JDCT_FASTEST;
272 cinfo.do_fancy_upsampling = FALSE;
273
274 while (cinfo.scale_denom < 8
275 && cinfo.output_width >= IW*4
276 && cinfo.output_height >= IH*4)
277 {
278 cinfo.scale_denom <<= 1;
279 jpeg_calc_output_dimensions (&cinfo);
280 }
281 }
282
283 pb = RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, cinfo.output_width, cinfo.output_height);
284 if (!RETVAL)
285 longjmp (jerr.setjmp_buffer, 2);
286
143 dst = gdk_pixbuf_get_pixels (RETVAL); 287 data = gdk_pixbuf_get_pixels (RETVAL);
144 dstr = gdk_pixbuf_get_rowstride (RETVAL); 288 rs = gdk_pixbuf_get_rowstride (RETVAL);
145 289
146 for (y = 0; y < h; y++) 290 if (cinfo.output_components != 3)
147 for (x = 0; x < w; x++) 291 longjmp (jerr.setjmp_buffer, 3);
148 for (i = 0; i < bpp; i++) 292
149 dst[(w - 1 - x) * bpp + y * dstr + i] = src[x * bpp + y * sstr + i]; 293 jpeg_start_decompress (&cinfo);
294
295 while (cinfo.output_scanline < cinfo.output_height)
296 {
297 int remaining = cinfo.output_height - cinfo.output_scanline;
298 JSAMPROW rp[4];
299
300 rp [0] = data + cinfo.output_scanline * rs;
301 rp [1] = (guchar *)rp [0] + rs;
302 rp [2] = (guchar *)rp [1] + rs;
303 rp [3] = (guchar *)rp [2] + rs;
304
305 jpeg_read_scanlines (&cinfo, rp, remaining < 4 ? remaining : 4);
306 }
307
308 jpeg_finish_decompress (&cinfo);
309 fclose (fp);
310 jpeg_destroy_decompress (&cinfo);
150} 311}
151 OUTPUT: 312 OUTPUT:
152 RETVAL 313 RETVAL
153 314
154############################################################################# 315#############################################################################
155 316
156MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 317MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
157 318
319SV *
320foldcase (SV *pathsv)
321 PROTOTYPE: $
322 CODE:
323{
324 STRLEN plen;
325 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
326 U8 *pend = path + plen;
327 U8 dst [plen * 6 * 3], *dstp = dst;
328
329 while (path < pend)
330 {
331 U8 ch = *path;
332
333 if (ch >= 'a' && ch <= 'z')
334 *dstp++ = *path++;
335 else if (ch >= '0' && ch <= '9')
336 {
337 STRLEN el, nl = 0;
338 while (*path >= '0' && *path <= '9' && path < pend)
339 path++, nl++;
340
341 for (el = nl; el < 6; el++)
342 *dstp++ = '0';
343
344 memcpy (dstp, path - nl, nl);
345 dstp += nl;
346 }
347 else
348 {
349 STRLEN cl;
350 to_utf8_fold (path, dstp, &cl);
351 dstp += cl;
352 path += is_utf8_char (path);
353 }
354 }
355
356 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
357}
358 OUTPUT:
359 RETVAL
360
158GdkPixbuf_noinc * 361GdkPixbuf_noinc *
159p7_to_pb (int w, int h, guchar *src) 362p7_to_pb (int w, int h, SV *src_sv)
363 PROTOTYPE: @
160 CODE: 364 CODE:
161{ 365{
162 int x, y; 366 int x, y;
163 guchar *dst, *d; 367 guchar *dst, *d;
164 int dstr; 368 int dstr;
369 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
165 370
166 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 371 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
167 dst = gdk_pixbuf_get_pixels (RETVAL); 372 dst = gdk_pixbuf_get_pixels (RETVAL);
168 dstr = gdk_pixbuf_get_rowstride (RETVAL); 373 dstr = gdk_pixbuf_get_rowstride (RETVAL);
169 374
178 } 383 }
179} 384}
180 OUTPUT: 385 OUTPUT:
181 RETVAL 386 RETVAL
182 387
388#############################################################################
389
390MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
391
392void
393dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
394 CODE:
395{
396 int w = gdk_pixbuf_get_width (pb);
397 int h = gdk_pixbuf_get_height (pb);
398 int x, y, i;
399 guchar *dst;
400 int bpp = gdk_pixbuf_get_n_channels (pb);
401 guchar *src = gdk_pixbuf_get_pixels (pb);
402 int sstr = gdk_pixbuf_get_rowstride (pb);
403
404 a85_init ();
405
406 for (y = 0; y < h; y++)
407 for (x = 0; x < w; x++)
408 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
409 a85_push (fp, src [x * bpp + y * sstr + i]);
410
411 a85_finish (fp);
412}
413
414void
415dump_binary (PerlIO *fp, GdkPixbuf *pb)
416 CODE:
417{
418 int w = gdk_pixbuf_get_width (pb);
419 int h = gdk_pixbuf_get_height (pb);
420 int x, y, i;
421 guchar *dst;
422 int bpp = gdk_pixbuf_get_n_channels (pb);
423 guchar *src = gdk_pixbuf_get_pixels (pb);
424 int sstr = gdk_pixbuf_get_rowstride (pb);
425
426 for (y = 0; y < h; y++)
427 for (x = 0; x < w; x++)
428 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
429 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
430}
431
432#############################################################################
433
434MODULE = Gtk2::CV PACKAGE = Gtk2::CV
435
183SV * 436SV *
184pb_to_p7 (GdkPixbuf *pb) 437pb_to_hv84 (GdkPixbuf *pb)
185 CODE: 438 CODE:
186{ 439{
187 int w = gdk_pixbuf_get_width (pb); 440 int w = gdk_pixbuf_get_width (pb);
188 int h = gdk_pixbuf_get_height (pb); 441 int h = gdk_pixbuf_get_height (pb);
189 int x, y; 442 int x, y;
190 guchar *dst; 443 guchar *dst;
191 int bpp = gdk_pixbuf_get_n_channels (pb); 444 int bpp = gdk_pixbuf_get_n_channels (pb);
192 guchar *src = gdk_pixbuf_get_pixels (pb); 445 guchar *src = gdk_pixbuf_get_pixels (pb);
193 int sstr = gdk_pixbuf_get_rowstride (pb); 446 int sstr = gdk_pixbuf_get_rowstride (pb);
194 int Er[IW], Eg[IW], Eb[IW];
195 int seed = 77;
196 447
197 RETVAL = newSV (w * h); 448 RETVAL = newSV (6 * 8 * 12 / 8);
198 SvPOK_only (RETVAL); 449 SvPOK_only (RETVAL);
199 SvCUR_set (RETVAL, w * h); 450 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
200 451
201 dst = SvPVX (RETVAL); 452 dst = (guchar *)SvPVX (RETVAL);
202
203 memset (Er, 0, sizeof (int) * IW);
204 memset (Eg, 0, sizeof (int) * IW);
205 memset (Eb, 0, sizeof (int) * IW);
206 453
207 /* some primitive error distribution + random dithering */ 454 /* some primitive error distribution + random dithering */
208 455
209 for (y = 0; y < h; y++) 456 for (y = 0; y < h; y++)
210 { 457 {
211 int er = 0, eg = 0, eb = 0; 458 guchar *p = src + y * sstr;
212 459
213 for (x = 0; x < w; x++) 460 for (x = 0; x < w; x += 2)
214 { 461 {
215 int r, g, b; 462 unsigned int r, g, b, h, s, v, H, V1, V2;
216 guchar *p = src + x * bpp + y * sstr;
217 463
218 r = ((p[0] + er + Er[x]) * 7 + 128) / 255; 464 if (bpp == 3)
219 g = ((p[1] + eg + Eg[x]) * 7 + 128) / 255; 465 r = *p++, g = *p++, b = *p++;
220 b = ((p[2] + eb + Eb[x]) * 3 + 128) / 255; 466 else if (bpp == 1)
467 r = g = b = *p++;
468 else
469 abort ();
221 470
222 r = r > 7 ? 7 : r < 0 ? 0 : r; 471 rgb_to_hsv (r, g, b, &h, &s, &v);
223 g = g > 7 ? 7 : g < 0 ? 0 : g;
224 b = b > 3 ? 3 : b < 0 ? 0 : b;
225 472
226 er += p[0] - (r * 255 + 4) / 7; 473 H = (h * 15 / 255) << 4;
227 eg += p[1] - (g * 255 + 4) / 7; 474 V1 = v;
228 eb += p[2] - (b * 255 + 2) / 3;
229 475
230 Er[x] = er / 2; er -= er / 2 + RAND % 5 - 2; 476 if (bpp == 3)
231 Eg[x] = eg / 2; eg -= eg / 2 + RAND % 5 - 2; 477 r = *p++, g = *p++, b = *p++;
232 Eb[x] = eb / 2; eb -= eb / 2 + RAND % 5 - 2; 478 else if (bpp == 1)
479 r = g = b = *p++;
480 else
481 abort ();
233 482
234 *dst++ = r << 5 | g << 2 | b; 483 rgb_to_hsv (r, g, b, &h, &s, &v);
484
485 H |= h * 15 / 255;
486 V2 = v;
487
488 *dst++ = H;
489 *dst++ = V1;
490 *dst++ = V2;
235 } 491 }
236 } 492 }
237} 493}
238 OUTPUT: 494 OUTPUT:
239 RETVAL 495 RETVAL
240 496
241SV * 497SV *
498hv84_to_av (unsigned char *hv84)
499 CODE:
500{
501 int i = 72 / 3;
502 AV *av = newAV ();
503
504 RETVAL = (SV *)newRV_noinc ((SV *)av);
505 while (i--)
506 {
507 int h = *hv84++;
508 int v1 = *hv84++;
509 int v2 = *hv84++;
510
511 av_push (av, newSViv (v1));
512 av_push (av, newSViv ((h >> 4) * 255 / 15));
513 av_push (av, newSViv (v2));
514 av_push (av, newSViv ((h & 15) * 255 / 15));
515 }
516}
517 OUTPUT:
518 RETVAL
519
520#############################################################################
521
522MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
523
524SV *
242make_histogram (SV *ar) 525make_histograms (SV *ar)
243 CODE: 526 CODE:
244{ 527{
245 int i; 528 int i;
246 AV *av, *result; 529 AV *av, *result;
247 530
291} 574}
292 OUTPUT: 575 OUTPUT:
293 RETVAL 576 RETVAL
294 577
295 578
296
297#############################################################################
298
299MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
300
301void
302dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
303 CODE:
304{
305 int w = gdk_pixbuf_get_width (pb);
306 int h = gdk_pixbuf_get_height (pb);
307 int x, y, i;
308 guchar *dst;
309 int bpp = gdk_pixbuf_get_n_channels (pb);
310 guchar *src = gdk_pixbuf_get_pixels (pb);
311 int sstr = gdk_pixbuf_get_rowstride (pb);
312
313 a85_init ();
314
315 for (y = 0; y < h; y++)
316 for (x = 0; x < w; x++)
317 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
318 a85_push (fp, src [x * bpp + y * sstr + i]);
319
320 a85_finish (fp);
321}
322
323void
324dump_binary (PerlIO *fp, GdkPixbuf *pb)
325 CODE:
326{
327 int w = gdk_pixbuf_get_width (pb);
328 int h = gdk_pixbuf_get_height (pb);
329 int x, y, i;
330 guchar *dst;
331 int bpp = gdk_pixbuf_get_n_channels (pb);
332 guchar *src = gdk_pixbuf_get_pixels (pb);
333 int sstr = gdk_pixbuf_get_rowstride (pb);
334
335 for (y = 0; y < h; y++)
336 for (x = 0; x < w; x++)
337 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
338 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
339}
340
341#############################################################################
342
343MODULE = Gtk2::CV PACKAGE = Gtk2::CV
344
345SV *
346pb_to_hv84 (GdkPixbuf *pb)
347 CODE:
348{
349 int w = gdk_pixbuf_get_width (pb);
350 int h = gdk_pixbuf_get_height (pb);
351 int x, y;
352 guchar *dst;
353 int bpp = gdk_pixbuf_get_n_channels (pb);
354 guchar *src = gdk_pixbuf_get_pixels (pb);
355 int sstr = gdk_pixbuf_get_rowstride (pb);
356
357 RETVAL = newSV (6 * 8 * 12 / 8);
358 SvPOK_only (RETVAL);
359 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
360
361 dst = SvPVX (RETVAL);
362
363 /* some primitive error distribution + random dithering */
364
365 for (y = 0; y < h; y++)
366 {
367 guchar *p = src + y * sstr;
368
369 for (x = 0; x < w; x += 2)
370 {
371 unsigned int r, g, b, h, s, v, H, V1, V2;
372
373 if (bpp == 3)
374 r = *p++, g = *p++, b = *p++;
375 else if (bpp == 1)
376 r = g = b = *p++;
377 else
378 abort ();
379
380 rgb_to_hsv (r, g, b, &h, &s, &v);
381
382 H = (h * 15 / 255) << 4;
383 V1 = v;
384
385 if (bpp == 3)
386 r = *p++, g = *p++, b = *p++;
387 else if (bpp == 1)
388 r = g = b = *p++;
389 else
390 abort ();
391
392 rgb_to_hsv (r, g, b, &h, &s, &v);
393
394 H |= h * 15 / 255;
395 V2 = v;
396
397 *dst++ = H;
398 *dst++ = V1;
399 *dst++ = V2;
400 }
401 }
402}
403 OUTPUT:
404 RETVAL
405
406SV *
407hv84_to_av (unsigned char *hv84)
408 CODE:
409{
410 int i = 72 / 3;
411 AV *av = newAV ();
412
413 RETVAL = (SV *)newRV_noinc ((SV *)av);
414 while (i--)
415 {
416 int h = *hv84++;
417 int v1 = *hv84++;
418 int v2 = *hv84++;
419
420 av_push (av, newSViv (v1));
421 av_push (av, newSViv ((h >> 4) * 255 / 15));
422 av_push (av, newSViv (v2));
423 av_push (av, newSViv ((h & 15) * 255 / 15));
424 }
425}
426 OUTPUT:
427 RETVAL
428
429
430

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines