From patchwork Wed Jun 9 17:25:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Fleurbaaij X-Patchwork-Id: 28185 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp1027094iol; Wed, 9 Jun 2021 10:26:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3uPJ92SB8OVfRp89pi2eN9pWvfHU3TRnolHZhrk+/8mA2/2TY9QsMtoPh6DycsO0tqLku X-Received: by 2002:a17:906:3181:: with SMTP id 1mr954833ejy.36.1623259565258; Wed, 09 Jun 2021 10:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259565; cv=none; d=google.com; s=arc-20160816; b=vkDLRG8+plYS7bOURog8HJDm9ZZXh6UvoG6/GhCLIoCrBZWjOCg+Z8T2RRsCoZctWC Ua7RyhgQ2gqYyKCuZVNAXa+BCiKmYY9aDoft4Ti9U+EWREzscaPEmTNjseimnoTtHcyQ C4yubKM+xPXpQhFn/rePcxAboo1X9Bt81RHHLCT/WI+DUfNmfPWIcBx9OkTmUJf+p8bu MAeUpss0LHJOb9yDNGwyGrt0TaR5eh9ilYUm56Ph77ERSCDFFwLdfLnFdDQRDKbNwizh 7xjtiZPBogBjUVeFKRaZWmgWfs1MVjMQn3sAJQCvKX1KOInzhvi7a1yBumGT9M4RQvim afDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=m26AUqBtkLxEkrsnydWf7umBC2ro7X54KG1nmgoo3Z0=; b=LPXQimgD3P6LFvP4zyGKdbVQoH0pFd5GOFcFlYidrTVQ7aX8apS/DKOE5+SLm3Eu4A wNr9+90ULeVLfjusxIXcCPyvaLsgLPWQXUlr4qa72MoIy19t9/7yMx8r6+y+thmnvr1L uG//fPnRGUnpb/1F9whC+eGNKjxe+RLNyrgnIWeWU22FX97U5Mlg/wuUlP+HDdH0NemC 0pQSro3A/pG8uoWz9fTatJl3r8Z9OBnDiZEBXpq3mGDtCqbiLMtVqM+fmSv0pDmpBhQs 4tD3dtVC4ejb66jewC7/D+tu50/fUccXLyldiBB0EYA2N0u0VqTtpOeZmcdRssV0BaxN VE6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@dennisfleurbaaij-com.20150623.gappssmtp.com header.s=20150623 header.b=SEtDrrCP; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c19si335698ejj.584.2021.06.09.10.26.04; Wed, 09 Jun 2021 10:26:05 -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=@dennisfleurbaaij-com.20150623.gappssmtp.com header.s=20150623 header.b=SEtDrrCP; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22A8D6802E4; Wed, 9 Jun 2021 20:26:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5101D6802E4 for ; Wed, 9 Jun 2021 20:25:53 +0300 (EEST) Received: by mail-ot1-f42.google.com with SMTP id 6-20020a9d07860000b02903e83bf8f8fcso11658620oto.12 for ; Wed, 09 Jun 2021 10:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dennisfleurbaaij-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=v7E7N93YCGczSlK9YPJ3gnyOlQrbaNOGk2hnQZ7W7b8=; b=SEtDrrCPhGos2NES3FiB2ZWq0PKRmXQgGfyS4Rh62YbEPEkCMkpwckwkAdVrQ0h9at MIC385AXfKmg60+RctjuqMrOngQt7j1ypKHAiMrIt9BiAlFV/wv3LMx64lj2ppR6VyHE iBkj0yleG/LLGndzzkGOZIlNqZxqXpHKVfaN2M/8dDRcCi5I/ovt6fNd2Jk1NjhUqv/8 j6mOWa7QhbvGbnPyeQQN6bSF+EbbqsQQ7miH22ailgWDnk4qmImF2D33O816RA8q29NH vY0hWyE5NV6orJQkqwbpib5pzB6MnC5M6E8Wt4uXP0GcqTA44xd8koFUjl4b0I3SKeRQ OkFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=v7E7N93YCGczSlK9YPJ3gnyOlQrbaNOGk2hnQZ7W7b8=; b=G8G7FEjqIlOWOHrQR/FUqpvVP+oZCiBz/3ZnPim4wyCbem+zhdDJREqQg8gtTD513t nT1yVMWthlKCVATciX1Xe0/0bu48nejEc18btLLNYxdpuo3CRdbrgI5nepqZofPi4iP9 KQ9cXYrZqi4hdDPjuWKbSKQjF4UF+xaTQzTBwqR1L4GCBslMccVSAMOPynM+6dnNVhg9 ANqMQGRC36ep0c04JNn8qxFsDtdD5DojQlgpSkLo+SwvbXM6bDzUR2bEdOLKymRzhHth c6Nr88CxZRfut2PgpqoX+iH1QY9+4g19bkTaA+S7UAm5S1JQ5iHlQIFXW3aFclhpCTzO c3kA== X-Gm-Message-State: AOAM530Kp6N1byHXHTssDAA5W8xj7Dv/IDrr3opZtprFNUy9bP0RBxca 97TSX64urJI+5zY0DfCDLrTXWqsU5Q0fq5F3bbtlY7g/W+pQ5ztB X-Received: by 2002:a9d:74c2:: with SMTP id a2mr432379otl.324.1623259551366; Wed, 09 Jun 2021 10:25:51 -0700 (PDT) MIME-Version: 1.0 From: Dennis Fleurbaaij Date: Wed, 9 Jun 2021 19:25:41 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] libavcodec: r12b decoder + r12b fourcc 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vBJP5N5rCI4N By request of Carl Eugen here is the r12b decoder and the fourcc proposal in 2 different patches so you can pick which ones are acceptable. Kind regards, Dennis Fleurbaaij From 0d2243a6b566b17e7f669efb65f5398971964146 Mon Sep 17 00:00:00 2001 From: Dennis Fleurbaaij Date: Wed, 9 Jun 2021 19:20:29 +0200 Subject: [PATCH 1/2] libavcodec: r12b decoder added R12B is a format used by BlackMagic DeckLink cards, it is a big-endian 12bpp RGB format which packs 8 pixels into 36 bytes. Signed-off-by: Dennis Fleurbaaij Signed-off-by: Dennis Fleurbaaij --- Changelog | 1 + libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/codec_desc.c | 7 ++ libavcodec/codec_id.h | 1 + libavcodec/r12bdec.c | 141 ++++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 4 +- 7 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 libavcodec/r12bdec.c diff --git a/Changelog b/Changelog index b9d5188cf6..d0717072eb 100644 --- a/Changelog +++ b/Changelog @@ -7,6 +7,7 @@ version : - ADPCM IMA Acorn Replay decoder - Argonaut Games CVG demuxer - Argonaut Games CVG muxer +- r12b decoder version 4.4: diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 4fa8d7ab10..cfef9d57ff 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -575,6 +575,7 @@ OBJS-$(CONFIG_QTRLE_ENCODER) += qtrleenc.o OBJS-$(CONFIG_R10K_DECODER) += r210dec.o OBJS-$(CONFIG_R10K_ENCODER) += r210enc.o OBJS-$(CONFIG_R210_DECODER) += r210dec.o +OBJS-$(CONFIG_R12B_DECODER) += r12bdec.o OBJS-$(CONFIG_R210_ENCODER) += r210enc.o OBJS-$(CONFIG_RA_144_DECODER) += ra144dec.o ra144.o celp_filters.o OBJS-$(CONFIG_RA_144_ENCODER) += ra144enc.o ra144.o celp_filters.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 623db2a9fa..8db7e730a6 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -266,6 +266,7 @@ extern const AVCodec ff_qtrle_encoder; extern const AVCodec ff_qtrle_decoder; extern const AVCodec ff_r10k_encoder; extern const AVCodec ff_r10k_decoder; +extern const AVCodec ff_r12b_decoder; extern const AVCodec ff_r210_encoder; extern const AVCodec ff_r210_decoder; extern const AVCodec ff_rasc_decoder; diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 35527dcc37..ef58d73576 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1856,6 +1856,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("Digital Pictures SGA Video"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_R12B, + .type = AVMEDIA_TYPE_VIDEO, + .name = "r12b", + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 12-bit 8px in 36B"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, + }, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 83e1dbb4b3..ecfdbc46c0 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -306,6 +306,7 @@ enum AVCodecID { AV_CODEC_ID_CRI, AV_CODEC_ID_SIMBIOSIS_IMX, AV_CODEC_ID_SGA_VIDEO, + AV_CODEC_ID_R12B, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/r12bdec.c b/libavcodec/r12bdec.c new file mode 100644 index 0000000000..986f96e687 --- /dev/null +++ b/libavcodec/r12bdec.c @@ -0,0 +1,141 @@ +/* + * r12b decoder + * + * Copyright (c) 2021 Dennis Fleurbaaij + * + * 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 "avcodec.h" +#include "internal.h" + +#define WORDS_PER_BLOCK 9 +#define PIXELS_PER_BLOCK 8 +#define BYTES_PER_BLOCK 36 + +static av_cold int decode_init(AVCodecContext *avctx) +{ + avctx->pix_fmt = AV_PIX_FMT_GBRP12LE; + avctx->bits_per_raw_sample = 12; + + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, + AVPacket *avpkt) +{ + int ret; + uint8_t *g_line, *b_line, *r_line; + + AVFrame *pic = data; + const uint8_t* src = avpkt->data; + const int blocks_per_line = avctx->width / PIXELS_PER_BLOCK; + + if (avctx->width % PIXELS_PER_BLOCK != 0) { + av_log(avctx, AV_LOG_ERROR, "image width not modulo 8\n"); + return AVERROR_INVALIDDATA; + } + + if (avpkt->size < avctx->height * blocks_per_line * BYTES_PER_BLOCK) { + av_log(avctx, AV_LOG_ERROR, "packet too small\n"); + return AVERROR_INVALIDDATA; + } + + pic->pict_type = AV_PICTURE_TYPE_I; + pic->key_frame = 1; + + if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) + return ret; + + g_line = pic->data[0]; + b_line = pic->data[1]; + r_line = pic->data[2]; + + for (int h = 0; h < avctx->height; h++) { + uint16_t *g_dst = (uint16_t *)g_line; + uint16_t *b_dst = (uint16_t *)b_line; + uint16_t *r_dst = (uint16_t *)r_line; + + for (int w = 0; w < blocks_per_line; w++) { + + // This is an encoding from the table on page 213 of the BlackMagic + // Decklink SDK pdf, version 12.0. Few helper defines to directly link + // the naming in the doc to the code. + + #define GET_FF(word, byte) (*(src + ((word * 4) + byte))) + #define GET_0F(word, byte) (GET_FF(word, byte) & 0x0F) + #define GET_F0(word, byte) (GET_FF(word, byte) >> 4) + #define PUT(dst, pixel) (*(dst + pixel)) + + PUT(b_dst, 0) = GET_FF(0, 0) | GET_0F(1, 3) << 8; + PUT(g_dst, 0) = GET_F0(0, 2) | GET_FF(0, 1) << 4; + PUT(r_dst, 0) = GET_FF(0, 3) | GET_0F(0, 2) << 8; + + PUT(b_dst, 1) = GET_F0(1, 0) | GET_FF(2, 3) << 4; + PUT(g_dst, 1) = GET_FF(1, 1) | GET_0F(1, 0) << 8; + PUT(r_dst, 1) = GET_F0(1, 3) | GET_FF(1, 2) << 4; + + PUT(b_dst, 2) = GET_FF(3, 3) | GET_0F(3, 2) << 8; + PUT(g_dst, 2) = GET_F0(2, 1) | GET_FF(2, 0) << 4; + PUT(r_dst, 2) = GET_FF(2, 2) | GET_0F(2, 1) << 8; + + PUT(b_dst, 3) = GET_F0(4, 3) | GET_FF(4, 2) << 4; + PUT(g_dst, 3) = GET_FF(3, 0) | GET_0F(4, 3) << 8; + PUT(r_dst, 3) = GET_F0(3, 2) | GET_FF(3, 1) << 4; + + PUT(b_dst, 4) = GET_FF(5, 2) | GET_0F(5, 1) << 8; + PUT(g_dst, 4) = GET_F0(4, 0) | GET_FF(5, 3) << 4; + PUT(r_dst, 4) = GET_FF(4, 1) | GET_0F(4, 0) << 8; + + PUT(b_dst, 5) = GET_F0(6, 2) | GET_FF(6, 1) << 4; + PUT(g_dst, 5) = GET_FF(6, 3) | GET_0F(6, 2) << 8; + PUT(r_dst, 5) = GET_F0(5, 1) | GET_FF(5, 0) << 4; + + PUT(b_dst, 6) = GET_FF(7, 1) | GET_0F(7, 0) << 8; + PUT(g_dst, 6) = GET_F0(7, 3) | GET_FF(7, 2) << 4; + PUT(r_dst, 6) = GET_FF(6, 0) | GET_0F(7, 3) << 8; + + PUT(b_dst, 7) = GET_F0(8, 1) | GET_FF(8, 0) << 4; + PUT(g_dst, 7) = GET_FF(8, 2) | GET_0F(8, 1) << 8; + PUT(r_dst, 7) = GET_F0(7, 0) | GET_FF(8, 3) << 4; + + src += BYTES_PER_BLOCK; + b_dst += PIXELS_PER_BLOCK; + g_dst += PIXELS_PER_BLOCK; + r_dst += PIXELS_PER_BLOCK; + } + + g_line += pic->linesize[0]; + b_line += pic->linesize[1]; + r_line += pic->linesize[2]; + } + + *got_frame = 1; + + return avpkt->size; +} + +const AVCodec ff_r12b_decoder = { + .name = "r12b", + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 12-bit 8px in 36B"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_R12B, + .init = decode_init, + .decode = decode_frame, + .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +}; diff --git a/libavcodec/version.h b/libavcodec/version.h index 5b1e9e77f3..1288cecebe 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,8 +28,8 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 59 -#define LIBAVCODEC_VERSION_MINOR 1 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MINOR 2 +#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \