File: pixword.c

package info (click to toggle)
euslisp 9.31%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,448 kB
  • sloc: ansic: 41,610; lisp: 3,339; makefile: 286; sh: 238; asm: 138; python: 53
file content (82 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download | duplicates (2)
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
/*
pixword.c
(c)1995, Toshihiro Matsui, Electrotechnical Laboratory
*/
static char *rcsid= "@(#)$Id: pixword.c,v 1.1.1.1 2003/11/20 07:46:30 eus Exp $";

#include "../c/eus.h"

#pragma init (init_object_module)
pointer pixword();

static void init_object_module()
  { add_module_initializer("pixword", pixword);}

pointer SPLIT_RGB(ctx,n,argv)
context *ctx;
int n;
pointer *argv;
{ register int size3, size1, s1, s3, offset;
  byte *rgb, *r, *g, *b;
  pointer rgbp, rp, gp, bp;

  /* a vector each of which element represents RGB colors is
     split into three vectors for R, G, and B */

  ckarg2(4,6);
  if (!isstring(argv[0])) error(E_NOSTRING);
  if (!isstring(argv[1])) error(E_NOSTRING);
  if (!isstring(argv[2])) error(E_NOSTRING);
  if (!isstring(argv[3])) error(E_NOSTRING);

  if (n>=5) offset=ckintval(argv[4]); else offset=0;

  rgbp=argv[0];  rp=argv[1];  gp=argv[2];  bp=argv[3];
  r=rp->c.str.chars; g=gp->c.str.chars; b=bp->c.str.chars; 
  rgb=rgbp->c.str.chars;
  if (n==6)   size3=ckintval(argv[5]);
  else size3=vecsize(rgbp);

  size1=size3/3;
  for (s1=0, s3=0; s1<size1; s1++)  {
    r[offset+s1]=rgb[s3++];
    g[offset+s1]=rgb[s3++];
    b[offset+s1]=rgb[s3++];}
  return(makeint(size3));}

pointer MERGE_RGB(ctx,n,argv)
context *ctx;
int n;
pointer *argv;
{ register int size3, size1, s1, s3, offset;
  byte *rgb, *r, *g, *b;

  /* three R,G, and B vectors are merged into one RGB vector */
  /* (merge-rgb rgbvec red green blue) */
  ckarg(5);
  if (!isstring(argv[0])) error(E_NOSTRING);
  if (!isstring(argv[1])) error(E_NOSTRING);
  if (!isstring(argv[2])) error(E_NOSTRING);
  if (!isstring(argv[3])) error(E_NOSTRING);
  size1=vecsize(argv[0]);
  rgb=argv[0]->c.str.chars;
  r=argv[1]->c.str.chars;
  g=argv[2]->c.str.chars;
  b=argv[3]->c.str.chars; 
  offset=ckintval(argv[4]);
  size3=vecsize(argv[0]);
  for (s1=0, s3=0; s3<size3; s1++)  {
    rgb[s3++]=r[s1+offset];
    rgb[s3++]=g[s1+offset];
    rgb[s3++]=b[s1+offset];}
  return(argv[0]);}

pointer pixword(ctx,n,argv)
  context *ctx;
  int n;
  pointer argv[];
{ pointer mod=argv[0];
  defun(ctx,"SPLIT-RGB",mod,SPLIT_RGB,NULL);
  defun(ctx,"MERGE-RGB",mod,MERGE_RGB,NULL);
  }