| 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_frame_diff.h" |
|---|
| 22 |
#include <stdbool.h> |
|---|
| 23 |
#include <stdio.h> |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
uint8_t cc3_frame_diff_scanline_start(cc3_frame_diff_pkt_t *pkt) |
|---|
| 28 |
{ |
|---|
| 29 |
uint8_t x,y; |
|---|
| 30 |
|
|---|
| 31 |
if(pkt->previous_template==NULL ) return 0; |
|---|
| 32 |
if((pkt->load_frame==0) && pkt->current_template==NULL ) return 0; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
for(y=0; y<pkt->template_height; y++ ) |
|---|
| 36 |
for(x=0; x<pkt->template_width; x++ ) |
|---|
| 37 |
{ |
|---|
| 38 |
if(pkt->load_frame) |
|---|
| 39 |
((uint32_t *)pkt->previous_template)[(y*pkt->template_width)+x]=0; |
|---|
| 40 |
else |
|---|
| 41 |
((uint32_t *)pkt->current_template)[(y*pkt->template_width)+x]=0; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
pkt->_scratch_y=0; |
|---|
| 45 |
pkt->_bin_div_x=(pkt->total_x/pkt->template_width); |
|---|
| 46 |
pkt->_bin_div_y=(pkt->total_y/pkt->template_height); |
|---|
| 47 |
pkt->x0=UINT16_MAX; |
|---|
| 48 |
pkt->y0=UINT16_MAX; |
|---|
| 49 |
pkt->x1=0; |
|---|
| 50 |
pkt->y1=0; |
|---|
| 51 |
pkt->centroid_x=0; |
|---|
| 52 |
pkt->centroid_y=0; |
|---|
| 53 |
pkt->num_pixels=0; |
|---|
| 54 |
pkt->int_density=0; |
|---|
| 55 |
return 1; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
uint8_t cc3_frame_diff_scanline(cc3_image_t *img, cc3_frame_diff_pkt_t *pkt) |
|---|
| 59 |
{ |
|---|
| 60 |
uint32_t x,y; |
|---|
| 61 |
uint16_t t_x,t_y; |
|---|
| 62 |
cc3_pixel_t cp; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
for(y=pkt->_scratch_y; y<(pkt->_scratch_y+img->height); y++ ) |
|---|
| 66 |
{ |
|---|
| 67 |
t_y=y/pkt->_bin_div_y; |
|---|
| 68 |
for(x=0; x<img->width; x++ ) |
|---|
| 69 |
{ |
|---|
| 70 |
uint8_t i; |
|---|
| 71 |
cc3_get_pixel( img, x, y-pkt->_scratch_y, &cp ); |
|---|
| 72 |
t_x=x/pkt->_bin_div_x; |
|---|
| 73 |
|
|---|
| 74 |
if(t_x<pkt->template_width && t_y<pkt->template_height) |
|---|
| 75 |
if(pkt->load_frame) |
|---|
| 76 |
{ |
|---|
| 77 |
((uint32_t *)pkt->previous_template)[(t_y*pkt->template_width)+t_x]+=cp.channel[0]; |
|---|
| 78 |
} else { |
|---|
| 79 |
((uint32_t *)pkt->current_template)[(t_y*pkt->template_width)+t_x]+=cp.channel[0]; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
pkt->_scratch_y=y; |
|---|
| 84 |
|
|---|
| 85 |
return 1; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
uint8_t cc3_frame_diff_scanline_finish(cc3_frame_diff_pkt_t *pkt) |
|---|
| 91 |
{ |
|---|
| 92 |
uint16_t x,y,st,ct; |
|---|
| 93 |
uint32_t cube_size; |
|---|
| 94 |
int32_t dif; |
|---|
| 95 |
|
|---|
| 96 |
cube_size=pkt->_bin_div_x * pkt->_bin_div_y; |
|---|
| 97 |
|
|---|
| 98 |
for(y=0; y<pkt->template_height; y++ ) |
|---|
| 99 |
{ |
|---|
| 100 |
for(x=0; x<pkt->template_width; x++ ) |
|---|
| 101 |
{ |
|---|
| 102 |
if(pkt->load_frame) { |
|---|
| 103 |
((uint32_t *)pkt->previous_template)[(y*pkt->template_width)+x]= |
|---|
| 104 |
((uint32_t *)pkt->previous_template)[(y*pkt->template_width)+x]/cube_size; |
|---|
| 105 |
} else { |
|---|
| 106 |
ct=((uint32_t *)pkt->current_template)[(y*pkt->template_width)+x]= |
|---|
| 107 |
((uint32_t *)pkt->current_template)[(y*pkt->template_width)+x]/cube_size; |
|---|
| 108 |
st= ((uint32_t *)pkt->previous_template)[(y*pkt->template_width)+x]; |
|---|
| 109 |
|
|---|
| 110 |
dif=ct-st; |
|---|
| 111 |
if(dif<0) dif*=-1; |
|---|
| 112 |
if(dif>pkt->threshold) |
|---|
| 113 |
{ |
|---|
| 114 |
if(pkt->x0>x) pkt->x0=x; |
|---|
| 115 |
if(pkt->y0>y) pkt->y0=y; |
|---|
| 116 |
if(pkt->x1<x) pkt->x1=x; |
|---|
| 117 |
if(pkt->y1<y) pkt->y1=y; |
|---|
| 118 |
pkt->centroid_x+=x; |
|---|
| 119 |
pkt->centroid_y+=y; |
|---|
| 120 |
pkt->num_pixels++; |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
if(!pkt->load_frame) |
|---|
| 127 |
{ |
|---|
| 128 |
if (pkt->num_pixels > 0) { |
|---|
| 129 |
|
|---|
| 130 |
pkt->int_density = |
|---|
| 131 |
(pkt->num_pixels * 100) / ((pkt->x1 - pkt->x0) * (pkt->y1 - pkt->y0)); |
|---|
| 132 |
pkt->centroid_x = pkt->centroid_x / pkt->num_pixels; |
|---|
| 133 |
pkt->centroid_y = pkt->centroid_y / pkt->num_pixels; |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
else { |
|---|
| 137 |
pkt->int_density = 0; |
|---|
| 138 |
pkt->x0 = 0; |
|---|
| 139 |
pkt->y0 = 0; |
|---|
| 140 |
pkt->x1 = 0; |
|---|
| 141 |
pkt->y1 = 0; |
|---|
| 142 |
pkt->centroid_x = 0; |
|---|
| 143 |
pkt->centroid_y = 0; |
|---|
| 144 |
|
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
return 1; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|