History

avcodec/ffv1enc: Eliminate RemapEncoderState

Michael Niedermayer committed 1 year ago

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

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

Unified · Split

libavcodec/ffv1enc.c+67−84
@@ -1252,64 +1252,47 @@ static void load_rgb_float32_frame(FFV1Context *f, FFV1SliceContext *sc, · 1251 unmodified lines
1252 AV_QSORT(sc->unit[3], i, struct Unit, CMP);1252 AV_QSORT(sc->unit[3], i, struct Unit, CMP);
1253}1253}
1254 1254
1255typedef struct RemapEncoderState {1255static 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;
1256 uint8_t state[2][3][32];1259 uint8_t state[2][3][32];
1257 int mul[4096+1];1260 int mul[4096+1];
1258 RangeCoder rc;1261 RangeCoder rc = sc->c;
1259 int lu;1262 int lu = 0;
1260 int run;1263 int run = 0;
1261 int64_t last_val;1264 int64_t last_val = -1;
1262 int compact_index;1265 int compact_index = -1;
1263 int mul_count;1266 int i = 0;
1264 int i;1267 int current_mul_index = -1;
1265 int pixel_num;1268 int run1final = 0;
1266 int p;
1267 int current_mul_index;
1268 int run1final;
1269 int64_t run1start_i;1269 int64_t run1start_i;
1270 int64_t run1start_last_val;1270 int64_t run1start_last_val;
1271 int run1start_mul_index;1271 int run1start_mul_index;
1272} RemapEncoderState;
1273 1272
1274static int encode_float32_remap_segment(FFV1SliceContext *sc,1273 memcpy(mul, mul_tab, sizeof(*mul_tab)*(mul_count+1));
1275 int p, int mul_count, int *mul_tab, int update, int final)1274 memset(state, 128, sizeof(state));
1276{1275 put_symbol(&rc, state[0][0], mul_count, 0);
1277 RemapEncoderState s;1276 memset(state, 128, sizeof(state));
1278 1277
1279 s.pixel_num = sc->slice_width * sc->slice_height;1278 for (; i < pixel_num+1; i++) {
1280 s.p = p;1279 int current_mul = current_mul_index < 0 ? 1 : FFABS(mul[current_mul_index]);
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]);
1297 int64_t val;1280 int64_t val;
1298 if (s.i == s.pixel_num) {1281 if (i == pixel_num) {
1299 if (s.last_val == 0xFFFFFFFF) {1282 if (last_val == 0xFFFFFFFF) {
1300 break;1283 break;
1301 } else {1284 } 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;
1303 av_assert2(val >= (1LL<<32));1286 av_assert2(val >= (1LL<<32));
1304 val += s.lu * current_mul; //ensure a run1 ends1287 val += lu * current_mul; //ensure a run1 ends
1305 }1288 }
1306 } else1289 } else
1307 val = sc->unit[s.p][s.i].val;1290 val = sc->unit[p][i].val;
1308 1291
1309 if (s.last_val != val) {1292 if (last_val != val) {
1310 int64_t delta = val - s.last_val;1293 int64_t delta = val - last_val;
1311 int64_t step = FFMAX(1, (delta + current_mul/2) / current_mul);1294 int64_t step = FFMAX(1, (delta + current_mul/2) / current_mul);
1312 av_assert2(s.last_val < val);1295 av_assert2(last_val < val);
1313 av_assert2(current_mul > 0);1296 av_assert2(current_mul > 0);
1314 1297
1315 delta -= step*current_mul;1298 delta -= step*current_mul;
@@ -1317,69 +1300,69 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc, · 1 unmodified line
1317 av_assert2(delta > -current_mul);1300 av_assert2(delta > -current_mul);
1318 1301
1319 av_assert2(step > 0);1302 av_assert2(step > 0);
1320 if (s.lu) {1303 if (lu) {
1321 if (!s.run) {1304 if (!run) {
1322 s.run1start_i = s.i - 1;1305 run1start_i = i - 1;
1323 s.run1start_last_val = s.last_val;1306 run1start_last_val = last_val;
1324 s.run1start_mul_index= s.current_mul_index;1307 run1start_mul_index= current_mul_index;
1325 }1308 }
1326 if (step == 1) {1309 if (step == 1) {
1327 if (s.run1final) {1310 if (run1final) {
1328 if (current_mul>1)1311 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);
1330 }1313 }
1331 s.run ++;1314 run ++;
1332 av_assert2(s.last_val + current_mul + delta == val);1315 av_assert2(last_val + current_mul + delta == val);
1333 } else {1316 } else {
1334 if (s.run1final) {1317 if (run1final) {
1335 if (s.run == 0)1318 if (run == 0)
1336 s.lu ^= 1;1319 lu ^= 1;
1337 s.i--; // we did not encode val so we need to backstep1320 i--; // we did not encode val so we need to backstep
1338 s.last_val += current_mul;1321 last_val += current_mul;
1339 } else {1322 } else {
1340 put_symbol_inline(&s.rc, s.state[s.lu][0], s.run, 0, NULL, NULL);1323 put_symbol_inline(&rc, state[lu][0], run, 0, NULL, NULL);
1341 s.i = s.run1start_i;1324 i = run1start_i;
1342 s.last_val = s.run1start_last_val; // we could compute this instead of storing1325 last_val = run1start_last_val; // we could compute this instead of storing
1343 s.current_mul_index = s.run1start_mul_index;1326 current_mul_index = run1start_mul_index;
1344 }1327 }
1345 s.run1final ^= 1;1328 run1final ^= 1;
1346 1329
1347 s.run = 0;1330 run = 0;
1348 continue;1331 continue;
1349 }1332 }
1350 } else {1333 } else {
1351 av_assert2(s.run == 0);1334 av_assert2(run == 0);
1352 av_assert2(s.run1final == 0);1335 av_assert2(run1final == 0);
1353 put_symbol_inline(&s.rc, s.state[s.lu][0], step - 1, 0, NULL, NULL);1336 put_symbol_inline(&rc, state[lu][0], step - 1, 0, NULL, NULL);
1354 1337
1355 if (current_mul > 1)1338 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);
1357 if (step == 1)1340 if (step == 1)
1358 s.lu ^= 1;1341 lu ^= 1;
1359 1342
1360 av_assert2(s.last_val + step * current_mul + delta == val);1343 av_assert2(last_val + step * current_mul + delta == val);
1361 }1344 }
1362 s.last_val = val;1345 last_val = val;
1363 s.current_mul_index = ((s.last_val + 1) * s.mul_count) >> 32;1346 current_mul_index = ((last_val + 1) * mul_count) >> 32;
1364 if (!s.run || s.run1final) {1347 if (!run || run1final) {
1365 av_assert2(s.mul[ s.current_mul_index ]);1348 av_assert2(mul[ current_mul_index ]);
1366 if (s.mul[ s.current_mul_index ] < 0) {1349 if (mul[ current_mul_index ] < 0) {
1367 av_assert2(s.i < s.pixel_num);1350 av_assert2(i < pixel_num);
1368 s.mul[ s.current_mul_index ] *= -1;1351 mul[ current_mul_index ] *= -1;
1369 put_symbol_inline(&s.rc, s.state[0][2], s.mul[ s.current_mul_index ], 0, NULL, NULL);1352 put_symbol_inline(&rc, state[0][2], mul[ current_mul_index ], 0, NULL, NULL);
1370 }1353 }
1371 s.compact_index ++;1354 compact_index ++;
1372 }1355 }
1373 }1356 }
1374 if (!s.run || s.run1final)1357 if (!run || run1final)
1375 if (final && s.i < s.pixel_num)1358 if (final && i < pixel_num)
1376 sc->bitmap[s.p][sc->unit[s.p][s.i].ndx] = s.compact_index;1359 sc->bitmap[p][sc->unit[p][i].ndx] = compact_index;
1377 }1360 }
1378 1361
1379 if (update) {1362 if (update) {
1380 sc->c = s.rc;1363 sc->c = rc;
1381 }1364 }
1382 return get_rac_count(&s.rc);1365 return get_rac_count(&rc);
1383}1366}
1384 1367
1385static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc,1368static 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