| 23 | | x=pkt->scratch_x; |
|---|
| 24 | | y=pkt->scratch_y; |
|---|
| 25 | | |
|---|
| 26 | | if( (pkt->lower_bound.channel[0]>pkt->upper_bound.channel[0]) || |
|---|
| 27 | | (pkt->lower_bound.channel[1]>pkt->upper_bound.channel[1]) || |
|---|
| 28 | | (pkt->lower_bound.channel[2]>pkt->upper_bound.channel[2]) ) return 0; |
|---|
| 29 | | pkt->num_pixels=0; |
|---|
| 30 | | pkt->x0=UINT16_MAX; |
|---|
| 31 | | pkt->y0=UINT16_MAX; |
|---|
| 32 | | pkt->x1=0; |
|---|
| 33 | | pkt->y1=0; |
|---|
| 34 | | pkt->centroid_x=0; |
|---|
| 35 | | pkt->centroid_y=0; |
|---|
| 36 | | |
|---|
| 37 | | |
|---|
| 38 | | for(y=0; y<cc3_g_current_frame.height; y++ ) |
|---|
| 39 | | for(x=0; x<cc3_g_current_frame.width; x++ ) |
|---|
| 40 | | { |
|---|
| 41 | | bool pixel_good=0; |
|---|
| 42 | | cc3_pixbuf_read(); |
|---|
| 43 | | if(cc3_g_current_frame.coi==CC3_ALL ) { |
|---|
| 44 | | if(cc3_g_current_pixel.channel[0]>=pkt->lower_bound.channel[0] && |
|---|
| 45 | | cc3_g_current_pixel.channel[0]<=pkt->upper_bound.channel[0] && |
|---|
| 46 | | cc3_g_current_pixel.channel[1]>=pkt->lower_bound.channel[1] && |
|---|
| 47 | | cc3_g_current_pixel.channel[1]<=pkt->upper_bound.channel[1] && |
|---|
| 48 | | cc3_g_current_pixel.channel[2]>=pkt->lower_bound.channel[2] && |
|---|
| 49 | | cc3_g_current_pixel.channel[2]<=pkt->upper_bound.channel[2] ) pixel_good=1; |
|---|
| 50 | | } else |
|---|
| 51 | | { |
|---|
| 52 | | if(cc3_g_current_pixel.channel[cc3_g_current_frame.coi]>=pkt->lower_bound.channel[cc3_g_current_frame.coi] && |
|---|
| 53 | | cc3_g_current_pixel.channel[cc3_g_current_frame.coi]<=pkt->upper_bound.channel[cc3_g_current_frame.coi] ) pixel_good=1; |
|---|
| 54 | | } |
|---|
| 55 | | |
|---|
| 56 | | if(pixel_good) |
|---|
| 57 | | { |
|---|
| 58 | | pkt->num_pixels++; |
|---|
| 59 | | if(pkt->x0 > x ) pkt->x0=x; |
|---|
| 60 | | if(pkt->y0 > y ) pkt->y0=y; |
|---|
| 61 | | if(pkt->x1 < x ) pkt->x1=x; |
|---|
| 62 | | if(pkt->y1 < y ) pkt->y1=y; |
|---|
| 63 | | pkt->centroid_x+=x; |
|---|
| 64 | | pkt->centroid_y+=y; |
|---|
| 65 | | } |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | |
|---|
| 69 | | if(pkt->num_pixels>0 ) |
|---|
| 70 | | { |
|---|
| 71 | | // FIXME: Density hack to keep it an integer |
|---|
| 72 | | pkt->int_density=(pkt->num_pixels*1000) / ((pkt->x1 - pkt->x0)*(pkt->y1 - pkt->y0)); |
|---|
| 73 | | pkt->centroid_x= pkt->centroid_x / pkt->num_pixels; |
|---|
| 74 | | pkt->centroid_y= pkt->centroid_y / pkt->num_pixels; |
|---|
| 75 | | |
|---|
| | 23 | x = pkt->scratch_x; |
|---|
| | 24 | y = pkt->scratch_y; |
|---|
| | 25 | |
|---|
| | 26 | if ((pkt->lower_bound.channel[0] > pkt->upper_bound.channel[0]) || |
|---|
| | 27 | (pkt->lower_bound.channel[1] > pkt->upper_bound.channel[1]) || |
|---|
| | 28 | (pkt->lower_bound.channel[2] > pkt->upper_bound.channel[2])) |
|---|
| | 29 | return 0; |
|---|
| | 30 | pkt->num_pixels = 0; |
|---|
| | 31 | pkt->x0 = UINT16_MAX; |
|---|
| | 32 | pkt->y0 = UINT16_MAX; |
|---|
| | 33 | pkt->x1 = 0; |
|---|
| | 34 | pkt->y1 = 0; |
|---|
| | 35 | pkt->centroid_x = 0; |
|---|
| | 36 | pkt->centroid_y = 0; |
|---|
| | 37 | |
|---|
| | 38 | |
|---|
| | 39 | for (y = 0; y < cc3_g_current_frame.height; y++) |
|---|
| | 40 | for (x = 0; x < cc3_g_current_frame.width; x++) { |
|---|
| | 41 | bool pixel_good = 0; |
|---|
| | 42 | cc3_pixbuf_read (); |
|---|
| | 43 | if (cc3_g_current_frame.coi == CC3_ALL) { |
|---|
| | 44 | if (cc3_g_current_pixel.channel[0] >= pkt->lower_bound.channel[0] |
|---|
| | 45 | && cc3_g_current_pixel.channel[0] <= pkt->upper_bound.channel[0] |
|---|
| | 46 | && cc3_g_current_pixel.channel[1] >= pkt->lower_bound.channel[1] |
|---|
| | 47 | && cc3_g_current_pixel.channel[1] <= pkt->upper_bound.channel[1] |
|---|
| | 48 | && cc3_g_current_pixel.channel[2] >= pkt->lower_bound.channel[2] |
|---|
| | 49 | && cc3_g_current_pixel.channel[2] <= pkt->upper_bound.channel[2]) |
|---|
| | 50 | pixel_good = 1; |
|---|
| | 51 | } |
|---|
| | 52 | else { |
|---|
| | 53 | if (cc3_g_current_pixel.channel[cc3_g_current_frame.coi] >= |
|---|
| | 54 | pkt->lower_bound.channel[cc3_g_current_frame.coi] |
|---|
| | 55 | && cc3_g_current_pixel.channel[cc3_g_current_frame.coi] <= |
|---|
| | 56 | pkt->upper_bound.channel[cc3_g_current_frame.coi]) |
|---|
| | 57 | pixel_good = 1; |
|---|
| | 58 | } |
|---|
| | 59 | |
|---|
| | 60 | if (pixel_good) { |
|---|
| | 61 | pkt->num_pixels++; |
|---|
| | 62 | if (pkt->x0 > x) |
|---|
| | 63 | pkt->x0 = x; |
|---|
| | 64 | if (pkt->y0 > y) |
|---|
| | 65 | pkt->y0 = y; |
|---|
| | 66 | if (pkt->x1 < x) |
|---|
| | 67 | pkt->x1 = x; |
|---|
| | 68 | if (pkt->y1 < y) |
|---|
| | 69 | pkt->y1 = y; |
|---|
| | 70 | pkt->centroid_x += x; |
|---|
| | 71 | pkt->centroid_y += y; |
|---|
| | 72 | } |
|---|
| 77 | | else |
|---|
| 78 | | { |
|---|
| 79 | | pkt->int_density=0; |
|---|
| 80 | | pkt->x0=0; |
|---|
| 81 | | pkt->y0=0; |
|---|
| 82 | | pkt->x1=0; |
|---|
| 83 | | pkt->y1=0; |
|---|
| 84 | | pkt->centroid_x=0; |
|---|
| 85 | | pkt->centroid_y=0; |
|---|
| 86 | | |
|---|
| | 74 | |
|---|
| | 75 | |
|---|
| | 76 | if (pkt->num_pixels > 0) { |
|---|
| | 77 | // FIXME: Density hack to keep it an integer |
|---|
| | 78 | pkt->int_density = |
|---|
| | 79 | (pkt->num_pixels * 1000) / ((pkt->x1 - pkt->x0) * (pkt->y1 - pkt->y0)); |
|---|
| | 80 | pkt->centroid_x = pkt->centroid_x / pkt->num_pixels; |
|---|
| | 81 | pkt->centroid_y = pkt->centroid_y / pkt->num_pixels; |
|---|
| | 82 | |
|---|
| | 83 | } |
|---|
| | 84 | else { |
|---|
| | 85 | pkt->int_density = 0; |
|---|
| | 86 | pkt->x0 = 0; |
|---|
| | 87 | pkt->y0 = 0; |
|---|
| | 88 | pkt->x1 = 0; |
|---|
| | 89 | pkt->y1 = 0; |
|---|
| | 90 | pkt->centroid_x = 0; |
|---|
| | 91 | pkt->centroid_y = 0; |
|---|
| | 92 | |
|---|
| | 93 | } |
|---|
| | 94 | return 1; |
|---|
| | 95 | } |
|---|
| | 96 | |
|---|
| | 97 | uint8_t cc3_track_color_img (cc3_image_t * img, cc3_track_pkt_t * pkt) |
|---|
| | 98 | { |
|---|
| | 99 | |
|---|
| | 100 | |
|---|
| | 101 | } |
|---|
| | 102 | |
|---|
| | 103 | |
|---|
| | 104 | uint8_t cc3_track_color_scanline_start (cc3_track_pkt_t * pkt) |
|---|
| | 105 | { |
|---|
| | 106 | |
|---|
| | 107 | if ((pkt->lower_bound.channel[0] > pkt->upper_bound.channel[0]) || |
|---|
| | 108 | (pkt->lower_bound.channel[1] > pkt->upper_bound.channel[1]) || |
|---|
| | 109 | (pkt->lower_bound.channel[2] > pkt->upper_bound.channel[2])) |
|---|
| | 110 | return 0; |
|---|
| | 111 | pkt->num_pixels = 0; |
|---|
| | 112 | pkt->x0 = UINT16_MAX; |
|---|
| | 113 | pkt->y0 = UINT16_MAX; |
|---|
| | 114 | pkt->x1 = 0; |
|---|
| | 115 | pkt->y1 = 0; |
|---|
| | 116 | pkt->centroid_x = 0; |
|---|
| | 117 | pkt->centroid_y = 0; |
|---|
| | 118 | pkt->scratch_x = 0; |
|---|
| | 119 | pkt->scratch_y = 0; |
|---|
| | 120 | return 1; |
|---|
| | 121 | } |
|---|
| | 122 | |
|---|
| | 123 | uint8_t cc3_track_color_scanline (cc3_image_t * img, cc3_track_pkt_t * pkt) |
|---|
| | 124 | { |
|---|
| | 125 | uint32_t x, y; |
|---|
| | 126 | |
|---|
| | 127 | for (x = 0; x < MAX_BINARY_WIDTH; x++) |
|---|
| | 128 | pkt->binary_scanline[x] = 0; |
|---|
| | 129 | |
|---|
| | 130 | for (y = pkt->scratch_y; y < (pkt->scratch_y + img->height); y++) |
|---|
| | 131 | for (x = 0; x < img->width; x++) { |
|---|
| | 132 | bool pixel_good = 0; |
|---|
| | 133 | cc3_pixel_t cp; |
|---|
| | 134 | //cc3_pixbuf_read(); |
|---|
| | 135 | cc3_get_pixel (img, x, 0, &cp); |
|---|
| | 136 | if (cc3_g_current_frame.coi == CC3_ALL) { |
|---|
| | 137 | if (cp.channel[0] >= pkt->lower_bound.channel[0] && |
|---|
| | 138 | cp.channel[0] <= pkt->upper_bound.channel[0] && |
|---|
| | 139 | cp.channel[1] >= pkt->lower_bound.channel[1] && |
|---|
| | 140 | cp.channel[1] <= pkt->upper_bound.channel[1] && |
|---|
| | 141 | cp.channel[2] >= pkt->lower_bound.channel[2] && |
|---|
| | 142 | cp.channel[2] <= pkt->upper_bound.channel[2]) |
|---|
| | 143 | pixel_good = 1; |
|---|
| | 144 | } |
|---|
| | 145 | else { |
|---|
| | 146 | if (cp.channel[cc3_g_current_frame.coi] >= |
|---|
| | 147 | pkt->lower_bound.channel[cc3_g_current_frame.coi] |
|---|
| | 148 | && cp.channel[cc3_g_current_frame.coi] <= |
|---|
| | 149 | pkt->upper_bound.channel[cc3_g_current_frame.coi]) |
|---|
| | 150 | pixel_good = 1; |
|---|
| | 151 | } |
|---|
| | 152 | |
|---|
| | 153 | /* pkt->binary_scanline[0]=0x01020304; |
|---|
| | 154 | pkt->binary_scanline[1]=0x05060708; |
|---|
| | 155 | pkt->binary_scanline[2]=0x090A0B0C; |
|---|
| | 156 | pkt->binary_scanline[3]=0x0D0E0F10; |
|---|
| | 157 | pkt->binary_scanline[4]=0x11121314; |
|---|
| | 158 | */ if (pixel_good) { |
|---|
| | 159 | uint8_t block, offset; |
|---|
| | 160 | block = x / 8; |
|---|
| | 161 | offset = x % 8; |
|---|
| | 162 | offset = 7 - offset; |
|---|
| | 163 | pkt->binary_scanline[block] |= (1 << offset); |
|---|
| | 164 | pkt->num_pixels++; |
|---|
| | 165 | if (pkt->x0 > x) |
|---|
| | 166 | pkt->x0 = x; |
|---|
| | 167 | if (pkt->y0 > y) |
|---|
| | 168 | pkt->y0 = y; |
|---|
| | 169 | if (pkt->x1 < x) |
|---|
| | 170 | pkt->x1 = x; |
|---|
| | 171 | if (pkt->y1 < y) |
|---|
| | 172 | pkt->y1 = y; |
|---|
| | 173 | pkt->centroid_x += x; |
|---|
| | 174 | pkt->centroid_y += y; |
|---|
| | 175 | } |
|---|
| 91 | | uint8_t cc3_track_color_img(cc3_image_t *img, cc3_track_pkt_t *pkt) |
|---|
| 92 | | { |
|---|
| 93 | | |
|---|
| 94 | | |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| 97 | | |
|---|
| 98 | | uint8_t cc3_track_color_scanline_start(cc3_track_pkt_t *pkt) |
|---|
| 99 | | { |
|---|
| 100 | | |
|---|
| 101 | | if( (pkt->lower_bound.channel[0]>pkt->upper_bound.channel[0]) || |
|---|
| 102 | | (pkt->lower_bound.channel[1]>pkt->upper_bound.channel[1]) || |
|---|
| 103 | | (pkt->lower_bound.channel[2]>pkt->upper_bound.channel[2]) ) return 0; |
|---|
| 104 | | pkt->num_pixels=0; |
|---|
| 105 | | pkt->x0=UINT16_MAX; |
|---|
| 106 | | pkt->y0=UINT16_MAX; |
|---|
| 107 | | pkt->x1=0; |
|---|
| 108 | | pkt->y1=0; |
|---|
| 109 | | pkt->centroid_x=0; |
|---|
| 110 | | pkt->centroid_y=0; |
|---|
| 111 | | pkt->scratch_x=0; |
|---|
| 112 | | pkt->scratch_y=0; |
|---|
| 113 | | return 1; |
|---|
| 114 | | } |
|---|
| 115 | | |
|---|
| 116 | | uint8_t cc3_track_color_scanline(cc3_image_t *img, cc3_track_pkt_t *pkt) |
|---|
| 117 | | { |
|---|
| 118 | | uint32_t x,y; |
|---|
| 119 | | |
|---|
| 120 | | for(x=0; x<MAX_BINARY_WIDTH; x++ ) pkt->binary_scanline[x]=0; |
|---|
| 121 | | |
|---|
| 122 | | for(y=pkt->scratch_y; y<(pkt->scratch_y+img->height); y++ ) |
|---|
| 123 | | for(x=0; x<img->width; x++ ) |
|---|
| 124 | | { |
|---|
| 125 | | bool pixel_good=0; |
|---|
| 126 | | cc3_pixel_t cp; |
|---|
| 127 | | //cc3_pixbuf_read(); |
|---|
| 128 | | cc3_get_pixel( img, x, 0, &cp ); |
|---|
| 129 | | if(cc3_g_current_frame.coi==CC3_ALL ) { |
|---|
| 130 | | if(cp.channel[0]>=pkt->lower_bound.channel[0] && |
|---|
| 131 | | cp.channel[0]<=pkt->upper_bound.channel[0] && |
|---|
| 132 | | cp.channel[1]>=pkt->lower_bound.channel[1] && |
|---|
| 133 | | cp.channel[1]<=pkt->upper_bound.channel[1] && |
|---|
| 134 | | cp.channel[2]>=pkt->lower_bound.channel[2] && |
|---|
| 135 | | cp.channel[2]<=pkt->upper_bound.channel[2] ) pixel_good=1; |
|---|
| 136 | | } else |
|---|
| 137 | | { |
|---|
| 138 | | if(cp.channel[cc3_g_current_frame.coi]>=pkt->lower_bound.channel[cc3_g_current_frame.coi] && |
|---|
| 139 | | cp.channel[cc3_g_current_frame.coi]<=pkt->upper_bound.channel[cc3_g_current_frame.coi] ) pixel_good=1; |
|---|
| 140 | | } |
|---|
| 141 | | |
|---|
| 142 | | /* pkt->binary_scanline[0]=0x01020304; |
|---|
| 143 | | pkt->binary_scanline[1]=0x05060708; |
|---|
| 144 | | pkt->binary_scanline[2]=0x090A0B0C; |
|---|
| 145 | | pkt->binary_scanline[3]=0x0D0E0F10; |
|---|
| 146 | | pkt->binary_scanline[4]=0x11121314; |
|---|
| 147 | | */ if(pixel_good) |
|---|
| 148 | | { |
|---|
| 149 | | uint8_t block,offset; |
|---|
| 150 | | block=x/8; |
|---|
| 151 | | offset=x%8; |
|---|
| 152 | | offset=7-offset; |
|---|
| 153 | | pkt->binary_scanline[block] |= (1<<offset); |
|---|
| 154 | | pkt->num_pixels++; |
|---|
| 155 | | if(pkt->x0 > x ) pkt->x0=x; |
|---|
| 156 | | if(pkt->y0 > y ) pkt->y0=y; |
|---|
| 157 | | if(pkt->x1 < x ) pkt->x1=x; |
|---|
| 158 | | if(pkt->y1 < y ) pkt->y1=y; |
|---|
| 159 | | pkt->centroid_x+=x; |
|---|
| 160 | | pkt->centroid_y+=y; |
|---|
| 161 | | } |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | pkt->scratch_y=y; |
|---|
| 165 | | |
|---|
| 166 | | return 1; |
|---|
| 167 | | } |
|---|
| 168 | | |
|---|
| 169 | | |
|---|
| 170 | | |
|---|
| 171 | | uint8_t cc3_track_color_scanline_finish(cc3_track_pkt_t *pkt) |
|---|
| 172 | | { |
|---|
| 173 | | if(pkt->num_pixels>0 ) |
|---|
| 174 | | { |
|---|
| 175 | | // FIXME: Density hack to keep it an integer |
|---|
| 176 | | pkt->int_density=(pkt->num_pixels*1000) / ((pkt->x1 - pkt->x0)*(pkt->y1 - pkt->y0)); |
|---|
| 177 | | pkt->centroid_x= pkt->centroid_x / pkt->num_pixels; |
|---|
| 178 | | pkt->centroid_y= pkt->centroid_y / pkt->num_pixels; |
|---|
| 179 | | |
|---|
| 180 | | } |
|---|
| 181 | | else |
|---|
| 182 | | { |
|---|
| 183 | | pkt->int_density=0; |
|---|
| 184 | | pkt->x0=0; |
|---|
| 185 | | pkt->y0=0; |
|---|
| 186 | | pkt->x1=0; |
|---|
| 187 | | pkt->y1=0; |
|---|
| 188 | | pkt->centroid_x=0; |
|---|
| 189 | | pkt->centroid_y=0; |
|---|
| 190 | | |
|---|
| 191 | | } |
|---|
| 192 | | |
|---|
| 193 | | |
|---|
| 194 | | } |
|---|
| 195 | | |
|---|
| 196 | | |
|---|
| 197 | | |
|---|
| | 183 | |
|---|
| | 184 | |
|---|
| | 185 | uint8_t cc3_track_color_scanline_finish (cc3_track_pkt_t * pkt) |
|---|
| | 186 | { |
|---|
| | 187 | if (pkt->num_pixels > 0) { |
|---|
| | 188 | // FIXME: Density hack to keep it an integer |
|---|
| | 189 | pkt->int_density = |
|---|
| | 190 | (pkt->num_pixels * 1000) / ((pkt->x1 - pkt->x0) * (pkt->y1 - pkt->y0)); |
|---|
| | 191 | pkt->centroid_x = pkt->centroid_x / pkt->num_pixels; |
|---|
| | 192 | pkt->centroid_y = pkt->centroid_y / pkt->num_pixels; |
|---|
| | 193 | |
|---|
| | 194 | } |
|---|
| | 195 | else { |
|---|
| | 196 | pkt->int_density = 0; |
|---|
| | 197 | pkt->x0 = 0; |
|---|
| | 198 | pkt->y0 = 0; |
|---|
| | 199 | pkt->x1 = 0; |
|---|
| | 200 | pkt->y1 = 0; |
|---|
| | 201 | pkt->centroid_x = 0; |
|---|
| | 202 | pkt->centroid_y = 0; |
|---|
| | 203 | |
|---|
| | 204 | } |
|---|
| | 205 | |
|---|
| | 206 | |
|---|
| | 207 | } |
|---|