History

Implement inline function av_fill_image_max_pixstep() and use it for factorizing code.

Originally committed as revision 24827 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini committed 16 years ago

Commit a6ddf8b1 parent 25ae7985 files · +43 −40Browse files

Unified · Split

5 files
  1. libavcore/avcore.h +1 −1
  2. libavcore/imgutils.c +3 −21
  3. libavcore/imgutils.h +35 −1
  4. libavfilter/vf_crop.c +2 −9
  5. libavfilter/vf_hflip.c +2 −8
libavcore/avcore.h+1−1
@@ -27,7 +27,7 @@ · 26 unmodified lines
2727 #include <libavutil/avutil.h>
2828
2929 #define LIBAVCORE_VERSION_MAJOR 0
30−#define LIBAVCORE_VERSION_MINOR 4
30+#define LIBAVCORE_VERSION_MINOR 5
3131 #define LIBAVCORE_VERSION_MICRO 0
3232
3333 #define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \
libavcore/imgutils.c+3−21
@@ -29,21 +29,12 @@ int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) · 28 unmodified lines
2929 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
3030 int max_step [4]; /* max pixel step for each plane */
3131 int max_step_comp[4]; /* the component for each plane which has the max pixel step */
32− int s, i;
32+ int s;
3333
3434 if (desc->flags & PIX_FMT_BITSTREAM)
3535 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
3636
37− memset(max_step , 0, sizeof(max_step ));
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−
37+ av_fill_image_max_pixstep(max_step, max_step_comp, desc);
4738 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0;
4839 return max_step[plane] * (((width + (1 << s) - 1)) >> s);
4940 }
@@ -65,16 +56,7 @@ int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt · 15 unmodified lines
6556 return 0;
6657 }
6758
68− memset(max_step , 0, sizeof(max_step ));
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−
59+ av_fill_image_max_pixstep(max_step, max_step_comp, desc);
7860 for (i = 0; i < 4; i++) {
7961 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0;
8062 linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s);
libavcore/imgutils.h+35−1
@@ -24,9 +24,43 @@ · 23 unmodified lines
2424 * misc image utilities
2525 */
2626
27−#include "libavutil/pixfmt.h"
27+#include "libavutil/pixdesc.h"
2828 #include "avcore.h"
2929
30+/**
31+ * Compute the max pixel step for each plane of an image with a
32+ * format described by pixdesc
33+ *
34+ * The pixel step is the distance in bytes between the first byte of
35+ * the group of bytes which describe a pixel component and the first
36+ * byte of the successive group in the same plane for the same
37+ * component.
38+ *
39+ * @param max_pixstep an array which is filled with the max pixel step
40+ * for each plane. Since a plane may contain different pixel
41+ * components, the computed max_pixstep[plane] is relative to the
42+ * component in the plane with the max pixel step.
43+ * @param max_pixstep_comp an array which is filled with the component
44+ * for each plane which has the max pixel step. May be NULL.
45+ */
46+static inline void av_fill_image_max_pixstep(int max_pixstep[4], int max_pixstep_comp[4],
47+ const AVPixFmtDescriptor *pixdesc)
48+{
49+ int i;
50+ memset(max_pixstep, 0, 4*sizeof(max_pixstep[0]));
51+ if (max_pixstep_comp)
52+ memset(max_pixstep_comp, 0, 4*sizeof(max_pixstep_comp[0]));
53+
54+ for (i = 0; i < 4; i++) {
55+ const AVComponentDescriptor *comp = &(pixdesc->comp[i]);
56+ if ((comp->step_minus1+1) > max_pixstep[comp->plane]) {
57+ max_pixstep[comp->plane] = comp->step_minus1+1;
58+ if (max_pixstep_comp)
59+ max_pixstep_comp[comp->plane] = i;
60+ }
61+ }
62+}
63+
3064 /**
3165 * Compute the size of an image line with format pix_fmt and width
3266 * width for the plane plane.
libavfilter/vf_crop.c+2−9
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424 */
2525
2626 #include "avfilter.h"
27−#include "libavutil/pixdesc.h"
27+#include "libavcore/imgutils.h"
2828
2929 typedef struct {
3030 int x; ///< x offset of the non-cropped area with respect to the input area
@@ -83,15 +83,8 @@ static int config_input(AVFilterLink *link) · 52 unmodified lines
8383 AVFilterContext *ctx = link->dst;
8484 CropContext *crop = ctx->priv;
8585 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format];
86− int i;
87−
88− memset(crop->max_step, 0, sizeof(crop->max_step));
89− for (i = 0; i < 4; i++) {
90− const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
91− if ((comp->step_minus1+1) > crop->max_step[comp->plane])
92− crop->max_step[comp->plane] = comp->step_minus1+1;
93− }
9486
87+ av_fill_image_max_pixstep(crop->max_step, NULL, pix_desc);
9588 crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
9689 crop->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
9790
libavfilter/vf_hflip.c+2−8
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 #include "avfilter.h"
2828 #include "libavutil/pixdesc.h"
2929 #include "libavutil/intreadwrite.h"
30+#include "libavcore/imgutils.h"
3031
3132 typedef struct {
3233 int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
@@ -68,15 +69,8 @@ static int config_props(AVFilterLink *inlink) · 35 unmodified lines
6869 {
6970 FlipContext *flip = inlink->dst->priv;
7071 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
71− int i;
72−
73− memset(flip->max_step, 0, sizeof(flip->max_step));
74− for (i = 0; i < 4; i++) {
75− const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
76− if ((comp->step_minus1+1) > flip->max_step[comp->plane])
77− flip->max_step[comp->plane] = comp->step_minus1+1;
78− }
7972
73+ av_fill_image_max_pixstep(flip->max_step, NULL, pix_desc);
8074 flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
8175 flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
8276

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t