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 885E04DFA1 for ; Thu, 6 Mar 2025 13:22:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B652668DDAA; Thu, 6 Mar 2025 15:21:58 +0200 (EET) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C98CC68DDAA for ; Thu, 6 Mar 2025 15:21:51 +0200 (EET) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-22349bb8605so10161495ad.0 for ; Thu, 06 Mar 2025 05:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741267309; x=1741872109; 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=G5PghS3XrvVwambHHsYWOcGHT5rwDzQBAxMpiBMQLYI=; b=N8x01vMzR6c+PEIqzCw8Fed/MN4VpEc6igcc0W5j3sGlGx3JOck8JAwbHeWG5brVzu pAe4Xl2EvsH6gil6/O60JCd/k7esYd+9XQwmkoVjuPXyPaR2H4PFwNyxNI5pVzBK3msA malkpLMbBKG+DjzkJkmcEv8xsS5sB+YDmuBPas2pZD5p68GeImatUGNMzcpLHnxEYB2A BKVOFxRe7d0YzngUT3TzqqhHKGePiFxu6xmkzCTAPj78n+Btzo0VZqrGHpbyfkUJdFWa +VUdZyl2z0PQnOmWbELY0vMJ02/8Y3R1j3AscxhWBApXx6P9Xu/rrMeephQfaPMMkkts 5b9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741267309; x=1741872109; 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=G5PghS3XrvVwambHHsYWOcGHT5rwDzQBAxMpiBMQLYI=; b=CETQL9FWD3FbzeQyf0Yjs/SQMlscoUXRest+z5ryzypzCnACONuniUFdB1JE4YpmMv 7Ub4C8BTB2rYIrLaJ49VaXQPNmRul4n9BZFSKkxI7x//t/nf1rRPlnE3/AzfazNHxg7U Du6Iom3Q1iSkj2uVkmijHqbXZBLDzeuG6zCtpWJrg30zUFAXdhe/4EsPMwyXCjO6EWpm iK2PaN32qJqvk8r7HLQlddyAYRvmUxj+yYN1/cSBZ6FvrGqodDLqFuKIAVxthsIvnTbC jwEUV/hZOjznGS+tEKhA8YeKdwB26yWPHEEDFTcopmxMFvkcfyQu5+Blg4THJnhbacCO Lh7w== X-Gm-Message-State: AOJu0YzbnMJMg1AKvoRh1X8zdGlHhABhc7OCrcwE2WapBS9pyNoMqtVM 7+R6iofxMHwX2sB5IUo4XA5WUboFAaZnuqEp6gqvaZ4xHoLtzB1uoDXHww== X-Gm-Gg: ASbGncsxkZo/bVFQf424q5X5Wgf/221HRq3kChMNFzpTFNqp0Qjw3tfEQgwiHzEEAsZ WSn/46MD7lk0nnHFxfpcH7pqWbgY6+MYKngJtQvESmZFIocMGKbUktV+2tPavzOa7j2X13d+Cd9 FBQ/ozklZ0L8ZPmT+J/9nVJmA8rRgFU1K3Ve1G+VXowOlQmjsodR4JeIEg4GlVBdW1+vx2MUdUh x/5oLZCYhsKC9jN2WlNyS7ppYl7QecMEAJ3EGNqIzoZSJoYhW9CqLlxHkdX9g9pOaKeVO9mHx4P QkIUBoI4Q2SBSiMdV34xVw6tjblRwDSRfq4EIBdlFutuav1Mblv7Jz80PfQ= X-Google-Smtp-Source: AGHT+IF4E7N6neU/mQwFvMjoO8vW0pzHT5GJbDXRPY1NNOgeNtw52bjIZpTqfarHyjfCP2PUIEsh8Q== X-Received: by 2002:a05:6a21:3e09:b0:1f3:5869:62b4 with SMTP id adf61e73a8af0-1f35869659amr5510802637.9.1741267308751; Thu, 06 Mar 2025 05:21:48 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:40e:65b1:6e62:9bb5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736a1f813d1sm567190b3a.129.2025.03.06.05.21.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 05:21:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Mar 2025 10:21:33 -0300 Message-ID: <20250306132133.1084-1-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305204413.36950-3-jamrial@gmail.com> References: <20250305204413.36950-3-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 | 70 +++++++------------- tests/ref/fate/exr-ya-scanline-zip-half-12x8 | 2 +- 2 files changed, 25 insertions(+), 47 deletions(-) diff --git a/libavcodec/exr.c b/libavcodec/exr.c index b25e9ef397..4482f104d0 100644 --- a/libavcodec/exr.c +++ b/libavcodec/exr.c @@ -1352,77 +1352,61 @@ 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]; + uint8_t *ptr_x = ptr + window_xoffset * step; + + // 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 - uint8_t *ptr_x = ptr; - - src = channel_buffer[c]; - - // Zero out the start if xmin is not 0 - memset(ptr_x, 0, bxmin); - ptr_x += 4 * window_xoffset; - - if (trc_func && c < 3) { - for (int x = 0; x < xsize; x++, ptr_x += 4) { + if (trc_func && (!c || (c < 3 && s->desc->flags & AV_PIX_FMT_FLAG_PLANAR))) { + for (int x = 0; x < xsize; x++, ptr_x += step) { float f = av_int2float(bytestream_get_le32(&src)); AV_WN32A(ptr_x, av_float2int(trc_func(f))); } } else if (one_gamma != 1.f) { - for (int x = 0; x < xsize; x++, ptr_x += 4) { + for (int x = 0; x < xsize; x++, ptr_x += step) { float f = av_int2float(bytestream_get_le32(&src)); if (f > 0.0f && c < 3) /* avoid negative values */ f = powf(f, one_gamma); AV_WN32A(ptr_x, av_float2int(f)); } } else { - for (int x = 0; x < xsize; x++, ptr_x += 4) + for (int x = 0; x < xsize; x++, ptr_x += step) AV_WN32A(ptr_x, bytestream_get_le32(&src)); } - 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); - } - memset(ptr + x * sizeof(uint16_t), 0, axmax); + for (int x = 0; x < xsize; x++, ptr_x += step) + AV_WN16A(ptr_x, bytestream_get_le16(&src)); } // Zero out the end if xmax+1 is not w + memset(ptr_x, 0, axmax); channel_buffer[c] += td->channel_line_size; } } @@ -2054,8 +2038,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) { @@ -2071,8 +2054,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) { @@ -2151,11 +2133,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".