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 ESMTPS id 9C92F4BDC6 for ; Wed, 5 Mar 2025 20:45:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A099B68DDC3; Wed, 5 Mar 2025 22:44:37 +0200 (EET) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C4F868D6E9 for ; Wed, 5 Mar 2025 22:44:31 +0200 (EET) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2fecba90cc3so10784026a91.2 for ; Wed, 05 Mar 2025 12:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741207469; x=1741812269; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=147Op1CiFK+9zNSZiXC5bNB5w0eR33MZ5DuoWbjguuw=; b=CcBBOgARudGcwbU0WPce8BkBjTeCzePyHU5gPWr/Izjf8KqYDriM1782BmgEdCY8wZ cbPbgdBFS9JZ4KB66UeaDw6SiUCbG9BLrhZSWlQXyH3nrgVq0DaFAdvcYEFZtGeC515R V7z/q0tmOQ3BJ/m9huY7PoPNt2LEqIYuo50gMxX38hTPgjQGdm+9jCrlog6NW/Hsrigu NPGbtuO0fe59ImLoe4uResQDUbj+6aczQndOqr2/Mx5Tj426Y2zIFnnTQ0u68IzR78Ph d/0MtTzkaVNjF9y6jzmc771p/qQ+9yG8GA6TniBMh/zT3zo9F8Yz7COqrPC5KprXjDOI 3PnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741207469; x=1741812269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=147Op1CiFK+9zNSZiXC5bNB5w0eR33MZ5DuoWbjguuw=; b=TVsBY6m8xSE30yBKHffTP9vNnp329ZKfyZhEH+YwtnfBd0G1WtGV7pLWROR5q1Rc7s WAcai+8iCxa/PU6sEqAcPfR7Dv7/zN4MpiAvFLDJMVr9tj4D7IbBcJCHUV6b4X9B0xKs naJ9/hRIppp97jrmqkpmJvFFGqZOrq9A/Q81NTUbEuWctvAkvzD71gnbp7LF1/BO/Zxa 1xr1CaxRnza6Wgg3Pe71aGJXTFrdC653+FmRk7+9GJ/28MO4FA3iZ5heCqGcp5SritLb J6Etkj9FfqxS7c+GlK5Ta95e7xWlaA6hbtrbwboZichZ83HjTHxAtKAUIPPQgIIaSCx9 W0dw== X-Gm-Message-State: AOJu0YxZYv3782OU2HtzndvYcj9RWtXuf+wrxUlC4L7upJZ2e9K8xcJL vUFlEcV96qoovx4knsFd9QcYfJYSntIOHg/ljSSjSE756XnzvhEGDxfnNQ== X-Gm-Gg: ASbGnctJkdAgYhA0AByF0k4u+xxsGrB7+O0i9qGVNeB8kxOGSA9pl8p3564Mg0pc9Kt s1UR0z7UuciJdo4tDD27fYqM1Z46FBytn8jmJoUD3go9+J3ENDQglslNeQZqRlvKWlp/CwfE3JM nJ8b5RflOQaR3Ij9FEQR3HAFEi789WLgTUmJfo0gTmkn5my+4xm8hI1skghjsm2HSHkgyo/9id/ AdYQ9RqEXrv8Gw2WkfW1eDekDtFk1MUaA6V5A1CrpcB+xLPVuYJX+3ZthiawRP7/5xSOkdXw8l/ vA8cxDXok41IMTRw0vznsv47HywZv4HIoXPu6z8uW/BfXUqEZm102aJCVgYx X-Google-Smtp-Source: AGHT+IHU0Jl08T3QugVKuXnk7OjwQ+vSyy0lH4LkMa44cuwR8dkPfe+P0MYJ/ve3fgAvdigQjLxYEQ== X-Received: by 2002:a17:90b:39cd:b0:2fe:a515:4a98 with SMTP id 98e67ed59e1d1-2ff4982eb59mr6542205a91.31.1741207468885; Wed, 05 Mar 2025 12:44:28 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:d959:d427:c88a:cc02]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7bdac8sm1771083a91.42.2025.03.05.12.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 12:44:28 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Mar 2025 17:44:13 -0300 Message-ID: <20250305204413.36950-3-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305204413.36950-1-jamrial@gmail.com> References: <20250305204413.36950-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/exr: use luma+alpha float pixel formats 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 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: James Almer --- libavcodec/exr.c | 71 +++++++------------- tests/ref/fate/exr-ya-scanline-zip-half-12x8 | 2 +- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/libavcodec/exr.c b/libavcodec/exr.c index 3eed4b3c87..312d8fd6e1 100644 --- a/libavcodec/exr.c +++ b/libavcodec/exr.c @@ -1353,82 +1353,67 @@ static int decode_block(AVCodecContext *avctx, void *tdata, data_yoffset = FFABS(FFMIN(0, line)); data_window_offset = (data_yoffset * td->channel_line_size) + data_xoffset; + if (s->channel_offsets[3] >= 0) + channel_buffer[3] = src + (td->xsize * s->channel_offsets[3]) + data_window_offset; if (!s->is_luma) { channel_buffer[0] = src + (td->xsize * s->channel_offsets[0]) + data_window_offset; channel_buffer[1] = src + (td->xsize * s->channel_offsets[1]) + data_window_offset; channel_buffer[2] = src + (td->xsize * s->channel_offsets[2]) + data_window_offset; rgb_channel_count = 3; - } else { /* put y data in the first channel_buffer */ + } else { /* put y data in the first channel_buffer and if needed, alpha in the second */ channel_buffer[0] = src + (td->xsize * s->channel_offsets[1]) + data_window_offset; + if (!(s->desc->flags & AV_PIX_FMT_FLAG_PLANAR)) + channel_buffer[1] = channel_buffer[3]; rgb_channel_count = 1; } - if (s->channel_offsets[3] >= 0) - channel_buffer[3] = src + (td->xsize * s->channel_offsets[3]) + data_window_offset; - if (s->desc->flags & AV_PIX_FMT_FLAG_PLANAR || s->desc->nb_components == 1 ) { - /* todo: change this when a floating point pixel format with luma with alpha is implemented */ - int channel_count = s->channel_offsets[3] >= 0 ? 4 : rgb_channel_count; - if (s->is_luma) { - channel_buffer[1] = channel_buffer[0]; - channel_buffer[2] = channel_buffer[0]; - } - - for (c = 0; c < channel_count; c++) { + if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) { + for (c = 0; c < s->desc->nb_components; c++) { int plane = s->desc->comp[c].plane; - ptr = p->data[plane] + window_ymin * p->linesize[plane] + (window_xmin * step); + ptr = p->data[plane] + window_ymin * p->linesize[plane] + (window_xmin * step) + s->desc->comp[c].offset; for (i = 0; i < ysize; i++, ptr += p->linesize[plane]) { - const uint8_t *src; + const uint8_t *src = channel_buffer[c]; + + // Zero out the start if xmin is not 0 + if (s->desc->flags & AV_PIX_FMT_FLAG_PLANAR || !c) + memset(ptr, 0, bxmin); if (s->pixel_type == EXR_FLOAT || s->compression == EXR_DWAA || s->compression == EXR_DWAB) { // 32-bit - union av_intfloat32 *ptr_x; - - src = channel_buffer[c]; - ptr_x = (union av_intfloat32 *)ptr; - - // Zero out the start if xmin is not 0 - memset(ptr_x, 0, bxmin); - ptr_x += window_xoffset; - union av_intfloat32 t; + if (trc_func && c < 3) { - for (x = 0; x < xsize; x++) { + for (x = window_xoffset; x < xsize + window_xoffset; x++) { t.i = bytestream_get_le32(&src); t.f = trc_func(t.f); - *ptr_x++ = t; + AV_WN32(ptr + x * step, t.i); } } else if (one_gamma != 1.f) { - for (x = 0; x < xsize; x++) { + for (x = window_xoffset; x < xsize + window_xoffset; x++) { t.i = bytestream_get_le32(&src); if (t.f > 0.0f && c < 3) /* avoid negative values */ t.f = powf(t.f, one_gamma); - *ptr_x++ = t; + AV_WN32(ptr + x * step, t.i); } } else { - for (x = 0; x < xsize; x++) { + for (x = window_xoffset; x < xsize + window_xoffset; x++) { t.i = bytestream_get_le32(&src); - *ptr_x++ = t; + AV_WN32(ptr + x * step, t.i); } } - memset(ptr_x, 0, axmax); } else if (s->pixel_type == EXR_HALF) { - src = channel_buffer[c]; - - // Zero out the start if xmin is not 0 - memset(ptr, 0, bxmin); - // 16-bit for (x = window_xoffset; x < xsize + window_xoffset; x++) { int v = bytestream_get_le16(&src); - AV_WN16(ptr + x * sizeof(uint16_t), v); + AV_WN16(ptr + x * step, v); } - memset(ptr + x * sizeof(uint16_t), 0, axmax); } // Zero out the end if xmax+1 is not w + memset(ptr + x * step, 0, axmax); channel_buffer[c] += td->channel_line_size; } } @@ -2060,8 +2045,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture, if (!s->is_luma) { avctx->pix_fmt = AV_PIX_FMT_GBRAPF16; } else { - /* todo: change this when a floating point pixel format with luma with alpha is implemented */ - avctx->pix_fmt = AV_PIX_FMT_GBRAPF16; + avctx->pix_fmt = AV_PIX_FMT_YAF16; } } else { if (!s->is_luma) { @@ -2077,8 +2061,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture, if (!s->is_luma) { avctx->pix_fmt = AV_PIX_FMT_GBRAPF32; } else { - /* todo: change this when a floating point pixel format with luma with alpha is implemented */ - avctx->pix_fmt = AV_PIX_FMT_GBRAPF32; + avctx->pix_fmt = AV_PIX_FMT_YAF32; } } else { if (!s->is_luma) { @@ -2157,11 +2140,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture, if (!s->desc) return AVERROR_INVALIDDATA; - if (s->desc->flags & AV_PIX_FMT_FLAG_PLANAR) { - planes = s->desc->nb_components; - } else { - planes = 1; - } + planes = av_pix_fmt_count_planes(avctx->pix_fmt); out_line_size = avctx->width * s->desc->comp[0].step; if (s->is_tile) { diff --git a/tests/ref/fate/exr-ya-scanline-zip-half-12x8 b/tests/ref/fate/exr-ya-scanline-zip-half-12x8 index 97ea715962..6c07f19846 100644 --- a/tests/ref/fate/exr-ya-scanline-zip-half-12x8 +++ b/tests/ref/fate/exr-ya-scanline-zip-half-12x8 @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 12x8 #sar 0: 1/1 -0, 0, 0, 1, 1536, 0x2b457bd2 +0, 0, 0, 1, 1536, 0xa33f5f69 -- 2.48.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".