Adding and reusing vpx_img_plane_{width, height}() functions.

Change-Id: I668afb50614644d2eac2e968e1fafd6d73170bec
This commit is contained in:
Dmitry Kovalev 2014-02-12 18:36:36 -08:00
parent 02c063797b
commit 2bdd43d8d4
3 changed files with 28 additions and 24 deletions

View File

@ -220,14 +220,31 @@ const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc) {
return NULL;
}
// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
// of vpx_image_t support
int vpx_img_plane_width(const vpx_image_t *img, int plane) {
if (plane > 0 && img->x_chroma_shift > 0)
return (img->d_w + 1) >> img->x_chroma_shift;
else
return img->d_w;
}
int vpx_img_plane_height(const vpx_image_t *img, int plane) {
if (plane > 0 && img->y_chroma_shift > 0)
return (img->d_h + 1) >> img->y_chroma_shift;
else
return img->d_h;
}
void vpx_img_write(const vpx_image_t *img, FILE *file) {
int plane, y;
int plane;
for (plane = 0; plane < 3; ++plane) {
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
const int w = plane ? (img->d_w + 1) >> 1 : img->d_w;
const int h = plane ? (img->d_h + 1) >> 1 : img->d_h;
const int w = vpx_img_plane_width(img, plane);
const int h = vpx_img_plane_height(img, plane);
int y;
for (y = 0; y < h; ++y) {
fwrite(buf, 1, w, file);
@ -242,8 +259,8 @@ int vpx_img_read(vpx_image_t *img, FILE *file) {
for (plane = 0; plane < 3; ++plane) {
unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
const int w = plane ? (img->d_w + 1) >> 1 : img->d_w;
const int h = plane ? (img->d_h + 1) >> 1 : img->d_h;
const int w = vpx_img_plane_width(img, plane);
const int h = vpx_img_plane_height(img, plane);
int y;
for (y = 0; y < h; ++y) {

View File

@ -140,10 +140,9 @@ const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc);
// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
// of vpx_image_t support
int vpx_img_plane_width(const vpx_image_t *img, int plane);
int vpx_img_plane_height(const vpx_image_t *img, int plane);
void vpx_img_write(const vpx_image_t *img, FILE *file);
// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
// of vpx_image_t support
int vpx_img_read(vpx_image_t *img, FILE *file);
#ifdef __cplusplus

View File

@ -229,18 +229,6 @@ static int read_frame(struct VpxDecInputContext *input, uint8_t **buf,
}
}
static int get_image_plane_width(int plane, const vpx_image_t *img) {
return (plane > 0 && img->x_chroma_shift > 0) ?
(img->d_w + 1) >> img->x_chroma_shift :
img->d_w;
}
static int get_image_plane_height(int plane, const vpx_image_t *img) {
return (plane > 0 && img->y_chroma_shift > 0) ?
(img->d_h + 1) >> img->y_chroma_shift :
img->d_h;
}
static void update_image_md5(const vpx_image_t *img, const int planes[3],
MD5Context *md5) {
int i, y;
@ -249,8 +237,8 @@ static void update_image_md5(const vpx_image_t *img, const int planes[3],
const int plane = planes[i];
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
const int w = get_image_plane_width(plane, img);
const int h = get_image_plane_height(plane, img);
const int w = vpx_img_plane_width(img, plane);
const int h = vpx_img_plane_height(img, plane);
for (y = 0; y < h; ++y) {
MD5Update(md5, buf, w);
@ -267,8 +255,8 @@ static void write_image_file(const vpx_image_t *img, const int planes[3],
const int plane = planes[i];
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
const int w = get_image_plane_width(plane, img);
const int h = get_image_plane_height(plane, img);
const int w = vpx_img_plane_width(img, plane);
const int h = vpx_img_plane_height(img, plane);
for (y = 0; y < h; ++y) {
fwrite(buf, 1, w, file);