X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fdvbsubdec.c;h=c3248c99191e84401ed0679d13c0d84fc5cffc53;hb=ea7ee4b4e381e0fa731458de0cbf740430eeb013;hp=d2b95bc53d4cbef61e66c38fedc58bf5c4640639;hpb=6a85dfc830f51f1f5c2d36d4182d265c1ea3ba25;p=ffmpeg diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index d2b95bc53d4..c3248c99191 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -34,121 +34,6 @@ #define cm (ff_crop_tab + MAX_NEG_CROP) -#ifdef DEBUG -#if 0 -static void png_save(const char *filename, uint8_t *bitmap, int w, int h, - uint32_t *rgba_palette) -{ - int x, y, v; - FILE *f; - char fname[40], fname2[40]; - char command[1024]; - - snprintf(fname, 40, "%s.ppm", filename); - - f = fopen(fname, "w"); - if (!f) { - perror(fname); - return; - } - fprintf(f, "P6\n" - "%d %d\n" - "%d\n", - w, h, 255); - for(y = 0; y < h; y++) { - for(x = 0; x < w; x++) { - v = rgba_palette[bitmap[y * w + x]]; - putc((v >> 16) & 0xff, f); - putc((v >> 8) & 0xff, f); - putc((v >> 0) & 0xff, f); - } - } - fclose(f); - - - snprintf(fname2, 40, "%s-a.pgm", filename); - - f = fopen(fname2, "w"); - if (!f) { - perror(fname2); - return; - } - fprintf(f, "P5\n" - "%d %d\n" - "%d\n", - w, h, 255); - for(y = 0; y < h; y++) { - for(x = 0; x < w; x++) { - v = rgba_palette[bitmap[y * w + x]]; - putc((v >> 24) & 0xff, f); - } - } - fclose(f); - - snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); - system(command); - - snprintf(command, 1024, "rm %s %s", fname, fname2); - system(command); -} -#endif - -static void png_save2(const char *filename, uint32_t *bitmap, int w, int h) -{ - int x, y, v; - FILE *f; - char fname[40], fname2[40]; - char command[1024]; - - snprintf(fname, sizeof(fname), "%s.ppm", filename); - - f = fopen(fname, "w"); - if (!f) { - perror(fname); - return; - } - fprintf(f, "P6\n" - "%d %d\n" - "%d\n", - w, h, 255); - for(y = 0; y < h; y++) { - for(x = 0; x < w; x++) { - v = bitmap[y * w + x]; - putc((v >> 16) & 0xff, f); - putc((v >> 8) & 0xff, f); - putc((v >> 0) & 0xff, f); - } - } - fclose(f); - - - snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename); - - f = fopen(fname2, "w"); - if (!f) { - perror(fname2); - return; - } - fprintf(f, "P5\n" - "%d %d\n" - "%d\n", - w, h, 255); - for(y = 0; y < h; y++) { - for(x = 0; x < w; x++) { - v = bitmap[y * w + x]; - putc((v >> 24) & 0xff, f); - } - } - fclose(f); - - snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); - system(command); - - snprintf(command, sizeof(command), "rm %s %s", fname, fname2); - system(command); -} -#endif - #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) typedef struct DVBSubCLUT { @@ -344,7 +229,7 @@ static void delete_state(DVBSubContext *ctx) /* Should already be null */ if (ctx->object_list) - av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n"); + av_log(NULL, AV_LOG_ERROR, "Memory deallocation error!\n"); } static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) @@ -539,7 +424,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } if (get_bits(&gb, 6)) - av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); + av_log(NULL, AV_LOG_ERROR, "DVBSub error: line overflow\n"); (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; @@ -660,7 +545,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } if (get_bits(&gb, 8)) - av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); + av_log(NULL, AV_LOG_ERROR, "DVBSub error: line overflow\n"); (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; @@ -712,7 +597,7 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, } if (*(*srcbuf)++) - av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); + av_log(NULL, AV_LOG_ERROR, "DVBSub error: line overflow\n"); return pixels_read; } @@ -1175,7 +1060,68 @@ static int dvbsub_parse_page_segment(AVCodecContext *avctx, #ifdef DEBUG -static void save_display_set(DVBSubContext *ctx) +static void png_save(const char *filename, uint32_t *bitmap, int w, int h) +{ + int x, y, v; + FILE *f; + char fname[40], fname2[40]; + char command[1024]; + + snprintf(fname, sizeof(fname), "%s.ppm", filename); + + f = fopen(fname, "w"); + if (!f) { + perror(fname); + return; + } + fprintf(f, "P6\n" + "%d %d\n" + "%d\n", + w, h, 255); + for(y = 0; y < h; y++) { + for(x = 0; x < w; x++) { + v = bitmap[y * w + x]; + putc((v >> 16) & 0xff, f); + putc((v >> 8) & 0xff, f); + putc((v >> 0) & 0xff, f); + } + } + fclose(f); + + + snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename); + + f = fopen(fname2, "w"); + if (!f) { + perror(fname2); + return; + } + fprintf(f, "P5\n" + "%d %d\n" + "%d\n", + w, h, 255); + for(y = 0; y < h; y++) { + for(x = 0; x < w; x++) { + v = bitmap[y * w + x]; + putc((v >> 24) & 0xff, f); + } + } + fclose(f); + + snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); + if (system(command) != 0) { + printf("Error running pnmtopng\n"); + return; + } + + snprintf(command, sizeof(command), "rm %s %s", fname, fname2); + if (system(command) != 0) { + printf("Error removing %s and %s\n", fname, fname2); + return; + } +} + +static int save_display_set(DVBSubContext *ctx) { DVBSubRegion *region; DVBSubRegionDisplay *display; @@ -1262,14 +1208,15 @@ static void save_display_set(DVBSubContext *ctx) snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index); - png_save2(filename, pbuf, width, height); + png_save(filename, pbuf, width, height); av_free(pbuf); } fileno_index++; + return 0; } -#endif +#endif /* DEBUG */ static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx, const uint8_t *buf, @@ -1361,7 +1308,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, rect->h = region->height; rect->nb_colors = 16; rect->type = SUBTITLE_BITMAP; - rect->pict.linesize[0] = region->width; + rect->linesize[0] = region->width; clut = get_clut(ctx, region->clut); @@ -1381,20 +1328,32 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, break; } - rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE); - if (!rect->pict.data[1]) { + rect->data[1] = av_mallocz(AVPALETTE_SIZE); + if (!rect->data[1]) { av_free(sub->rects); return AVERROR(ENOMEM); } - memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); + memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); - rect->pict.data[0] = av_malloc(region->buf_size); - if (!rect->pict.data[0]) { - av_free(rect->pict.data[1]); + rect->data[0] = av_malloc(region->buf_size); + if (!rect->data[0]) { + av_free(rect->data[1]); av_free(sub->rects); return AVERROR(ENOMEM); } - memcpy(rect->pict.data[0], region->pbuf, region->buf_size); + memcpy(rect->data[0], region->pbuf, region->buf_size); + +#if FF_API_AVPICTURE +FF_DISABLE_DEPRECATION_WARNINGS +{ + int j; + for (j = 0; j < 4; j++) { + rect->pict.data[j] = rect->data[j]; + rect->pict.linesize[j] = rect->linesize[j]; + } +} +FF_ENABLE_DEPRECATION_WARNINGS +#endif i++; }