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