From patchwork Fri Jul 1 09:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 36577 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp879747pzh; Fri, 1 Jul 2022 02:20:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sviYe6RwpfAPOkA12YcUfxwt//HrjbxkpxtQfVJ+xEWvKZ4krgWU3PB09JA9g7jywCzpEj X-Received: by 2002:a17:907:8a17:b0:726:35ac:b3ad with SMTP id sc23-20020a1709078a1700b0072635acb3admr13191459ejc.447.1656667248279; Fri, 01 Jul 2022 02:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656667248; cv=none; d=google.com; s=arc-20160816; b=asNJmFstGP5wJNq97azEZ1IZ86rqjV09G8eT20dYl40Qm9meFDRDg2yoLhTF0ZmhIJ s9HGbPHKcRss4Ewk0FA+Tsfa+CS56cG4sfQqgyBzEsFI1eLz77nkfjhJPHh8LpS0Cxdx MXZ5xU91B5UGyHVlqTflHFF0JD3fhqsN7FmYWZN5lJFJ/bJ/IjSRSX6QkDtt5KnkbfqR vnDIVDQjy9jIRa/Fluj2WJdoJ2vdqOIEdYFLOriC/Tn7CV7M4DjWLKnABXJVo2XV01in ZhJvBgbB7+oKdVVWKPAlMSbczSY26rQNP6vq9YPcCQqVvYcyW690u4TEkxNMzRqR0VlK ShrQ== 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=+1VFVspgzWzGlq1gkV/wjA7ZAfE8lvSnD6lFu0fMJh0=; b=JBcAo8KCI/aQl2n1ghX8eVsZKj/HD495Up8DJZzx1mThWOgt+ppMMc/J2eFotY2Y30 HiQKxtx7bZGlMZizQkFRi1kQiRSJhpOoij/0p/XIoRIbPsag5E87lyxxqqihrAbiF6jX j7FPFDlI44f7MCgBWTDXjUp5EtkWQfRe+3uYb9/V7Fjvutsx9HpUmJVthfEpYEXUb+dJ J42A5QSEewC/DcSErkq+2+9frq8MiedGARcLQo4BpPYyx86dpUGs4nW/V/wukLAIp7XO K0YotDrpBJ1OexCNa2RknaHaaQwDsVZKGG5Jg2VBBUHxzaLtngxlIDZMkF3W373zE6Vd JD3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=OUWvJL+Z; 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 du20-20020a17090772d400b0072a6be70d03si1712317ejc.461.2022.07.01.02.20.47; Fri, 01 Jul 2022 02:20:48 -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=OUWvJL+Z; 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 7069568B546; Fri, 1 Jul 2022 12:20:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7675268069F for ; Fri, 1 Jul 2022 12:20:36 +0300 (EEST) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-317710edb9dso18187797b3.0 for ; Fri, 01 Jul 2022 02:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=BjAPlX1j0J8DCLF+TBJelrULO405AQIXyQ8P/acgk0A=; b=OUWvJL+Z1SAWC6swEyd84oY3f0RttLRO9Ip1uC8dJ48emD9iMb5ueFiCj6eqx5VYWw XLG+fyBBVMEpe9mLlnCNOWHO/1x8mzmkqnQMp2Tt1fKfG6Pknx4H3Vm9z29LtgPzTgGG yieEz4eKVEQhcChng9f6M8MS7KKGTT+f0GK+Z1JLrR2IluEMmUfZpLbuANMgxWnz5xH6 +OYo5LXghGm1iNYsxE3iAyDXE/U1vT+WGb3GPzMNVdhrQnA8sMtE28ihbDpTvAlJBoE5 i1xrpNnTXLsEZMn79Prrbzx4uLuuhJdy4x0Hcn1J+VV/sZa5qotuXG2Fp2kxUOn7QkVm VqgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=BjAPlX1j0J8DCLF+TBJelrULO405AQIXyQ8P/acgk0A=; b=fLrJ4Aw2GgB3lT2pqZr2L1k1DGeYcpJOjutJiVwj5YLp9l5Xr64oOjxgCdtFbH6fJD U7obYkjlbjWPb3Ra2SOXKpIRh7CTXI4kh2JnFfmiOf8x2JJ+Bp32Ee6SoLeJkTxGVSqV WXKlDytux8UsY/2W3xI21pruHsArDzU9F0XVH/OB5Io4vqYx8xqBRz6UA84w1DuzlbyF T1HqJwmScnCe3dTcrjXtw1/SqlkHRx9rxHIBdiTJd9btHPjBnwO8fRFl52KXjwaR+KoL a+nLFsXmU0LS7cZeLPYtCP3rsBqpCmNMIOz1oXIbjiWaH33VXcSnKDyxH7+zcMdg6iYj CWQA== X-Gm-Message-State: AJIora/x9hdEntDwOEpcdFHJ6UQF55NeYX5Ln1bBcJfiG8veyq51EL+Q Tojy0ItNq2aByH434Iszb4R8smGcnK4+dBHodj8lYU2hFXY= X-Received: by 2002:a81:750a:0:b0:317:da37:4f2d with SMTP id q10-20020a81750a000000b00317da374f2dmr15655318ywc.124.1656667235182; Fri, 01 Jul 2022 02:20:35 -0700 (PDT) MIME-Version: 1.0 From: Paul B Mahol Date: Fri, 1 Jul 2022 11:23:20 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avcodec: add PHM decoder and encoder 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: mmTMnEyLPcg3 Hello, patch attached. From cec6259e75fa56a4b064f7d5a0823449d19f3b47 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 1 Jul 2022 10:06:15 +0200 Subject: [PATCH] avcodec: add PHM decoder and encoder Signed-off-by: Paul B Mahol --- libavcodec/Makefile | 2 + libavcodec/allcodecs.c | 2 + libavcodec/codec_desc.c | 7 +++ libavcodec/codec_id.h | 1 + libavcodec/pnm.c | 10 +++- libavcodec/pnm.h | 5 ++ libavcodec/pnm_parser.c | 3 +- libavcodec/pnmdec.c | 114 ++++++++++++++++++++++++++++++++++++++++ libavcodec/pnmenc.c | 75 +++++++++++++++++++++++++- libavformat/img2.c | 1 + libavformat/img2enc.c | 2 +- 11 files changed, 217 insertions(+), 5 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 050934101c..457ec58377 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -571,6 +571,8 @@ OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o OBJS-$(CONFIG_PGMYUV_ENCODER) += pnmenc.o OBJS-$(CONFIG_PGSSUB_DECODER) += pgssubdec.o OBJS-$(CONFIG_PGX_DECODER) += pgxdec.o +OBJS-$(CONFIG_PHM_DECODER) += pnmdec.o pnm.o +OBJS-$(CONFIG_PHM_ENCODER) += pnmenc.o OBJS-$(CONFIG_PHOTOCD_DECODER) += photocd.o OBJS-$(CONFIG_PICTOR_DECODER) += pictordec.o cga_data.o OBJS-$(CONFIG_PIXLET_DECODER) += pixlet.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index f0b01051b0..bdfc2f6f45 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -254,6 +254,8 @@ extern const FFCodec ff_pgm_decoder; extern const FFCodec ff_pgmyuv_encoder; extern const FFCodec ff_pgmyuv_decoder; extern const FFCodec ff_pgx_decoder; +extern const FFCodec ff_phm_encoder; +extern const FFCodec ff_phm_decoder; extern const FFCodec ff_photocd_decoder; extern const FFCodec ff_pictor_decoder; extern const FFCodec ff_pixlet_decoder; diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index e2c1c67f5e..44ad2d1fe8 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1886,6 +1886,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("QOI (Quite OK Image)"), .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, }, + { + .id = AV_CODEC_ID_PHM, + .type = AVMEDIA_TYPE_VIDEO, + .name = "phm", + .long_name = NULL_IF_CONFIG_SMALL("PHM (Portable HalfFloatMap) image"), + .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 93856a16f2..81fb316cff 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -311,6 +311,7 @@ enum AVCodecID { AV_CODEC_ID_VBN, AV_CODEC_ID_JPEGXL, AV_CODEC_ID_QOI, + AV_CODEC_ID_PHM, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index 958f2a342e..5d67e78e36 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -73,7 +73,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) (s->bytestream[1] < '1' || s->bytestream[1] > '7' && s->bytestream[1] != 'f' && - s->bytestream[1] != 'F')) { + s->bytestream[1] != 'F' && + s->bytestream[1] != 'H' && + s->bytestream[1] != 'h')) { s->bytestream += s->bytestream_end > s->bytestream; s->bytestream += s->bytestream_end > s->bytestream; return AVERROR_INVALIDDATA; @@ -85,6 +87,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) avctx->pix_fmt = AV_PIX_FMT_GBRPF32; } else if (buf1[1] == 'f') { avctx->pix_fmt = AV_PIX_FMT_GRAYF32; + } else if (buf1[1] == 'H') { + avctx->pix_fmt = AV_PIX_FMT_GBRPF32; + s->half = 1; + } else if (buf1[1] == 'h') { + avctx->pix_fmt = AV_PIX_FMT_GRAYF32; + s->half = 1; } else if (s->type==1 || s->type==4) { avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; } else if (s->type==2 || s->type==5) { diff --git a/libavcodec/pnm.h b/libavcodec/pnm.h index 89c3b5a2da..f109d16239 100644 --- a/libavcodec/pnm.h +++ b/libavcodec/pnm.h @@ -31,7 +31,12 @@ typedef struct PNMContext { int maxval; ///< maximum value of a pixel int type; int endian; + int half; float scale; + + uint32_t mantissatable[2048]; + uint32_t exponenttable[64]; + uint16_t offsettable[64]; } PNMContext; int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c index 309bc76a24..928b6dcd21 100644 --- a/libavcodec/pnm_parser.c +++ b/libavcodec/pnm_parser.c @@ -133,7 +133,8 @@ end: const AVCodecParser ff_pnm_parser = { .codec_ids = { AV_CODEC_ID_PGM, AV_CODEC_ID_PGMYUV, AV_CODEC_ID_PPM, - AV_CODEC_ID_PBM, AV_CODEC_ID_PAM, AV_CODEC_ID_PFM }, + AV_CODEC_ID_PBM, AV_CODEC_ID_PAM, AV_CODEC_ID_PFM, + AV_CODEC_ID_PHM }, .priv_data_size = sizeof(PNMParseContext), .parser_parse = pnm_parse, .parser_close = ff_parse_close, diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index f2d9b7e4b6..bb2ce53496 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -26,6 +26,7 @@ #include "internal.h" #include "put_bits.h" #include "pnm.h" +#include "half2float.h" static void samplecpy(uint8_t *dst, const uint8_t *src, int n, int maxval) { @@ -258,6 +259,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, } break; case AV_PIX_FMT_GBRPF32: + if (!s->half) { if (avctx->width * avctx->height * 12 > s->bytestream_end - s->bytestream) return AVERROR_INVALIDDATA; scale = 1.f / s->scale; @@ -298,8 +300,68 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, b += p->linesize[1] / 4; } } + } else { + if (avctx->width * avctx->height * 6 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + scale = 1.f / s->scale; + if (s->endian) { + float *r, *g, *b; + + r = (float *)p->data[2]; + g = (float *)p->data[0]; + b = (float *)p->data[1]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + r[j] = av_int2float(half2float(AV_RL16(s->bytestream+0), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + g[j] = av_int2float(half2float(AV_RL16(s->bytestream+2), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + b[j] = av_int2float(half2float(AV_RL16(s->bytestream+4), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + s->bytestream += 6; + } + + r += p->linesize[2] / 4; + g += p->linesize[0] / 4; + b += p->linesize[1] / 4; + } + } else { + float *r, *g, *b; + + r = (float *)p->data[2]; + g = (float *)p->data[0]; + b = (float *)p->data[1]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + r[j] = av_int2float(half2float(AV_RB16(s->bytestream+0), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + g[j] = av_int2float(half2float(AV_RB16(s->bytestream+2), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + b[j] = av_int2float(half2float(AV_RB16(s->bytestream+4), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + s->bytestream += 6; + } + + r += p->linesize[2] / 4; + g += p->linesize[0] / 4; + b += p->linesize[1] / 4; + } + } } break; case AV_PIX_FMT_GRAYF32: + if (!s->half) { if (avctx->width * avctx->height * 4 > s->bytestream_end - s->bytestream) return AVERROR_INVALIDDATA; scale = 1.f / s->scale; @@ -322,6 +384,36 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, g += p->linesize[0] / 4; } } + } else { + if (avctx->width * avctx->height * 2 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + scale = 1.f / s->scale; + if (s->endian) { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(half2float(AV_RL16(s->bytestream), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + s->bytestream += 2; + } + g += p->linesize[0] / 4; + } + } else { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(half2float(AV_RB16(s->bytestream), + s->mantissatable, + s->exponenttable, + s->offsettable)) * scale; + s->bytestream += 2; + } + g += p->linesize[0] / 4; + } + } + } break; } *got_frame = 1; @@ -401,3 +493,25 @@ const FFCodec ff_pfm_decoder = { FF_CODEC_DECODE_CB(pnm_decode_frame), }; #endif + +#if CONFIG_PHM_DECODER +static av_cold int phm_dec_init(AVCodecContext *avctx) +{ + PNMContext *s = avctx->priv_data; + + half2float_table(s->mantissatable, s->exponenttable, s->offsettable); + + return 0; +} + +const FFCodec ff_phm_decoder = { + .p.name = "phm", + .p.long_name = NULL_IF_CONFIG_SMALL("PHM (Portable HalfFloatMap) image"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_PHM, + .p.capabilities = AV_CODEC_CAP_DR1, + .priv_data_size = sizeof(PNMContext), + .init = phm_dec_init, + FF_CODEC_DECODE_CB(pnm_decode_frame), +}; +#endif diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c index c1820ac79e..258d919d32 100644 --- a/libavcodec/pnmenc.c +++ b/libavcodec/pnmenc.c @@ -27,10 +27,17 @@ #include "avcodec.h" #include "codec_internal.h" #include "encode.h" +#include "float2half.h" + +typedef struct PHMEncContext { + uint16_t basetable[512]; + uint8_t shifttable[512]; +} PHMEncContext; static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet) { + PHMEncContext *s = avctx->priv_data; uint8_t *bytestream, *bytestream_start, *bytestream_end; int i, h, h1, c, n, linesize, ret; uint8_t *ptr, *ptr1, *ptr2; @@ -82,12 +89,22 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, h1 = (h * 3) / 2; break; case AV_PIX_FMT_GBRPF32: + if (avctx->codec_id == AV_CODEC_ID_PFM) { c = 'F'; n = avctx->width * 4; + } else { + c = 'H'; + n = avctx->width * 2; + } break; case AV_PIX_FMT_GRAYF32: + if (avctx->codec_id == AV_CODEC_ID_PFM) { c = 'f'; n = avctx->width * 4; + } else { + c = 'h'; + n = avctx->width * 2; + } break; default: return -1; @@ -110,7 +127,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytestream += strlen(bytestream); } - if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32) { + if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32 && c == 'F') { float *r = (float *)p->data[2]; float *g = (float *)p->data[0]; float *b = (float *)p->data[1]; @@ -127,7 +144,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, g += p->linesize[0] / 4; b += p->linesize[1] / 4; } - } else if (avctx->pix_fmt == AV_PIX_FMT_GRAYF32) { + } else if (avctx->pix_fmt == AV_PIX_FMT_GRAYF32 && c == 'f') { const float *g = (const float *)p->data[0]; for (int i = 0; i < avctx->height; i++) { @@ -136,6 +153,34 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytestream += 4; } + g += p->linesize[0] / 4; + } + } else if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32 && c == 'H') { + float *r = (float *)p->data[2]; + float *g = (float *)p->data[0]; + float *b = (float *)p->data[1]; + + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + AV_WN16(bytestream + 0, float2half(av_float2int(r[j]), s->basetable, s->shifttable)); + AV_WN16(bytestream + 2, float2half(av_float2int(g[j]), s->basetable, s->shifttable)); + AV_WN16(bytestream + 4, float2half(av_float2int(b[j]), s->basetable, s->shifttable)); + bytestream += 6; + } + + r += p->linesize[2] / 4; + g += p->linesize[0] / 4; + b += p->linesize[1] / 4; + } + } else if (avctx->pix_fmt == AV_PIX_FMT_GRAYF32 && c == 'h') { + const float *g = (const float *)p->data[0]; + + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + AV_WN16(bytestream, float2half(av_float2int(g[j]), s->basetable, s->shifttable)); + bytestream += 2; + } + g += p->linesize[0] / 4; } } else { @@ -241,3 +286,29 @@ const FFCodec ff_pfm_encoder = { .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif + +#if CONFIG_PHM_ENCODER +static av_cold int phm_enc_init(AVCodecContext *avctx) +{ + PHMEncContext *s = avctx->priv_data; + + float2half_tables(s->basetable, s->shifttable); + + return 0; +} + +const FFCodec ff_phm_encoder = { + .p.name = "phm", + .p.long_name = NULL_IF_CONFIG_SMALL("PHM (Portable HalfFloatMap) image"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_PHM, + .p.capabilities = AV_CODEC_CAP_DR1, + .priv_data_size = sizeof(PHMEncContext), + .init = phm_enc_init, + FF_CODEC_ENCODE_CB(pnm_encode_frame), + .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_GBRPF32, + AV_PIX_FMT_GRAYF32, + AV_PIX_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +}; +#endif diff --git a/libavformat/img2.c b/libavformat/img2.c index 68cb7de2c1..870d2ebbc5 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -41,6 +41,7 @@ const IdStrMap ff_img_tags[] = { { AV_CODEC_ID_PBM, "pbm" }, { AV_CODEC_ID_PAM, "pam" }, { AV_CODEC_ID_PFM, "pfm" }, + { AV_CODEC_ID_PHM, "phm" }, { AV_CODEC_ID_CRI, "cri" }, { AV_CODEC_ID_ALIAS_PIX, "pix" }, { AV_CODEC_ID_DDS, "dds" }, diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index b3a0801ec9..0a11fae34e 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -265,7 +265,7 @@ static const AVClass img2mux_class = { const AVOutputFormat ff_image2_muxer = { .name = "image2", .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), - .extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv," + .extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm," "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8," "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi", .priv_data_size = sizeof(VideoMuxData), -- 2.36.1