From patchwork Sat May 28 14:52:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35975 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp1396991pzj; Sat, 28 May 2022 07:52:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZWyOsI2KDT0eYO83XF/2t/v0FCJ/JSs1EQkQ0pEec2ksp8piusJmScuxOPktMuehmnCNr X-Received: by 2002:a17:907:94c6:b0:6fe:d71a:b721 with SMTP id dn6-20020a17090794c600b006fed71ab721mr27599176ejc.313.1653749553412; Sat, 28 May 2022 07:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653749553; cv=none; d=google.com; s=arc-20160816; b=wl07av9DjnxDMmAUX0Nh9hdK1s3szICLeJe1DXX9PYNaU7WHx6Gkut8gI9Ycceih2R oyIu7FrA+GUilQR10pDtPLbKZB7AulX5awMRw6N7dDVkBzuehq4+irhuzWsSjuDqmMJp NEQ9OlaCjXrTsqnl8b92LPvNAXw1ozCHLRrq0BBFvguINFMGt+ExF/Eib5aginztu5AA g4rA8KKmpittR0uu5rITWVM592wlA+bb44C1dVSdE/x9qIQA5U9iSE0cDuwZD2ZmAj1H 2/PNkmjUvvtRGGJtDOr5TdAiO6sEhulnnJjqxHf6AaSjfM+e9EUHsg5D7I5UalEjvwq9 p3Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=beBtDe4HfvgiIDMsAmGcl+g6l9BjiA0VS7l7aukFyvc=; b=ZMzIxh2c3RzWrIeAwvuOrAHehyoONVZUJgDNJl2gVkgrfJj9MzjxNDvObUH+PxAhn6 dwwe15z745zz8wUzC/cG0BjMEfe5QFjEz6234dskQ91O+mAhPcrVgWAANG+CJVvQBY+c n/tdshqqDD88VmSrXk7ac7Rhba5DkZUBQGHtaREOiP8SCAamzkRU4OebTH1LENh2Ebh/ Me7+ursXFWFgWLhkq23Rx9jULK8qYuwmBENlsBv8PmvJEJr7htjTNKlvz+p5McgyGRMj kOdUKlg6nGQ4UVXcKcC8kYvsyeVfeo2D6o6TYcOrFc3bxgvBBrUV0Bzg+vshjORFNblH ptJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=VfCEPg9j; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s3-20020a17090699c300b006feba2fff4dsi6506670ejn.840.2022.05.28.07.52.32; Sat, 28 May 2022 07:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=VfCEPg9j; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE70968B5F8; Sat, 28 May 2022 17:52:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4047268B3F9 for ; Sat, 28 May 2022 17:52:22 +0300 (EEST) Received: by mail-pl1-f179.google.com with SMTP id b5so6562736plx.10 for ; Sat, 28 May 2022 07:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=4b6+R2mpPyfb8Po9lij3kEhIPnN2/66eQoVk1vhhXxY=; b=VfCEPg9jOIEWxBRzxzUt1mv5xJgXqbTHte2L54SrUhd95krJsmVbrVnOdaDS2jyeym 45pgSY9xVwHkxpSTwf4LL4LjVJCzvAU74qNDs2PHm8GyydnYsjB7CHLahR3pX5Bwb/ky +nn/xz/YWuduLd+fQ9cyVEUVpulNEGcNA3bjWfL5Ld6i7sb3keMhP7NRmlGH6zIcLyWt ptXlPhWwSkSqmKHY5tEP5BzuyDEJZIDd6jc9dSmrvlkHOD6k0gfw5Oeg53yZHJHTkv5S 31WtFg9wYMhe6pw4vOLgQfsChMwFHYmVE+uUJBht93Jn+S9TGpWBWt6ayH6UdhrsCjki OQQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4b6+R2mpPyfb8Po9lij3kEhIPnN2/66eQoVk1vhhXxY=; b=7C/+EKvQGOoPe0mZQBTZzYC0nx1MO26xFLCWAB0AGNMJRjfaqDKn1vb9s+JahxU4aE a5O47aQmqce7O/XgDrHYYrvEv0DB1wd2P2iqhYYvwFSQX0f3sKoEdqa0E2ZNnOPt/po0 otTcs/5CSaTRf8oX76PLorxKmlZXBbGZIkqjyZMMOnvM2dBp7fLzZoaL5Os1HY2kAg7O mgyTzYmvQ6XNS3mJp2TPD0CPCraeyTUvpiMsAhou370d0mzntL9eSkdnwEdotbxUf0OB rZHoy+8QZJfIcp4p93DN7QZw6V00jNs/wd5F1estGsK9oX9v0BSAwEFYfwmjKoASYLWC rCyw== X-Gm-Message-State: AOAM5331t+u0z7Mt4g9Mdp4g+wTLC5uIEJsg+u64wlrUGbvTftmV7DD9 u1q+PCRFfbaatl5N9bcCl0aO/r/uYx3cyg== X-Received: by 2002:a17:90b:1c92:b0:1dd:10ff:8f13 with SMTP id oo18-20020a17090b1c9200b001dd10ff8f13mr13584182pjb.54.1653749540206; Sat, 28 May 2022 07:52:20 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id x9-20020aa793a9000000b0050dc7628191sm5377509pff.107.2022.05.28.07.52.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 May 2022 07:52:19 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 28 May 2022 14:52:18 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3] avcodec/dvdsubdec, dvbsubdec: remove bitmap dumping in DEBUG builds X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: softworkz , Hendrik Leppkes , Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oUnYDDUB8BEK From: softworkz It's been a regular annoyance and often undesired. There will be a subtitle filter which allows to dump individual subtitle bitmaps. Signed-off-by: softworkz --- avcodec/dvdsubdec,dvbsubdec: remove bitmap dumping in DEBUG builds Original Message: > It's annoying and unexpected, but still useful at times (as I've > realized just recently). > > This is a follow-up to the earlier submission here: > https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg128080.html > > There has been a comment from Anton, questioning whether the > dump-feature is useful. Meanwhile I came to the conclusion that it can > be useful in-fact. It just shouldn't happen automatically when DEBUG > is defined. That's what these patches do. v2: My previous submission wasn't liked that much and there seemed to be a consensus to drop this altogether. So - here's the commit for dropping it. Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-17%2Fsoftworkz%2Fsubmit_dvb_subs-v3 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-17/softworkz/submit_dvb_subs-v3 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/17 Range-diff vs v2: 1: 2f12ac7f1f < -: ---------- avcodec/dvdsubdec,dvbsubdec: don't dump images to disk based on DEBUG define 2: 0cd2c77f31 < -: ---------- avcodec/dvdsubdec,dvbsubdec: fix writing ppm -: ---------- > 1: e12db0e6d7 avcodec/dvdsubdec,dvbsubdec: remove bitmap dumping in DEBUG builds libavcodec/dvbsubdec.c | 169 ----------------------------------------- libavcodec/dvdsubdec.c | 48 ------------ 2 files changed, 217 deletions(-) base-commit: 9fba0b8a8c754a012fc74c90ffb7c26a56be8ca0 diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index 6e510d12c7..4d4007ffd9 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -1381,172 +1381,6 @@ static int dvbsub_parse_page_segment(AVCodecContext *avctx, return 0; } - -#ifdef DEBUG -static void png_save(DVBSubContext *ctx, 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) { - av_log(ctx, AV_LOG_ERROR, "Error running pnmtopng\n"); - return; - } - - snprintf(command, sizeof(command), "rm %s %s", fname, fname2); - if (system(command) != 0) { - av_log(ctx, AV_LOG_ERROR, "Error removing %s and %s\n", fname, fname2); - return; - } -} - -static int save_display_set(DVBSubContext *ctx) -{ - DVBSubRegion *region; - DVBSubRegionDisplay *display; - const DVBSubCLUT *clut; - const uint32_t *clut_table; - int x_pos, y_pos, width, height; - int x, y, y_off, x_off; - uint32_t *pbuf; - char filename[32]; - static int fileno_index = 0; - - x_pos = -1; - y_pos = -1; - width = 0; - height = 0; - - for (display = ctx->display_list; display; display = display->next) { - region = get_region(ctx, display->region_id); - - if (!region) - return -1; - - if (x_pos == -1) { - x_pos = display->x_pos; - y_pos = display->y_pos; - width = region->width; - height = region->height; - } else { - if (display->x_pos < x_pos) { - width += (x_pos - display->x_pos); - x_pos = display->x_pos; - } - - if (display->y_pos < y_pos) { - height += (y_pos - display->y_pos); - y_pos = display->y_pos; - } - - if (display->x_pos + region->width > x_pos + width) { - width = display->x_pos + region->width - x_pos; - } - - if (display->y_pos + region->height > y_pos + height) { - height = display->y_pos + region->height - y_pos; - } - } - } - - if (x_pos >= 0) { - - pbuf = av_malloc(width * height * 4); - if (!pbuf) - return -1; - - for (display = ctx->display_list; display; display = display->next) { - region = get_region(ctx, display->region_id); - - if (!region) - return -1; - - x_off = display->x_pos - x_pos; - y_off = display->y_pos - y_pos; - - clut = get_clut(ctx, region->clut); - - if (!clut) - clut = &default_clut; - - switch (region->depth) { - case 2: - clut_table = clut->clut4; - break; - case 8: - clut_table = clut->clut256; - break; - case 4: - default: - clut_table = clut->clut16; - break; - } - - for (y = 0; y < region->height; y++) { - for (x = 0; x < region->width; x++) { - pbuf[((y + y_off) * width) + x_off + x] = - clut_table[region->pbuf[y * region->width + x]]; - } - } - - } - - snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index); - - png_save(ctx, filename, pbuf, width, height); - - av_freep(&pbuf); - } - - fileno_index++; - return 0; -} -#endif /* DEBUG */ - static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) @@ -1601,9 +1435,6 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, if (ctx->compute_edt == 0) save_subtitle_set(avctx, sub, got_output); -#ifdef DEBUG - save_display_set(ctx); -#endif return 0; } diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index b54073393e..97f366cc74 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -43,9 +43,6 @@ typedef struct DVDSubContext int buf_size; int forced_subs_only; uint8_t used_color[256]; -#ifdef DEBUG - int sub_id; -#endif } DVDSubContext; static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values) @@ -499,38 +496,6 @@ static int find_smallest_bounding_rectangle(DVDSubContext *ctx, AVSubtitle *s) return 1; } -#ifdef DEBUG -#define ALPHA_MIX(A,BACK,FORE) (((255-(A)) * (BACK) + (A) * (FORE)) / 255) -static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h, - uint32_t *rgba_palette) -{ - int x, y, alpha; - uint32_t v; - int back[3] = {0, 255, 0}; /* green background */ - FILE *f; - - f = fopen(filename, "w"); - if (!f) { - perror(filename); - 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]]; - alpha = v >> 24; - putc(ALPHA_MIX(alpha, back[0], (v >> 16) & 0xff), f); - putc(ALPHA_MIX(alpha, back[1], (v >> 8) & 0xff), f); - putc(ALPHA_MIX(alpha, back[2], (v >> 0) & 0xff), f); - } - } - fclose(f); -} -#endif - static int append_to_cached_buf(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { @@ -588,19 +553,6 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED)) goto no_subtitle; -#if defined(DEBUG) - { - char ppm_name[32]; - - snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++); - ff_dlog(NULL, "start=%d ms end =%d ms\n", - sub->start_display_time, - sub->end_display_time); - ppm_save(ppm_name, sub->rects[0]->data[0], - sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->data[1]); - } -#endif - ctx->buf_size = 0; *data_size = 1; return buf_size;