History

avcodec/xbmenc: Avoid snprintf() for data->hex conversion

Use a small LUT instead. Improves performance.

Andreas Rheinhardt committed 2 years ago

Commit 878f8ca1 parent 357e3391 file · +15 −6Browse files

Unified · Split

libavcodec/xbmenc.c+15−6
@@ -20,11 +20,9 @@ · 19 unmodified lines
2020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121 */
2222
23−#include "libavutil/reverse.h"
2423 #include "avcodec.h"
2524 #include "codec_internal.h"
2625 #include "encode.h"
27−#include "mathops.h"
2826
2927 #define ANSI_MIN_READLINE 509
3028
@@ -57,14 +55,25 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 26 unmodified lines
5755 buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n");
5856 for (i = 0, l = lineout; i < avctx->height; i++) {
5957 for (j = 0; j < linesize; j++) {
60− buf += snprintf(buf, 6, " 0x%02X", ff_reverse[*ptr++]);
58+ // 0..15 bitreversed as chars
59+ static const char lut[] = {
60+ '0', '8', '4', 'C', '2', 'A', '6', 'E',
61+ '1', '9', '5', 'D', '3', 'B', '7', 'F'
62+ };
63+ buf[0] = ' ';
64+ buf[1] = '0';
65+ buf[2] = 'x';
66+ buf[3] = lut[*ptr & 0xF];
67+ buf[4] = lut[*ptr >> 4];
68+ buf += 5;
69+ ptr++;
6170 if (--commas <= 0) {
62− buf += snprintf(buf, 2, "\n");
71+ *buf++ = '\n';
6372 break;
6473 }
65− buf += snprintf(buf, 2, ",");
74+ *buf++ = ',';
6675 if (--l <= 0) {
67− buf += snprintf(buf, 2, "\n");
76+ *buf++ = '\n';
6877 l = lineout;
6978 }
7079 }

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