Mercurial > libavcore.hg
comparison imgutils.c @ 16:1a1faa090ff1 libavcore
Implement inline function av_fill_image_max_pixstep() and use it for
factorizing code.
author | stefano |
---|---|
date | Wed, 18 Aug 2010 21:02:38 +0000 |
parents | 665cb0c97133 |
children | ebe3b7ce4cca |
comparison
equal
deleted
inserted
replaced
15:665cb0c97133 | 16:1a1faa090ff1 |
---|---|
27 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) | 27 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) |
28 { | 28 { |
29 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; | 29 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; |
30 int max_step [4]; /* max pixel step for each plane */ | 30 int max_step [4]; /* max pixel step for each plane */ |
31 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ | 31 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ |
32 int s, i; | 32 int s; |
33 | 33 |
34 if (desc->flags & PIX_FMT_BITSTREAM) | 34 if (desc->flags & PIX_FMT_BITSTREAM) |
35 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; | 35 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; |
36 | 36 |
37 memset(max_step , 0, sizeof(max_step )); | 37 av_fill_image_max_pixstep(max_step, max_step_comp, desc); |
38 memset(max_step_comp, 0, sizeof(max_step_comp)); | |
39 for (i = 0; i < 4; i++) { | |
40 const AVComponentDescriptor *comp = &(desc->comp[i]); | |
41 if ((comp->step_minus1+1) > max_step[comp->plane]) { | |
42 max_step [comp->plane] = comp->step_minus1+1; | |
43 max_step_comp[comp->plane] = i; | |
44 } | |
45 } | |
46 | |
47 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; | 38 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; |
48 return max_step[plane] * (((width + (1 << s) - 1)) >> s); | 39 return max_step[plane] * (((width + (1 << s) - 1)) >> s); |
49 } | 40 } |
50 | 41 |
51 int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) | 42 int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) |
63 if (desc->flags & PIX_FMT_BITSTREAM) { | 54 if (desc->flags & PIX_FMT_BITSTREAM) { |
64 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; | 55 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; |
65 return 0; | 56 return 0; |
66 } | 57 } |
67 | 58 |
68 memset(max_step , 0, sizeof(max_step )); | 59 av_fill_image_max_pixstep(max_step, max_step_comp, desc); |
69 memset(max_step_comp, 0, sizeof(max_step_comp)); | |
70 for (i = 0; i < 4; i++) { | |
71 const AVComponentDescriptor *comp = &(desc->comp[i]); | |
72 if ((comp->step_minus1+1) > max_step[comp->plane]) { | |
73 max_step [comp->plane] = comp->step_minus1+1; | |
74 max_step_comp[comp->plane] = i; | |
75 } | |
76 } | |
77 | |
78 for (i = 0; i < 4; i++) { | 60 for (i = 0; i < 4; i++) { |
79 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0; | 61 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); | 62 linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s); |
81 } | 63 } |
82 | 64 |