root/trunk/lib/cc3-ilp/cc3_color_info.c

Revision 399, 2.1 kB (checked in by goodea, 2 years ago)

enum update

  • Property svn:eol-style set to native
Line 
1 /*
2  * Copyright 2006  Anthony Rowe and Adam Goode
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 #include "cc3.h"
20 #include "cc3_ilp.h"
21 #include "cc3_color_info.h"
22 #include <stdbool.h>
23 #include <stdio.h>
24
25
26
27 uint8_t cc3_color_info_scanline_start(cc3_color_info_pkt_t *pkt)
28 {
29 uint8_t i;
30
31 for(i=0; i<3; i++ )
32 {
33  pkt->mean.channel[i]=0;
34  pkt->scratch_mean[i]=0;
35  pkt->deviation.channel[i]=0;
36  pkt->min.channel[i]=255;
37  pkt->max.channel[i]=0;
38 }
39 pkt->scratch_x=0;
40 pkt->scratch_y=0;
41 pkt->scratch_pix=0;
42
43 return 1;
44 }
45
46 uint8_t cc3_color_info_scanline(cc3_image_t *img, cc3_color_info_pkt_t *pkt)
47 {
48 uint32_t x,y;
49
50
51 for(y=pkt->scratch_y; y<(pkt->scratch_y+img->height); y++ )
52 for(x=0; x<img->width; x++ )
53 {
54         cc3_pixel_t cp;
55         cc3_get_pixel( img, x, 0, &cp );       
56         pkt->scratch_pix++;
57         if(cc3_g_pixbuf_frame.coi==CC3_CHANNEL_ALL ) { 
58                 uint8_t i;
59                 for(i=0; i<3; i++ )
60                 {
61                 pkt->scratch_mean[i]+=cp.channel[i];
62                 if(cp.channel[i]<pkt->min.channel[i]) pkt->min.channel[i]=cp.channel[i];       
63                 if(cp.channel[i]>pkt->max.channel[i]) pkt->max.channel[i]=cp.channel[i];
64                 }       
65        
66         } else
67         {
68             uint8_t i;
69                 i=cc3_g_pixbuf_frame.coi;
70                 pkt->scratch_mean[i]+=cp.channel[i];
71                 if(cp.channel[i]<pkt->min.channel[i]) pkt->min.channel[i]=cp.channel[i];       
72                 if(cp.channel[i]>pkt->max.channel[i]) pkt->max.channel[i]=cp.channel[i];
73         }
74
75 }
76
77 pkt->scratch_y=y;
78
79 return 1;
80 }
81
82
83
84 uint8_t cc3_color_info_scanline_finish(cc3_color_info_pkt_t *pkt)
85 {
86 uint8_t i;
87 for(i=0; i<3; i++ )
88 {
89         pkt->mean.channel[i]=pkt->scratch_mean[i]/pkt->scratch_pix;
90         pkt->deviation.channel[i]=((pkt->max.channel[i]-pkt->mean.channel[i])+
91                 (pkt->mean.channel[i]-pkt->min.channel[i]))/2;
92 }
93
94 return 1;
95 }
96
97
98
Note: See TracBrowser for help on using the browser.