From: Ramiro Polla <ramiro.polla@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH] swscale/utils: split off format code into new file Date: Tue, 11 Mar 2025 00:03:28 +0100 Message-ID: <c6b08f9e-82cd-46e5-93d1-f47306395e39@gmail.com> (raw) In-Reply-To: <20250310151811.107728-1-ffmpeg@haasn.xyz> On 3/10/25 16:18, Niklas Haas wrote: > From: Niklas Haas <git@haasn.dev> > > utils.c is getting quite crowded, and I need a new place to dump a lot of > format handling code for the ongoing rewrite. Rather than bloating this file > even more, start splitting format handling helpers off into a new file. > > This also renames the existing utils.h header, which didn't really contain > anything except the SwsFormat definition anyway (the prototypes for what should > have been in utils.h are all still in the legacy swscale_internal.h). > --- > libswscale/Makefile | 1 + > libswscale/cms.c | 2 +- > libswscale/cms.h | 2 +- > libswscale/csputils.c | 2 +- > libswscale/format.c | 583 +++++++++++++++++++++++++++++++ > libswscale/{utils.h => format.h} | 6 +- > libswscale/graph.c | 2 +- > libswscale/graph.h | 2 +- > libswscale/lut3d.h | 2 +- > libswscale/utils.c | 559 ----------------------------- > 10 files changed, 593 insertions(+), 568 deletions(-) > create mode 100644 libswscale/format.c > rename libswscale/{utils.h => format.h} (98%) > > diff --git a/libswscale/format.c b/libswscale/format.c > new file mode 100644 > index 0000000000..89ed4eae6b > --- /dev/null > +++ b/libswscale/format.c > @@ -0,0 +1,583 @@ > +/* > + * Copyright (C) 2024 Niklas Haas > + * > + * 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/avassert.h" > +#include "libavutil/hdr_dynamic_metadata.h" > +#include "libavutil/mastering_display_metadata.h" > + > +#include "format.h" > + > +typedef struct FormatEntry { > + uint8_t is_supported_in :1; > + uint8_t is_supported_out :1; > + uint8_t is_supported_endianness :1; > +} FormatEntry; > + > +/* Format support table for legacy swscale */ > +static const FormatEntry format_entries[] = { > + [AV_PIX_FMT_YUV420P] = { 1, 1 }, [...] > + [AV_PIX_FMT_BAYER_RGGB8] = { 1, 0 }, > + [AV_PIX_FMT_BAYER_GBRG8] = { 1, 0 }, > + [AV_PIX_FMT_BAYER_GRBG8] = { 1, 0 }, > + [AV_PIX_FMT_BAYER_BGGR16LE] = { 1, 0 }, Perhaps you could vertically align this array while moving it. [...] > +/** > + * This function also sanitizes and strips the input data, removing irrelevant > + * fields for certain formats. > + */ > +SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field) > +{ > + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); > + const AVColorPrimariesDesc *primaries; > + AVFrameSideData *sd; > + > + SwsFormat fmt = { > + .width = frame->width, > + .height = frame->height, > + .format = frame->format, > + .range = frame->color_range, > + .csp = frame->colorspace, > + .loc = frame->chroma_location, > + .desc = desc, > + .color = { > + .prim = frame->color_primaries, > + .trc = frame->color_trc, > + }, > + }; > + > + av_assert1(fmt.width > 0); > + av_assert1(fmt.height > 0); > + av_assert1(fmt.format != AV_PIX_FMT_NONE); > + av_assert0(desc); > + if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_BAYER)) { > + /* RGB-like family */ > + fmt.csp = AVCOL_SPC_RGB; > + fmt.range = AVCOL_RANGE_JPEG; > + } else if (desc->flags & AV_PIX_FMT_FLAG_XYZ) { > + fmt.csp = AVCOL_SPC_UNSPECIFIED; > + fmt.range = AVCOL_RANGE_UNSPECIFIED; This line above was not in utils.c. Ramiro _______________________________________________ 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".
prev parent reply other threads:[~2025-03-10 23:03 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-10 15:18 Niklas Haas 2025-03-10 15:20 ` Niklas Haas 2025-03-10 23:03 ` Ramiro Polla [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c6b08f9e-82cd-46e5-93d1-f47306395e39@gmail.com \ --to=ramiro.polla@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git