From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 377AE4934D for ; Sat, 9 Mar 2024 18:28:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0EE568CD6D; Sat, 9 Mar 2024 20:28:21 +0200 (EET) Received: from mail-ua1-f97.google.com (mail-ua1-f97.google.com [209.85.222.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1512968CD3F for ; Sat, 9 Mar 2024 20:28:15 +0200 (EET) Received: by mail-ua1-f97.google.com with SMTP id a1e0cc1a2514c-7db1a21e83fso1004929241.2 for ; Sat, 09 Mar 2024 10:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1710008894; x=1710613694; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pybtzo3A6sNdIK4tns5Nv3mYvJIEEiwxWz023wKBa2I=; b=fjFpCpk2qWbLOXCS3oz/tyMzWlqE1Bg3MyvhlonzxDWkGcan36Ae//8IGI9xowckkK l0hte9JVnOtapVmGqePoZYF3pnKDHoimijJ+3lrAel0q3trgEgRdMAy8GMPJ04t8pJtB 2X0q2NyihLqNoXux5Rn21JeOjkGBg+xAZggfm0baWquK3G6A0WiaZCx7ZYCEl20YeQYd FTdVKH4PllQVT3zMoS0QLtflE6ulnbUILM5hqrTqKUhLbmDijAHXS27/I4q6/lmnNMdS Wm9wQ5rUzpOg3VKxQBkussUDWoJ4ysLd/OO/DL/maq1b0l3ziT2aWOgnkMYjjZ4P8o/2 hxgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710008894; x=1710613694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pybtzo3A6sNdIK4tns5Nv3mYvJIEEiwxWz023wKBa2I=; b=AOTRy5oaZAeLKDnb3qJ5JLfBlUuAr6C/RyMusYBBqwNYgjJKlxP5waYChrmNWRwKII UnYQOhvktgKq6FHVxQ+2Pcc6zSraqQ4jsQtLc0JkZMuxP3Fa+UJK3AfyiejTVGc5LNIc 0sO1kaWG5aXk/8+wA2UfeH2QmQqudJ+dB4WuCxhZP4nBbpo9QTKki/pLTbHxQV4q8nZF jI2ScZacV3j6S3bsFLyjAX3kfMC8KCXuV74N7WAHDZ3RbA56kC1tbhtmn4JyJiO5UepP ppunzFiv1oBjrQUtsGO7XmcVvjUUFFzSh3s9fd8EtPvCVBiEbPnkFRkY5xknnHMDyxC5 FQng== X-Gm-Message-State: AOJu0YzdsTn2PKU1Uh/c6O/Gs7ZC10vHA7hk5kqrUY+PvVaMFvaLeX9h VFzg4rVn9VK4BBaDmzMfwp8vLY/IKmcrF3Gin302LxmY/sCRiXEVh/p7wpy78z7ybswfJAW3ofz 9SlBxfH/9VUS9yI2LPRRSNMkmqOK9R1My3DrRX2Ca X-Google-Smtp-Source: AGHT+IHGLlIWYaleat+Ye0HWq/d6VngU+3fgvSTIlJbpYQHY50odJlK6pCzJ0+ghV/+CsjyrOJicYM9PlPEa X-Received: by 2002:a05:6102:21b1:b0:473:2445:cd58 with SMTP id i17-20020a05610221b100b004732445cd58mr501577vsb.16.1710008893828; Sat, 09 Mar 2024 10:28:13 -0800 (PST) Received: from wsx-cc1-001.. (c-76-141-249-38.hsd1.il.comcast.net. [76.141.249.38]) by smtp-relay.gmail.com with ESMTPS id bl39-20020a05610250a700b0047309fc6020sm95893vsb.1.2024.03.09.10.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 10:28:13 -0800 (PST) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 12:27:51 -0600 Message-Id: <20240309182752.3204466-3-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240309182752.3204466-1-marth64@proxyid.net> References: <20240309182752.3204466-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] avformat/dvdvideodec: add CLUT utilities and subtitle color support 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: Marth64 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Marth64 --- libavformat/Makefile | 2 +- libavformat/dvdclut.c | 75 +++++++++++++++++++++++++++++++++++++++ libavformat/dvdclut.h | 37 +++++++++++++++++++ libavformat/dvdvideodec.c | 14 ++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 libavformat/dvdclut.c create mode 100644 libavformat/dvdclut.h diff --git a/libavformat/Makefile b/libavformat/Makefile index 8811a0ffc9..a3bfc209c3 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -194,7 +194,7 @@ OBJS-$(CONFIG_DTS_MUXER) += rawenc.o OBJS-$(CONFIG_DV_MUXER) += dvenc.o OBJS-$(CONFIG_DVBSUB_DEMUXER) += dvbsub.o rawdec.o OBJS-$(CONFIG_DVBTXT_DEMUXER) += dvbtxt.o rawdec.o -OBJS-$(CONFIG_DVDVIDEO_DEMUXER) += dvdvideodec.o +OBJS-$(CONFIG_DVDVIDEO_DEMUXER) += dvdvideodec.o dvdclut.o OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o diff --git a/libavformat/dvdclut.c b/libavformat/dvdclut.c new file mode 100644 index 0000000000..cd4b103e4b --- /dev/null +++ b/libavformat/dvdclut.c @@ -0,0 +1,75 @@ +/* + * DVD-Video subpicture CLUT (Color Lookup Table) utilities + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/bprint.h" +#include "libavutil/colorspace.h" +#include "libavutil/common.h" + +#include "dvdclut.h" +#include "internal.h" + +int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, + const size_t clut_size, + AVCodecParameters *par) +{ + AVBPrint bp; + + if (clut_size != FF_DVDCLUT_CLUT_SIZE) + return AVERROR(EINVAL); + + av_bprint_init(&bp, 0, FF_DVDCLUT_EXTRADATA_SIZE); + + av_bprintf(&bp, "palette: "); + + for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) + av_bprintf(&bp, "%06"PRIx32"%s", clut[i], + i != (FF_DVDCLUT_CLUT_LEN - 1) ? ", " : ""); + + av_bprintf(&bp, "\n"); + + return ff_bprint_to_codecpar_extradata(par, &bp); +} + +int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size) +{ + int y, cb, cr; + uint8_t r, g, b; + int r_add, g_add, b_add; + + if (clut_size != FF_DVDCLUT_CLUT_SIZE) + return AVERROR(EINVAL); + + for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) { + y = (clut[i] >> 16) & 0xFF; + cr = (clut[i] >> 8) & 0xFF; + cb = clut[i] & 0xFF; + + YUV_TO_RGB1_CCIR(cb, cr); + + y = (y - 16) * FIX(255.0 / 219.0); + r = av_clip_uint8((y + r_add - 1024) >> SCALEBITS); + g = av_clip_uint8((y + g_add - 1024) >> SCALEBITS); + b = av_clip_uint8((y + b_add - 1024) >> SCALEBITS); + + clut[i] = (r << 16) | (g << 8) | b; + } + + return 0; +} diff --git a/libavformat/dvdclut.h b/libavformat/dvdclut.h new file mode 100644 index 0000000000..41cea7e2c9 --- /dev/null +++ b/libavformat/dvdclut.h @@ -0,0 +1,37 @@ +/* + * DVD-Video subpicture CLUT (Color Lookup Table) utilities + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_DVDCLUT_H +#define AVFORMAT_DVDCLUT_H + +#include "libavcodec/codec_par.h" + +/* ("palette: ") + ("rrggbb, "*15) + ("rrggbb") + \n + \0 */ +#define FF_DVDCLUT_EXTRADATA_SIZE (9 + (8 * 15) + 6 + 1 + 1) +#define FF_DVDCLUT_CLUT_LEN 16 +#define FF_DVDCLUT_CLUT_SIZE FF_DVDCLUT_CLUT_LEN * sizeof(uint32_t) + +int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, + const size_t clut_size, + AVCodecParameters *par); + +int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size); + +#endif /* AVFORMAT_DVDCLUT_H */ diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c index ca85aa8d3d..6f626ce9a0 100644 --- a/libavformat/dvdvideodec.c +++ b/libavformat/dvdvideodec.c @@ -49,6 +49,7 @@ #include "avio_internal.h" #include "avlanguage.h" #include "demux.h" +#include "dvdclut.h" #include "internal.h" #include "url.h" @@ -95,6 +96,7 @@ typedef struct DVDVideoPGCSubtitleStreamEntry { int startcode; enum DVDVideoSubpictureViewport viewport; int disposition; + uint32_t clut[FF_DVDCLUT_CLUT_LEN]; const char *lang_iso; } DVDVideoPGCSubtitleStreamEntry; @@ -1040,6 +1042,8 @@ break_error: static int dvdvideo_subp_stream_analyze(AVFormatContext *s, uint32_t offset, subp_attr_t subp_attr, DVDVideoPGCSubtitleStreamEntry *entry) { + DVDVideoDemuxContext *c = s->priv_data; + char lang_dvd[3] = {0}; entry->startcode = 0x20 + (offset & 0x1F); @@ -1047,6 +1051,12 @@ static int dvdvideo_subp_stream_analyze(AVFormatContext *s, uint32_t offset, sub if (subp_attr.lang_extension == 9) entry->disposition |= AV_DISPOSITION_FORCED; + memcpy(&entry->clut, c->play_state.pgc->palette, FF_DVDCLUT_CLUT_SIZE); + + /* dvdsub palettes currently have no colorspace tagging and all muxers only support RGB */ + /* this is not a lossless conversion, but no use cases are supported for the original YUV */ + ff_dvdclut_yuv_to_rgb(entry->clut, FF_DVDCLUT_CLUT_SIZE); + AV_WB16(lang_dvd, subp_attr.lang_code); entry->lang_iso = ff_convert_lang_to(lang_dvd, AV_LANG_ISO639_2_BIBL); @@ -1058,6 +1068,7 @@ static int dvdvideo_subp_stream_add(AVFormatContext *s, DVDVideoPGCSubtitleStrea { AVStream *st; FFStream *sti; + int ret; st = avformat_new_stream(s, NULL); if (!st) @@ -1067,6 +1078,9 @@ static int dvdvideo_subp_stream_add(AVFormatContext *s, DVDVideoPGCSubtitleStrea st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_DVD_SUBTITLE; + if ((ret = ff_dvdclut_palette_extradata_cat(entry->clut, FF_DVDCLUT_CLUT_SIZE, st->codecpar)) < 0) + return ret; + if (entry->lang_iso) av_dict_set(&st->metadata, "language", entry->lang_iso, 0); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".