Skip to content

Commit d959447

Browse files
committed
swscale/graph: move vshift() and shift_img() to shared header
I need to reuse these inside `ops.c`.
1 parent bc9696b commit d959447

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

libswscale/graph.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,14 @@ static int pass_append(SwsGraph *graph, enum AVPixelFormat fmt, int w, int h,
9494
return 0;
9595
}
9696

97-
static int vshift(enum AVPixelFormat fmt, int plane)
98-
{
99-
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
100-
return (plane == 1 || plane == 2) ? desc->log2_chroma_h : 0;
101-
}
102-
103-
/* Shift an image vertically by y lines */
104-
static SwsImg shift_img(const SwsImg *img_base, int y)
105-
{
106-
SwsImg img = *img_base;
107-
for (int i = 0; i < 4 && img.data[i]; i++)
108-
img.data[i] += (y >> vshift(img.fmt, i)) * img.linesize[i];
109-
return img;
110-
}
111-
11297
static void run_copy(const SwsImg *out_base, const SwsImg *in_base,
11398
int y, int h, const SwsPass *pass)
11499
{
115-
SwsImg in = shift_img(in_base, y);
116-
SwsImg out = shift_img(out_base, y);
100+
SwsImg in = ff_sws_img_shift(in_base, y);
101+
SwsImg out = ff_sws_img_shift(out_base, y);
117102

118103
for (int i = 0; i < FF_ARRAY_ELEMS(out.data) && out.data[i]; i++) {
119-
const int lines = h >> vshift(in.fmt, i);
104+
const int lines = h >> ff_fmt_vshift(in.fmt, i);
120105
av_assert1(in.data[i]);
121106

122107
if (in.linesize[i] == out.linesize[i]) {
@@ -219,7 +204,7 @@ static void run_legacy_unscaled(const SwsImg *out, const SwsImg *in_base,
219204
{
220205
SwsContext *sws = slice_ctx(pass, y);
221206
SwsInternal *c = sws_internal(sws);
222-
const SwsImg in = shift_img(in_base, y);
207+
const SwsImg in = ff_sws_img_shift(in_base, y);
223208

224209
c->convert_unscaled(c, (const uint8_t *const *) in.data, in.linesize, y, h,
225210
out->data, out->linesize);
@@ -230,7 +215,7 @@ static void run_legacy_swscale(const SwsImg *out_base, const SwsImg *in,
230215
{
231216
SwsContext *sws = slice_ctx(pass, y);
232217
SwsInternal *c = sws_internal(sws);
233-
const SwsImg out = shift_img(out_base, y);
218+
const SwsImg out = ff_sws_img_shift(out_base, y);
234219

235220
ff_swscale(c, (const uint8_t *const *) in->data, in->linesize, 0,
236221
sws->src_h, out.data, out.linesize, y, h);
@@ -490,8 +475,8 @@ static void run_lut3d(const SwsImg *out_base, const SwsImg *in_base,
490475
int y, int h, const SwsPass *pass)
491476
{
492477
SwsLut3D *lut = pass->priv;
493-
const SwsImg in = shift_img(in_base, y);
494-
const SwsImg out = shift_img(out_base, y);
478+
const SwsImg in = ff_sws_img_shift(in_base, y);
479+
const SwsImg out = ff_sws_img_shift(out_base, y);
495480

496481
ff_sws_lut3d_apply(lut, in.data[0], in.linesize[0], out.data[0],
497482
out.linesize[0], pass->width, h);

libswscale/graph.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ typedef struct SwsImg {
3434
int linesize[4];
3535
} SwsImg;
3636

37+
static av_always_inline av_const int ff_fmt_vshift(enum AVPixelFormat fmt, int plane)
38+
{
39+
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
40+
return (plane == 1 || plane == 2) ? desc->log2_chroma_h : 0;
41+
}
42+
43+
static av_const inline SwsImg ff_sws_img_shift(const SwsImg *base, const int y)
44+
{
45+
SwsImg img = *base;
46+
for (int i = 0; i < 4 && img.data[i]; i++)
47+
img.data[i] += (y >> ff_fmt_vshift(img.fmt, i)) * img.linesize[i];
48+
return img;
49+
}
50+
3751
typedef struct SwsPass SwsPass;
3852
typedef struct SwsGraph SwsGraph;
3953

0 commit comments

Comments
 (0)