History

avcodec/ffv1enc: Eliminate RemapEncoderState

Michael Niedermayer committed 1 year ago

Commit f7650851 parent 3faee891 file · +67 −84Browse files

Unified · Split

libavcodec/ffv1enc.c+67−84
@@ -1252,64 +1252,47 @@ static void load_rgb_float32_frame(FFV1Context *f, FFV1SliceContext *sc, · 1251 unmodified lines
12521252 AV_QSORT(sc->unit[3], i, struct Unit, CMP);
12531253 }
12541254
1255−typedef struct RemapEncoderState {
1255+static int encode_float32_remap_segment(FFV1SliceContext *sc,
1256+ int p, int mul_count, int *mul_tab, int update, int final)
1257+{
1258+ const int pixel_num = sc->slice_width * sc->slice_height;
12561259 uint8_t state[2][3][32];
12571260 int mul[4096+1];
1258− RangeCoder rc;
1259− int lu;
1260− int run;
1261− int64_t last_val;
1262− int compact_index;
1263− int mul_count;
1264− int i;
1265− int pixel_num;
1266− int p;
1267− int current_mul_index;
1268− int run1final;
1261+ RangeCoder rc = sc->c;
1262+ int lu = 0;
1263+ int run = 0;
1264+ int64_t last_val = -1;
1265+ int compact_index = -1;
1266+ int i = 0;
1267+ int current_mul_index = -1;
1268+ int run1final = 0;
12691269 int64_t run1start_i;
12701270 int64_t run1start_last_val;
12711271 int run1start_mul_index;
1272−} RemapEncoderState;
12731272
1274−static int encode_float32_remap_segment(FFV1SliceContext *sc,
1275− int p, int mul_count, int *mul_tab, int update, int final)
1276−{
1277− RemapEncoderState s;
1278−
1279− s.pixel_num = sc->slice_width * sc->slice_height;
1280− s.p = p;
1281− s.i = 0;
1282− s.rc = sc->c;
1283− s.mul_count = mul_count;
1284− memcpy(s.mul, mul_tab, sizeof(*mul_tab)*(mul_count+1));
1285− memset(s.state, 128, sizeof(s.state));
1286− put_symbol(&s.rc, s.state[0][0], s.mul_count, 0);
1287− memset(s.state, 128, sizeof(s.state));
1288− s.last_val = -1;
1289− s.compact_index = -1;
1290− s.lu = 0;
1291− s.run = 0;
1292− s.current_mul_index = -1;
1293− s.run1final = 0;
1294−
1295− for (; s.i < s.pixel_num+1; s.i++) {
1296− int current_mul = s.current_mul_index < 0 ? 1 : FFABS(s.mul[s.current_mul_index]);
1273+ memcpy(mul, mul_tab, sizeof(*mul_tab)*(mul_count+1));
1274+ memset(state, 128, sizeof(state));
1275+ put_symbol(&rc, state[0][0], mul_count, 0);
1276+ memset(state, 128, sizeof(state));
1277+
1278+ for (; i < pixel_num+1; i++) {
1279+ int current_mul = current_mul_index < 0 ? 1 : FFABS(mul[current_mul_index]);
12971280 int64_t val;
1298− if (s.i == s.pixel_num) {
1299− if (s.last_val == 0xFFFFFFFF) {
1281+ if (i == pixel_num) {
1282+ if (last_val == 0xFFFFFFFF) {
13001283 break;
13011284 } else {
1302− val = s.last_val + ((1LL<<32) - s.last_val + current_mul - 1) / current_mul * current_mul;
1285+ val = last_val + ((1LL<<32) - last_val + current_mul - 1) / current_mul * current_mul;
13031286 av_assert2(val >= (1LL<<32));
1304− val += s.lu * current_mul; //ensure a run1 ends
1287+ val += lu * current_mul; //ensure a run1 ends
13051288 }
13061289 } else
1307− val = sc->unit[s.p][s.i].val;
1290+ val = sc->unit[p][i].val;
13081291
1309− if (s.last_val != val) {
1310− int64_t delta = val - s.last_val;
1292+ if (last_val != val) {
1293+ int64_t delta = val - last_val;
13111294 int64_t step = FFMAX(1, (delta + current_mul/2) / current_mul);
1312− av_assert2(s.last_val < val);
1295+ av_assert2(last_val < val);
13131296 av_assert2(current_mul > 0);
13141297
13151298 delta -= step*current_mul;
@@ -1317,69 +1300,69 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc, · 1 unmodified line
13171300 av_assert2(delta > -current_mul);
13181301
13191302 av_assert2(step > 0);
1320− if (s.lu) {
1321− if (!s.run) {
1322− s.run1start_i = s.i - 1;
1323− s.run1start_last_val = s.last_val;
1324− s.run1start_mul_index= s.current_mul_index;
1303+ if (lu) {
1304+ if (!run) {
1305+ run1start_i = i - 1;
1306+ run1start_last_val = last_val;
1307+ run1start_mul_index= current_mul_index;
13251308 }
13261309 if (step == 1) {
1327− if (s.run1final) {
1310+ if (run1final) {
13281311 if (current_mul>1)
1329− put_symbol_inline(&s.rc, s.state[s.lu][1], delta, 1, NULL, NULL);
1312+ put_symbol_inline(&rc, state[lu][1], delta, 1, NULL, NULL);
13301313 }
1331− s.run ++;
1332− av_assert2(s.last_val + current_mul + delta == val);
1314+ run ++;
1315+ av_assert2(last_val + current_mul + delta == val);
13331316 } else {
1334− if (s.run1final) {
1335− if (s.run == 0)
1336− s.lu ^= 1;
1337− s.i--; // we did not encode val so we need to backstep
1338− s.last_val += current_mul;
1317+ if (run1final) {
1318+ if (run == 0)
1319+ lu ^= 1;
1320+ i--; // we did not encode val so we need to backstep
1321+ last_val += current_mul;
13391322 } else {
1340− put_symbol_inline(&s.rc, s.state[s.lu][0], s.run, 0, NULL, NULL);
1341− s.i = s.run1start_i;
1342− s.last_val = s.run1start_last_val; // we could compute this instead of storing
1343− s.current_mul_index = s.run1start_mul_index;
1323+ put_symbol_inline(&rc, state[lu][0], run, 0, NULL, NULL);
1324+ i = run1start_i;
1325+ last_val = run1start_last_val; // we could compute this instead of storing
1326+ current_mul_index = run1start_mul_index;
13441327 }
1345− s.run1final ^= 1;
1328+ run1final ^= 1;
13461329
1347− s.run = 0;
1330+ run = 0;
13481331 continue;
13491332 }
13501333 } else {
1351− av_assert2(s.run == 0);
1352− av_assert2(s.run1final == 0);
1353− put_symbol_inline(&s.rc, s.state[s.lu][0], step - 1, 0, NULL, NULL);
1334+ av_assert2(run == 0);
1335+ av_assert2(run1final == 0);
1336+ put_symbol_inline(&rc, state[lu][0], step - 1, 0, NULL, NULL);
13541337
13551338 if (current_mul > 1)
1356− put_symbol_inline(&s.rc, s.state[s.lu][1], delta, 1, NULL, NULL);
1339+ put_symbol_inline(&rc, state[lu][1], delta, 1, NULL, NULL);
13571340 if (step == 1)
1358− s.lu ^= 1;
1341+ lu ^= 1;
13591342
1360− av_assert2(s.last_val + step * current_mul + delta == val);
1343+ av_assert2(last_val + step * current_mul + delta == val);
13611344 }
1362− s.last_val = val;
1363− s.current_mul_index = ((s.last_val + 1) * s.mul_count) >> 32;
1364− if (!s.run || s.run1final) {
1365− av_assert2(s.mul[ s.current_mul_index ]);
1366− if (s.mul[ s.current_mul_index ] < 0) {
1367− av_assert2(s.i < s.pixel_num);
1368− s.mul[ s.current_mul_index ] *= -1;
1369− put_symbol_inline(&s.rc, s.state[0][2], s.mul[ s.current_mul_index ], 0, NULL, NULL);
1345+ last_val = val;
1346+ current_mul_index = ((last_val + 1) * mul_count) >> 32;
1347+ if (!run || run1final) {
1348+ av_assert2(mul[ current_mul_index ]);
1349+ if (mul[ current_mul_index ] < 0) {
1350+ av_assert2(i < pixel_num);
1351+ mul[ current_mul_index ] *= -1;
1352+ put_symbol_inline(&rc, state[0][2], mul[ current_mul_index ], 0, NULL, NULL);
13701353 }
1371− s.compact_index ++;
1354+ compact_index ++;
13721355 }
13731356 }
1374− if (!s.run || s.run1final)
1375− if (final && s.i < s.pixel_num)
1376− sc->bitmap[s.p][sc->unit[s.p][s.i].ndx] = s.compact_index;
1357+ if (!run || run1final)
1358+ if (final && i < pixel_num)
1359+ sc->bitmap[p][sc->unit[p][i].ndx] = compact_index;
13771360 }
13781361
13791362 if (update) {
1380− sc->c = s.rc;
1363+ sc->c = rc;
13811364 }
1382− return get_rac_count(&s.rc);
1365+ return get_rac_count(&rc);
13831366 }
13841367
13851368 static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc,

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