History

avfilter/vf_colorlevels: refactor code so all components are processed in same loop

This is also faster.

Paul B Mahol committed 5 years ago

Commit 4727e301 parent 8983c3d1 file · +59 −41Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_colorlevels.c+59−41
@@ -104,56 +104,74 @@ typedef struct ThreadData { · 103 unmodified lines
104 int omin[4];104 int omin[4];
105} ThreadData;105} ThreadData;
106 106
107#define LOAD_COMMON \107#define DO_COMMON(type, clip) \
108 ColorLevelsContext *s = ctx->priv; \108 ColorLevelsContext *s = ctx->priv; \
109 const ThreadData *td = arg; \109 const ThreadData *td = arg; \
110 const int process_h = td->h; \110 const int linesize = s->linesize; \
111 const int slice_start = (process_h * jobnr ) / nb_jobs; \111 const int step = s->step; \
112 const int slice_end = (process_h * (jobnr+1)) / nb_jobs; \112 const int process_h = td->h; \
113 const uint8_t *srcrow = td->srcrow; \113 const int slice_start = (process_h * jobnr ) / nb_jobs; \
114 uint8_t *dstrow = td->dstrow; \114 const int slice_end = (process_h * (jobnr+1)) / nb_jobs; \
115 const int step = s->step;115 const int src_linesize = td->src_linesize / sizeof(type); \
116 const int dst_linesize = td->dst_linesize / sizeof(type); \
117 const type *srcrow = (const type *)td->srcrow + src_linesize * slice_start; \
118 type *dstrow = (type *)td->dstrow + dst_linesize * slice_start; \
119 const uint8_t offset_r = s->rgba_map[R]; \
120 const uint8_t offset_g = s->rgba_map[G]; \
121 const uint8_t offset_b = s->rgba_map[B]; \
122 const uint8_t offset_a = s->rgba_map[A]; \
123 const int imin_r = td->imin[R]; \
124 const int imin_g = td->imin[G]; \
125 const int imin_b = td->imin[B]; \
126 const int imin_a = td->imin[A]; \
127 const int omin_r = td->omin[R]; \
128 const int omin_g = td->omin[G]; \
129 const int omin_b = td->omin[B]; \
130 const int omin_a = td->omin[A]; \
131 const float coeff_r = td->coeff[R]; \
132 const float coeff_g = td->coeff[G]; \
133 const float coeff_b = td->coeff[B]; \
134 const float coeff_a = td->coeff[A]; \
135 const type *src_r = srcrow + offset_r; \
136 const type *src_g = srcrow + offset_g; \
137 const type *src_b = srcrow + offset_b; \
138 const type *src_a = srcrow + offset_a; \
139 type *dst_r = dstrow + offset_r; \
140 type *dst_g = dstrow + offset_g; \
141 type *dst_b = dstrow + offset_b; \
142 type *dst_a = dstrow + offset_a; \
143 \
144 for (int y = slice_start; y < slice_end; y++) { \
145 for (int x = 0; x < linesize; x += step) { \
146 dst_r[x] = clip((src_r[x] - imin_r) * coeff_r + omin_r); \
147 dst_g[x] = clip((src_g[x] - imin_g) * coeff_g + omin_g); \
148 dst_b[x] = clip((src_b[x] - imin_b) * coeff_b + omin_b); \
149 } \
150 \
151 for (int x = 0; x < linesize && s->nb_comp == 4; x += step) \
152 dst_a[x] = clip((src_a[x] - imin_a) * coeff_a + omin_a); \
153 \
154 src_r += src_linesize; \
155 src_g += src_linesize; \
156 src_b += src_linesize; \
157 src_a += src_linesize; \
158 \
159 dst_r += dst_linesize; \
160 dst_g += dst_linesize; \
161 dst_b += dst_linesize; \
162 dst_a += dst_linesize; \
163 }
116 164
117static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)165static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
118{166{
119 LOAD_COMMON167 DO_COMMON(uint8_t, av_clip_uint8)
120
121 for (int comp = 0; comp < s->nb_comp; comp++) {
122 const uint8_t offset = s->rgba_map[comp];
123 const int imin = td->imin[comp];
124 const int omin = td->omin[comp];
125 const float coeff = td->coeff[comp];
126
127 for (int y = slice_start; y < slice_end; y++) {
128 const uint8_t *src = srcrow + y * td->src_linesize;
129 uint8_t *dst = dstrow + y * td->dst_linesize;
130
131 for (int x = 0; x < s->linesize; x += step)
132 dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * coeff + omin);
133 }
134 }
135 168
136 return 0;169 return 0;
137}170}
138 171
139static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)172static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
140{173{
141 LOAD_COMMON174 DO_COMMON(uint16_t, av_clip_uint16)
142
143 for (int comp = 0; comp < s->nb_comp; comp++) {
144 const uint8_t offset = s->rgba_map[comp];
145 const int imin = td->imin[comp];
146 const int omin = td->omin[comp];
147 const float coeff = td->coeff[comp];
148
149 for (int y = slice_start; y < slice_end; y++) {
150 const uint16_t *src = (const uint16_t *)(srcrow + y * td->src_linesize);
151 uint16_t *dst = (uint16_t *)(dstrow + y * td->dst_linesize);
152
153 for (int x = 0; x < s->linesize; x += step)
154 dst[x + offset] = av_clip_uint16((src[x + offset] - imin) * coeff + omin);
155 }
156 }
157 175
158 return 0;176 return 0;
159}177}

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