History

avfilter/vf_lenscorrection: get rid of all floats per frame

there are some still left for 1 time initialization

Michael Niedermayer committed 12 years ago

Commit 2450ca01 parent c1b663b1 file · +32 −13Browse files

Unified · Split

libavfilter/vf_lenscorrection.c+32−13
@@ -41,6 +41,7 @@ typedef struct LenscorrectionCtx { · 40 unmodified lines
4141 int hsub, vsub;
4242 int nb_planes;
4343 double cx, cy, k1, k2;
44+ int32_t *correction[4];
4445 } LenscorrectionCtx;
4546
4647 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
@@ -59,7 +60,7 @@ typedef struct ThreadData { · 12 unmodified lines
5960 int w, h;
6061 int plane;
6162 int xcenter, ycenter;
62− float k1, k2;
63+ int32_t *correction;
6364 } ThreadData;
6465
6566 static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
@@ -71,9 +72,6 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) · 5 unmodified lines
7172 const int w = td->w, h = td->h;
7273 const int xcenter = td->xcenter;
7374 const int ycenter = td->ycenter;
74− const float r2inv = 4.0 / (w * w + h * h);
75− const float k1 = td->k1;
76− const float k2 = td->k2;
7775 const int start = (h * job ) / nb_jobs;
7876 const int end = (h * (job+1)) / nb_jobs;
7977 const int plane = td->plane;
@@ -84,15 +82,13 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) · 4 unmodified lines
8482 int i;
8583 for (i = start; i < end; i++, outrow += outlinesize) {
8684 const int off_y = i - ycenter;
87− const int off_y2 = off_y * off_y;
8885 uint8_t *out = outrow;
8986 int j;
9087 for (j = 0; j < w; j++) {
9188 const int off_x = j - xcenter;
92− const float r2 = (off_x * off_x + off_y2) * r2inv;
93− const float radius_mult = 1.0f + r2 * k1 + r2 * r2 * k2;
94− const int x = xcenter + radius_mult * off_x + 0.5f;
95− const int y = ycenter + radius_mult * off_y + 0.5f;
89+ const int64_t radius_mult = td->correction[j + i*w];
90+ const int x = xcenter + ((radius_mult * off_x + (1<<23))>>24);
91+ const int y = ycenter + ((radius_mult * off_y + (1<<23))>>24);
9692 const char isvalid = x > 0 && x < w - 1 && y > 0 && y < h - 1;
9793 *out++ = isvalid ? indata[y * inlinesize + x] : 0;
9894 }
@@ -151,16 +147,39 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 52 unmodified lines
151147 int vdiv = 1 << vsub;
152148 int w = rect->width / hdiv;
153149 int h = rect->height / vdiv;
150+ int xcenter = rect->cx * w;
151+ int ycenter = rect->cy * h;
152+ float k1 = rect->k1;
153+ float k2 = rect->k2;
154154 ThreadData td = {
155155 .in = in,
156156 .out = out,
157157 .w = w,
158158 .h = h,
159− .xcenter = rect->cx * w,
160− .ycenter = rect->cy * h,
161− .k1 = rect->k1,
162− .k2 = rect->k2,
159+ .xcenter = xcenter,
160+ .ycenter = ycenter,
163161 .plane = plane};
162+
163+ if (!rect->correction[plane]) {
164+ int i,j;
165+ const float r2inv = 4.0 / (w * w + h * h);
166+
167+ rect->correction[plane] = av_malloc_array(w, h * sizeof(**rect->correction));
168+ if (!rect->correction[plane])
169+ return AVERROR(ENOMEM);
170+ for (j = 0; j < h; j++) {
171+ const int off_y = j - ycenter;
172+ const int off_y2 = off_y * off_y;
173+ for (i = 0; i < w; i++) {
174+ const int off_x = i - xcenter;
175+ const float r2 = (off_x * off_x + off_y2) * r2inv;
176+ const float radius_mult = 1.0f + r2 * k1 + r2 * r2 * k2;
177+ rect->correction[plane][j * w + i] = lrintf(radius_mult * (1<<24));
178+ }
179+ }
180+ }
181+
182+ td.correction = rect->correction[plane];
164183 ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads));
165184 }
166185

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