1 /*
2  * This software is copyrighted as noted below.  It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is".  Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * chroma.c - do a chroma with two images.
20  *
21  * Author:      Raul Rivero
22  *              Mathematics Dept.
23  *              University of Oviedo
24  * Date:        Mon Jan 6 1992
25  * Copyright (c) 1992, Raul Rivero
26  *
27  */
28 
29 #include <lug.h>
30 #include <lugfnts.h>
31 
chroma_bitmaps(basebitmap,superbitmap,outbitmap)32 chroma_bitmaps(basebitmap, superbitmap, outbitmap)
33 bitmap_hdr *basebitmap, *superbitmap;
34 bitmap_hdr *outbitmap;
35 {
36   int totalsize = basebitmap->xsize * basebitmap->ysize;
37 
38   if ( superbitmap->xsize != basebitmap->xsize ||
39        superbitmap->ysize != basebitmap->ysize )
40     error( 12 );
41 
42   if ( basebitmap->magic != LUGUSED )
43     error( 19 );
44 
45   /* A RGB image ? */
46   if ( basebitmap->depth != 24 )
47     error(7);
48 
49   /*
50    * Chroma modifies the base image, so we
51    * copy ( and save ) it.
52    */
53   copy_bitmap( basebitmap, outbitmap );
54   chroma( outbitmap, superbitmap );
55 
56   /* No errors */
57   return 0;
58 }
59 
chroma(base,super)60 chroma( base, super )
61 bitmap_hdr *base;
62 bitmap_hdr *super;
63 {
64   register int i, j;
65   byte *r1, *g1, *b1;
66   byte *r2, *g2, *b2;
67 
68   /* Set pointers */
69   r1= base->r , g1= base->g , b1= base->b;
70   r2= super->r, g2= super->g, b2= super->b;
71 
72   for ( i = 0; i < super->ysize; i++ ) {
73     for ( j = 0; j < base->xsize; j++ ) {
74       if ( j < super->xsize ) {
75         /* We are into super image */
76         if ( (*r2 + *g2 + *b2) < CHROMABORDER ) {
77           r1++, g1++, b1++;
78           r2++, g2++, b2++;
79         }else {
80           *r1++ = *r2++;
81           *g1++ = *g2++;
82           *b1++ = *b2++;
83         }
84       }else {
85         /* Out of super borders */
86         r1++, g1++, b1++;
87       }
88     }
89   }
90 }
91