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 ESMTP id 88D4F47256 for ; Tue, 30 Jan 2024 15:24:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D206B68D399; Tue, 30 Jan 2024 17:24:36 +0200 (EET) Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A4C468D206 for ; Tue, 30 Jan 2024 17:24:30 +0200 (EET) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5958b9cda7aso907897eaf.0 for ; Tue, 30 Jan 2024 07:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706628269; x=1707233069; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=udkUGuI91VRoNC1E/SBTCvV3JACMMs9SPa9NrjKPg04=; b=F2cOKK3tOno4zu6MFaYIcZP2koPRwMcJJZZg7yPl/BhHf8ShzjNtGu/opiTT94Ei8f pz0l7qdfbiMhonCOeYpHqcPchGHHc+xAalpzPAa/BwC7yalEyjvTpf6ExPX84Lc825Ah yPdU9r3F+n8ZC9pmKDSa2L8uQQ1tEeTry2eamdUhdp817MZwD3e+qzbK9eqcFU30JTao iFG2CT1RqKXnppEh4LASvBBoqW7LAblM366ofpI+4Kp7kAKG6GolqME9OFoRlSX9HYSk pBghZHaZ2mJQUKIRWHukm2PFXOHf5Da0uS3pWpJys17eAaqquZVXgbLMQVFud6zM5xDe xcEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706628269; x=1707233069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=udkUGuI91VRoNC1E/SBTCvV3JACMMs9SPa9NrjKPg04=; b=oOtSpXRdARLDmi57JJB7Wzu8gHzxFrs6xmjRNGmrJKWFCoUgRd6t19TMMddP2E97rx KJL+bp3IALlp3WddkD7lUD5HjMlwPPFfS8tKcoenR6HeOzEiMyfu7waxRnHIYYmczFJw OWavsdymKq0xTsk0E1QFxiAO9tLS0Mfmx36uBXF1+Er7SlrRCMGYVNIq5/ht6YVXplwt l8dcw67aV1WEHQF7ECwrcRiJ4kDP76+bpwNLVdEZwnCSDwpl11SGqhOXOhuy9LV4QsLe fe3f6yn3/TvU2TQUAkhpbR3Offlzw8AiXT1DynsUFv71oAcu8qA304+exPBUwxdk2ZOb +4Kg== X-Gm-Message-State: AOJu0Yzk7wd05WniyqrleVEHIDWqPXodi6ZBAJ7PkWZC0aNGMlW3DTZh 3rg0nFqFqzCS6Sxlr3CdahM4hwmxnW15flRX0nA2ctOoMf+kM79nsTQEKT3q X-Google-Smtp-Source: AGHT+IHQA2lZ9HJeSDQQrUSAoSuJmDO6PjRvqeXVqT1IJ1TTsSJwnoF/nUorr7OM4L3iEtelkaoD9w== X-Received: by 2002:a05:6820:2c06:b0:599:6d16:353c with SMTP id dw6-20020a0568202c0600b005996d16353cmr8755108oob.1.1706628268755; Tue, 30 Jan 2024 07:24:28 -0800 (PST) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id lz8-20020a0562145c4800b0068174386320sm4528169qvb.19.2024.01.30.07.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 07:24:28 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 10:24:24 -0500 Message-ID: <20240130152424.56123-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/libjxlenc: support negative linesizes 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 Cc: Leo Izen 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: libjxl doesn't support negative strides, but JPEG XL has an orientation flag inside the codestream. We can use this to work around the library limitation, by taking the absolute value of the negative row stride, sending the image up-side-down, and telling the library that the image has a vertical-flip orientation. Signed-off-by: Leo Izen --- libavcodec/libjxlenc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c index 67be8a01ca..5f5f9751dc 100644 --- a/libavcodec/libjxlenc.c +++ b/libavcodec/libjxlenc.c @@ -259,6 +259,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra size_t available = ctx->buffer_size; size_t bytes_written = 0; uint8_t *next_out = ctx->buffer; + const uint8_t *data; ret = libjxl_init_jxl_encoder(avctx); if (ret) { @@ -303,6 +304,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra /* bitexact lossless requires there to be no XYB transform */ info.uses_original_profile = ctx->distance == 0.0; + info.orientation = frame->linesize[0] >= 0 ? JXL_ORIENT_IDENTITY : JXL_ORIENT_FLIP_VERTICAL; if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n"); @@ -383,9 +385,15 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra } jxl_fmt.endianness = JXL_NATIVE_ENDIAN; - jxl_fmt.align = frame->linesize[0]; + if (frame->linesize[0] >= 0) { + jxl_fmt.align = frame->linesize[0]; + data = frame->data[0]; + } else { + jxl_fmt.align = -frame->linesize[0]; + data = frame->data[0] + frame->linesize[0] * (info.ysize - 1); + } - if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, frame->data[0], jxl_fmt.align * info.ysize) != JXL_ENC_SUCCESS) { + if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, data, jxl_fmt.align * info.ysize) != JXL_ENC_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n"); return AVERROR_EXTERNAL; } -- 2.43.0 _______________________________________________ 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".