Use a small LUT instead. Improves performance.
Unified · Split
| @@ -20,11 +20,9 @@ · 19 unmodified lines | |||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 20 | * 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 509 | 27 | #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 | } |