comparison imgutils.c @ 22:0899fc09d43c libavcore

Adopt a hierarchical name scheme for the imgutils.h API. Simplify grepping and somewhat more consistent with the scheme adopted by other FFmpeg modules API.
author stefano
date Tue, 07 Sep 2010 19:15:17 +0000
parents 3b8eec1cfdaa
children 478992775cf8
comparison
equal deleted inserted replaced
21:3b8eec1cfdaa 22:0899fc09d43c
22 */ 22 */
23 23
24 #include "imgutils.h" 24 #include "imgutils.h"
25 #include "libavutil/pixdesc.h" 25 #include "libavutil/pixdesc.h"
26 26
27 void av_fill_image_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], 27 void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
28 const AVPixFmtDescriptor *pixdesc) 28 const AVPixFmtDescriptor *pixdesc)
29 { 29 {
30 int i; 30 int i;
31 memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0])); 31 memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0]));
32 if (max_pixstep_comps) 32 if (max_pixstep_comps)
40 max_pixstep_comps[comp->plane] = i; 40 max_pixstep_comps[comp->plane] = i;
41 } 41 }
42 } 42 }
43 } 43 }
44 44
45 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) 45 int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane)
46 { 46 {
47 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; 47 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
48 int max_step [4]; /* max pixel step for each plane */ 48 int max_step [4]; /* max pixel step for each plane */
49 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ 49 int max_step_comp[4]; /* the component for each plane which has the max pixel step */
50 int s; 50 int s;
51 51
52 if (desc->flags & PIX_FMT_BITSTREAM) 52 if (desc->flags & PIX_FMT_BITSTREAM)
53 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; 53 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
54 54
55 av_fill_image_max_pixsteps(max_step, max_step_comp, desc); 55 av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
56 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; 56 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0;
57 return max_step[plane] * (((width + (1 << s) - 1)) >> s); 57 return max_step[plane] * (((width + (1 << s) - 1)) >> s);
58 } 58 }
59 59
60 int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) 60 int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width)
61 { 61 {
62 int i; 62 int i;
63 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; 63 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
64 int max_step [4]; /* max pixel step for each plane */ 64 int max_step [4]; /* max pixel step for each plane */
65 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ 65 int max_step_comp[4]; /* the component for each plane which has the max pixel step */
72 if (desc->flags & PIX_FMT_BITSTREAM) { 72 if (desc->flags & PIX_FMT_BITSTREAM) {
73 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; 73 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
74 return 0; 74 return 0;
75 } 75 }
76 76
77 av_fill_image_max_pixsteps(max_step, max_step_comp, desc); 77 av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
78 for (i = 0; i < 4; i++) { 78 for (i = 0; i < 4; i++) {
79 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0; 79 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0;
80 linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s); 80 linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s);
81 } 81 }
82 82
83 return 0; 83 return 0;
84 } 84 }
85 85
86 int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, 86 int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height,
87 uint8_t *ptr, const int linesizes[4]) 87 uint8_t *ptr, const int linesizes[4])
88 { 88 {
89 int i, total_size, size[4], has_plane[4]; 89 int i, total_size, size[4], has_plane[4];
90 90
91 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; 91 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
126 void *log_ctx; 126 void *log_ctx;
127 } ImgUtils; 127 } ImgUtils;
128 128
129 static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) }; 129 static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) };
130 130
131 int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) 131 int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
132 { 132 {
133 ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; 133 ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx };
134 134
135 if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) 135 if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
136 return 0; 136 return 0;
137 137
138 av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h); 138 av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h);
139 return AVERROR(EINVAL); 139 return AVERROR(EINVAL);
140 } 140 }
141
142 #if FF_API_OLD_IMAGE_NAMES
143 void av_fill_image_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
144 const AVPixFmtDescriptor *pixdesc)
145 {
146 av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps, pixdesc);
147 }
148
149 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane)
150 {
151 return av_image_get_linesize(pix_fmt, width, plane);
152 }
153
154 int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width)
155 {
156 return av_image_fill_linesizes(linesizes, pix_fmt, width);
157 }
158
159 int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height,
160 uint8_t *ptr, const int linesizes[4])
161 {
162 return av_image_fill_pointers(data, pix_fmt, height, ptr, linesizes);
163 }
164
165 int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
166 {
167 return av_image_check_size(w, h, log_offset, log_ctx);
168 }
169 #endif