Move basic SAD functions to picture-module.

This commit is contained in:
Ari Koivula 2013-10-10 18:51:10 +03:00
parent 0e078b2d18
commit 4e36992752
3 changed files with 59 additions and 52 deletions

View file

@ -559,6 +559,52 @@ uint32_t sad4x4(int16_t *block1, uint32_t stride1,
return sum; return sum;
} }
unsigned cor_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned char ref = *ref_data;
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref);
}
}
return sad;
}
unsigned ver_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref_data[x]);
}
}
return sad;
}
unsigned hor_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref_data[y * width]);
}
}
return sad;
}
/** /**
* \brief Calculate Sum of Absolute Differences (SAD) * \brief Calculate Sum of Absolute Differences (SAD)
* *
@ -573,7 +619,7 @@ uint32_t sad4x4(int16_t *block1, uint32_t stride1,
* *
* \returns Sum of Absolute Differences * \returns Sum of Absolute Differences
*/ */
uint32_t sad(uint8_t *data1, uint8_t *data2, uint32_t reg_sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride) unsigned width, unsigned height, unsigned stride)
{ {
unsigned y, x; unsigned y, x;

View file

@ -120,8 +120,15 @@ uint32_t sad8x8(int16_t *block1, uint32_t stride1,
int16_t* block2, uint32_t stride2); int16_t* block2, uint32_t stride2);
uint32_t sad4x4(int16_t *block1, uint32_t stride1, uint32_t sad4x4(int16_t *block1, uint32_t stride1,
int16_t* block2, uint32_t stride2); int16_t* block2, uint32_t stride2);
uint32_t sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride); uint32_t cor_sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride);
uint32_t ver_sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride);
uint32_t hor_sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride);
uint32_t reg_sad(uint8_t *data1, uint8_t *data2,
unsigned width, unsigned height, unsigned stride);
double image_psnr(uint8_t *frame1, uint8_t *frame2, int32_t x, int32_t y); double image_psnr(uint8_t *frame1, uint8_t *frame2, int32_t x, int32_t y);

View file

@ -36,52 +36,6 @@
&& (x) + (block_width) <= (width) \ && (x) + (block_width) <= (width) \
&& (y) + (block_height) <= (height)) && (y) + (block_height) <= (height))
unsigned cor_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned char ref = *ref_data;
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref);
}
}
return sad;
}
unsigned ver_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref_data[x]);
}
}
return sad;
}
unsigned hor_sad(unsigned char* pic_data, unsigned char* ref_data,
unsigned block_width, unsigned block_height, unsigned width)
{
unsigned x, y;
unsigned sad = 0;
for (y = 0; y < block_height; ++y) {
for (x = 0; x < block_width; ++x) {
sad += abs(pic_data[y * width + x] - ref_data[y * width]);
}
}
return sad;
}
/** /**
* \brief Get Sum of Absolute Differences (SAD) between two blocks in two * \brief Get Sum of Absolute Differences (SAD) between two blocks in two
* different frames. * different frames.
@ -149,7 +103,7 @@ unsigned get_block_sad(picture *pic, picture *ref,
} else if (bottom) { } else if (bottom) {
} else { } else {
result += sad(pic_data, ref_data, block_width, block_height, width); result += reg_sad(pic_data, ref_data, block_width, block_height, width);
} }
return result; return result;
@ -406,8 +360,8 @@ void search_mv_full(picture *pic, uint8_t *pic_data, uint8_t *ref_data,
if (orig_x + x < 0 || orig_y + y < 0 || orig_x + x > pic->width - block_width if (orig_x + x < 0 || orig_y + y < 0 || orig_x + x > pic->width - block_width
|| orig_y + y > pic->height - block_height) return; || orig_y + y > pic->height - block_height) return;
cost = sad(pic_data, &ref_data[(orig_y + y) * pic->width + (orig_x + x)], cost = reg_sad(pic_data, &ref_data[(orig_y + y) * pic->width + (orig_x + x)],
block_width, block_height, pic->width) + 1; block_width, block_height, pic->width) + 1;
if (cost < cur_cu->inter.cost) { if (cost < cur_cu->inter.cost) {
cur_cu->inter.cost = cost; cur_cu->inter.cost = cost;
cur_cu->inter.mv[0] = x << 2; cur_cu->inter.mv[0] = x << 2;