| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#include "cc3.h" |
|---|
| 20 |
#include "cc3_ilp.h" |
|---|
| 21 |
#include "cc3_color_track.h" |
|---|
| 22 |
#include <stdbool.h> |
|---|
| 23 |
#include <stdio.h> |
|---|
| 24 |
#include <stdlib.h> |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
uint8_t cc3_track_color (cc3_track_pkt_t * pkt) |
|---|
| 39 |
{ |
|---|
| 40 |
uint16_t y, x; |
|---|
| 41 |
|
|---|
| 42 |
uint8_t *row, *pixel; |
|---|
| 43 |
|
|---|
| 44 |
x = pkt->scratch_x; |
|---|
| 45 |
y = pkt->scratch_y; |
|---|
| 46 |
|
|---|
| 47 |
if ((pkt->lower_bound.channel[0] > pkt->upper_bound.channel[0]) || |
|---|
| 48 |
(pkt->lower_bound.channel[1] > pkt->upper_bound.channel[1]) || |
|---|
| 49 |
(pkt->lower_bound.channel[2] > pkt->upper_bound.channel[2])) |
|---|
| 50 |
return 0; |
|---|
| 51 |
|
|---|
| 52 |
pkt->num_pixels = 0; |
|---|
| 53 |
pkt->x0 = UINT16_MAX; |
|---|
| 54 |
pkt->y0 = UINT16_MAX; |
|---|
| 55 |
pkt->x1 = 0; |
|---|
| 56 |
pkt->y1 = 0; |
|---|
| 57 |
pkt->centroid_x = 0; |
|---|
| 58 |
pkt->centroid_y = 0; |
|---|
| 59 |
|
|---|
| 60 |
pixel = row = cc3_malloc_rows(1); |
|---|
| 61 |
|
|---|
| 62 |
for (y = 0; y < cc3_g_pixbuf_frame.height; y++) { |
|---|
| 63 |
cc3_pixbuf_read_rows(row, 1); |
|---|
| 64 |
|
|---|
| 65 |
for (x = 0; x < cc3_g_pixbuf_frame.width; x++) { |
|---|
| 66 |
bool pixel_good = 0; |
|---|
| 67 |
|
|---|
| 68 |
if (cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL) { |
|---|
| 69 |
if (pixel[0] >= pkt->lower_bound.channel[0] |
|---|
| 70 |
&& pixel[0] <= pkt->upper_bound.channel[0] |
|---|
| 71 |
&& pixel[1] >= pkt->lower_bound.channel[1] |
|---|
| 72 |
&& pixel[1] <= pkt->upper_bound.channel[1] |
|---|
| 73 |
&& pixel[2] >= pkt->lower_bound.channel[2] |
|---|
| 74 |
&& pixel[2] <= pkt->upper_bound.channel[2]) |
|---|
| 75 |
pixel_good = 1; |
|---|
| 76 |
|
|---|
| 77 |
pixel += 3; |
|---|
| 78 |
} |
|---|
| 79 |
else { |
|---|
| 80 |
if (*pixel >= |
|---|
| 81 |
pkt->lower_bound.channel[cc3_g_pixbuf_frame.coi] |
|---|
| 82 |
&& pixel [cc3_g_pixbuf_frame.coi] <= |
|---|
| 83 |
pkt->upper_bound.channel[cc3_g_pixbuf_frame.coi]) |
|---|
| 84 |
pixel_good = 1; |
|---|
| 85 |
|
|---|
| 86 |
pixel++; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
if(pkt->track_invert==1) pixel_good=!pixel_good; |
|---|
| 90 |
if (pixel_good) { |
|---|
| 91 |
pkt->num_pixels++; |
|---|
| 92 |
if (pkt->x0 > x) |
|---|
| 93 |
pkt->x0 = x; |
|---|
| 94 |
if (pkt->y0 > y) |
|---|
| 95 |
pkt->y0 = y; |
|---|
| 96 |
if (pkt->x1 < x) |
|---|
| 97 |
pkt->x1 = x; |
|---|
| 98 |
if (pkt->y1 < y) |
|---|
| 99 |
pkt->y1 = y; |
|---|
| 100 |
pkt->centroid_x += x; |
|---|
| 101 |
pkt->centroid_y += y; |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
pixel=row; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if (pkt->num_pixels > 0) { |
|---|
| 108 |
|
|---|
| 109 |
pkt->int_density = |
|---|
| 110 |
(pkt->num_pixels * 1000) / ((pkt->x1 - pkt->x0) * (pkt->y1 - pkt->y0)); |
|---|
| 111 |
pkt->centroid_x = pkt->centroid_x / pkt->num_pixels; |
|---|
| 112 |
pkt->centroid_y = pkt->centroid_y / pkt->num_pixels; |
|---|
| 113 |
|
|---|
| 114 |
} |
|---|
| 115 |
else { |
|---|
| 116 |
pkt->int_density = 0; |
|---|
| 117 |
pkt->x0 = 0; |
|---|
| 118 |
pkt->y0 = 0; |
|---|
| 119 |
pkt->x1 = 0; |
|---|
| 120 |
pkt->y1 = 0; |
|---|
| 121 |
pkt->centroid_x = 0; |
|---|
| 122 |
pkt->centroid_y = 0; |
|---|
| 123 |
|
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
free(row); |
|---|
| 127 |
|
|---|
| 128 |
return 1; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
uint8_t cc3_track_color_img (cc3_image_t * img, cc3_track_pkt_t * pkt) |
|---|
| 132 |
{ |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
uint8_t cc3_track_color_scanline_start (cc3_track_pkt_t * pkt) |
|---|
| 139 |
{ |
|---|
| 140 |
|
|---|
| 141 |
if ((pkt->lower_bound.channel[0] > pkt->upper_bound.channel[0]) || |
|---|
| 142 |
(pkt->lower_bound.channel[1] > pkt->upper_bound.channel[1]) || |
|---|
| 143 |
(pkt->lower_bound.channel[2] > pkt->upper_bound.channel[2])) |
|---|
| 144 |
return 0; |
|---|
| 145 |
pkt->num_pixels = 0; |
|---|
| 146 |
pkt->x0 = UINT16_MAX; |
|---|
| 147 |
pkt->y0 = UINT16_MAX; |
|---|
| 148 |
pkt->x1 = 0; |
|---|
| 149 |
pkt->y1 = 0; |
|---|
| 150 |
pkt->centroid_x = 0; |
|---|
| 151 |
pkt->centroid_y = 0; |
|---|
| 152 |
pkt->scratch_x = 0; |
|---|
| 153 |
pkt->scratch_y = 0; |
|---|
| 154 |
return 1; |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
uint8_t cc3_track_color_scanline (cc3_image_t * img, cc3_track_pkt_t * pkt) |
|---|
| 158 |
{ |
|---|
| 159 |
uint32_t x, y; |
|---|
| 160 |
uint8_t seq_count; |
|---|
| 161 |
|
|---|
| 162 |
for (x = 0; x < MAX_BINARY_WIDTH; x++) |
|---|
| 163 |
pkt->binary_scanline[x] = 0; |
|---|
| 164 |
|
|---|
| 165 |
for (y = pkt->scratch_y; y < (pkt->scratch_y + img->height); y++) |
|---|
| 166 |
{ |
|---|
| 167 |
seq_count=0; |
|---|
| 168 |
for (x = 0; x < img->width; x++) { |
|---|
| 169 |
bool pixel_good = 0; |
|---|
| 170 |
cc3_pixel_t cp; |
|---|
| 171 |
|
|---|
| 172 |
cc3_get_pixel (img, x, 0, &cp); |
|---|
| 173 |
if (cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL) { |
|---|
| 174 |
if (cp.channel[0] >= pkt->lower_bound.channel[0] && |
|---|
| 175 |
cp.channel[0] <= pkt->upper_bound.channel[0] && |
|---|
| 176 |
cp.channel[1] >= pkt->lower_bound.channel[1] && |
|---|
| 177 |
cp.channel[1] <= pkt->upper_bound.channel[1] && |
|---|
| 178 |
cp.channel[2] >= pkt->lower_bound.channel[2] && |
|---|
| 179 |
cp.channel[2] <= pkt->upper_bound.channel[2]) |
|---|
| 180 |
pixel_good = 1; |
|---|
| 181 |
} |
|---|
| 182 |
else { |
|---|
| 183 |
if (cp.channel[cc3_g_pixbuf_frame.coi] >= |
|---|
| 184 |
pkt->lower_bound.channel[cc3_g_pixbuf_frame.coi] |
|---|
| 185 |
&& cp.channel[cc3_g_pixbuf_frame.coi] <= |
|---|
| 186 |
pkt->upper_bound.channel[cc3_g_pixbuf_frame.coi]) |
|---|
| 187 |
pixel_good = 1; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
if(pkt->track_invert==1) pixel_good=!pixel_good; |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
if(pixel_good) |
|---|
| 198 |
{ |
|---|
| 199 |
if( seq_count<255) seq_count++; |
|---|
| 200 |
} else seq_count=0; |
|---|
| 201 |
|
|---|
| 202 |
if (pixel_good && seq_count>pkt->noise_filter) { |
|---|
| 203 |
uint8_t block, offset; |
|---|
| 204 |
block = x / 8; |
|---|
| 205 |
offset = x % 8; |
|---|
| 206 |
offset = 7 - offset; |
|---|
| 207 |
pkt->binary_scanline[block] |= (1 << offset); |
|---|
| 208 |
pkt->num_pixels++; |
|---|
| 209 |
if (pkt->x0 > x) |
|---|
| 210 |
pkt->x0 = x; |
|---|
| 211 |
if (pkt->y0 > y) |
|---|
| 212 |
pkt->y0 = y; |
|---|
| 213 |
if (pkt->x1 < x) |
|---|
| 214 |
pkt->x1 = x; |
|---|
| 215 |
if (pkt->y1 < y) |
|---|
| 216 |
pkt->y1 = y; |
|---|
| 217 |
pkt->centroid_x += x; |
|---|
| 218 |
pkt->centroid_y += y; |
|---|
| 219 |
} |
|---|
| 220 |
} |
|---|
| 221 |
} |
|---|
| 222 |
pkt->scratch_y = y; |
|---|
| 223 |
|
|---|
| 224 |
return 1; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
uint8_t cc3_track_color_scanline_finish (cc3_track_pkt_t * pkt) |
|---|
| 230 |
{ |
|---|
| 231 |
if (pkt->num_pixels > 0) { |
|---|
| 232 |
|
|---|
| 233 |
pkt->int_density = |
|---|
| 234 |
(pkt->num_pixels * 1000) / ((pkt->x1 - pkt->x0) * (pkt->y1 - pkt->y0)); |
|---|
| 235 |
pkt->centroid_x = pkt->centroid_x / pkt->num_pixels; |
|---|
| 236 |
pkt->centroid_y = pkt->centroid_y / pkt->num_pixels; |
|---|
| 237 |
|
|---|
| 238 |
} |
|---|
| 239 |
else { |
|---|
| 240 |
pkt->int_density = 0; |
|---|
| 241 |
pkt->x0 = 0; |
|---|
| 242 |
pkt->y0 = 0; |
|---|
| 243 |
pkt->x1 = 0; |
|---|
| 244 |
pkt->y1 = 0; |
|---|
| 245 |
pkt->centroid_x = 0; |
|---|
| 246 |
pkt->centroid_y = 0; |
|---|
| 247 |
|
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
} |
|---|