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
27#include <libavutil/avutil.h>27#include <libavutil/avutil.h>
28 28
29#define LIBAVCORE_VERSION_MAJOR 029#define LIBAVCORE_VERSION_MAJOR 0
30#define LIBAVCORE_VERSION_MINOR 430#define LIBAVCORE_VERSION_MINOR 5
31#define LIBAVCORE_VERSION_MICRO 031#define LIBAVCORE_VERSION_MICRO 0
32 32
33#define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \33#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
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}
@@ -65,16 +56,7 @@ int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt · 15 unmodified lines
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);
libavcore/imgutils.h+35−1
@@ -24,9 +24,43 @@ · 23 unmodified lines
24 * misc image utilities24 * misc image utilities
25 */25 */
26 26
27#include "libavutil/pixfmt.h"27#include "libavutil/pixdesc.h"
28#include "avcore.h"28#include "avcore.h"
29 29
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 */
46static 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
30/**64/**
31 * Compute the size of an image line with format pix_fmt and width65 * Compute the size of an image line with format pix_fmt and width
32 * width for the plane plane.66 * width for the plane plane.
libavfilter/vf_crop.c+2−9
@@ -24,7 +24,7 @@ · 23 unmodified lines
24 */24 */
25 25
26#include "avfilter.h"26#include "avfilter.h"
27#include "libavutil/pixdesc.h"27#include "libavcore/imgutils.h"
28 28
29typedef struct {29typedef struct {
30 int x; ///< x offset of the non-cropped area with respect to the input area30 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
83 AVFilterContext *ctx = link->dst;83 AVFilterContext *ctx = link->dst;
84 CropContext *crop = ctx->priv;84 CropContext *crop = ctx->priv;
85 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format];85 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 }
94 86
87 av_fill_image_max_pixstep(crop->max_step, NULL, pix_desc);
95 crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;88 crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
96 crop->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;89 crop->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
97 90
libavfilter/vf_hflip.c+2−8
@@ -27,6 +27,7 @@ · 26 unmodified lines
27#include "avfilter.h"27#include "avfilter.h"
28#include "libavutil/pixdesc.h"28#include "libavutil/pixdesc.h"
29#include "libavutil/intreadwrite.h"29#include "libavutil/intreadwrite.h"
30#include "libavcore/imgutils.h"
30 31
31typedef struct {32typedef struct {
32 int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes33 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
68{69{
69 FlipContext *flip = inlink->dst->priv;70 FlipContext *flip = inlink->dst->priv;
70 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];71 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 }
79 72
73 av_fill_image_max_pixstep(flip->max_step, NULL, pix_desc);
80 flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;74 flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
81 flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;75 flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
82 76

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