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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */21 */
22 22
23#include "libavutil/reverse.h"
24#include "avcodec.h"23#include "avcodec.h"
25#include "codec_internal.h"24#include "codec_internal.h"
26#include "encode.h"25#include "encode.h"
27#include "mathops.h"
28 26
29#define ANSI_MIN_READLINE 50927#define ANSI_MIN_READLINE 509
30 28
@@ -57,14 +55,25 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 26 unmodified lines
57 buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n");55 buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n");
58 for (i = 0, l = lineout; i < avctx->height; i++) {56 for (i = 0, l = lineout; i < avctx->height; i++) {
59 for (j = 0; j < linesize; j++) {57 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++;
61 if (--commas <= 0) {70 if (--commas <= 0) {
62 buf += snprintf(buf, 2, "\n");71 *buf++ = '\n';
63 break;72 break;
64 }73 }
65 buf += snprintf(buf, 2, ",");74 *buf++ = ',';
66 if (--l <= 0) {75 if (--l <= 0) {
67 buf += snprintf(buf, 2, "\n");76 *buf++ = '\n';
68 l = lineout;77 l = lineout;
69 }78 }
70 }79 }

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