From patchwork Sat Oct 1 14:06:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 38493 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp302852pzh; Sat, 1 Oct 2022 07:07:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7G4JSLXOngzQ5GmONSCcbaZ7tZ76NoY/4yrq3cDuCNDUBplODwmz4n+AJyS1/Q3LqsP4J2 X-Received: by 2002:a17:906:ef90:b0:77c:280b:93a1 with SMTP id ze16-20020a170906ef9000b0077c280b93a1mr9936326ejb.709.1664633226596; Sat, 01 Oct 2022 07:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664633226; cv=none; d=google.com; s=arc-20160816; b=gXyr6n/xKkrhg/LV5AvVpK5sFCCzfOTHWIYBaMful29FuodAtNmNTjjhizrbAVBAeZ wSy9FGJuojU+AayPfWzqr3WcK0MXDNCnY/xTVhb0w9XiFNkFDUjQ+A4YurQ4SfsmG6jy yzu8PTCzP5Vhclzu2glAXQ1COgv/2GWPlWY4x+sz5oat0cbbCvnEoVfDC4+2YFyiqf0d COUClUgtwDDtieLNXIFGw7F1pnzrYQGvo2/1cECVXRr5Sz10duptnDQtTOvlq/RQ3W0P JnV4FFEslAD31Iwnqk/CN8MAEk7TpRwAdOQH9ZiM/3oLj3z8aK86C47ItWE2yc4M/VdL /BcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=JICIhDHDjhwEswd1rX6L7glYM/Myk+Q+pM3cOERyU14=; b=G35y4vxahBAxq7qFn4KAbb45F3KVZspmooz6eL/bdp2sPaHMByfLhnhUep4ziCn02y AmX3jROmXXOpxJcAk45jDUyNxlIu63QLxaAz0tfwvCZE4L8S0g58SVVUbLBNmXoiJjAp DJ4Liw0vyduiQqqaWb2q5IuqufSoTBtFPTDAR5L7o0pxYV2GGRdBh4LrfNbRlARRzM7j Ekkm5effeoEvikhF7d/juwQpu2dqkGiF6nnA6/8cptFvzvKrHwmltvw+3jQMGniXH9D4 +BNDitHV9bS+9/Npo9yZ9IYq8+Fhe4SBR57SIU+O6KsEkLe2xiulf2Htinnc0ARFvEBL IdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NnTDAutO; 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 dk24-20020a170906f0d800b007820f00167fsi3580010ejb.260.2022.10.01.07.07.05; Sat, 01 Oct 2022 07:07:06 -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=NnTDAutO; 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 B55D168BB01; Sat, 1 Oct 2022 17:07:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8C5568B554 for ; Sat, 1 Oct 2022 17:06:54 +0300 (EEST) Received: by mail-pf1-f177.google.com with SMTP id b23so6564967pfp.9 for ; Sat, 01 Oct 2022 07:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=qIP0BrauOwnNJqeHpf4LVAe+zAKSi2h2VekUWDbpSd4=; b=NnTDAutO6NRTs9Myr3J4j5IQHOVtAt2KKdUJUmUVqWkm1wjqBH6rkwSnIXKbHRvQfx OJXUk+3AJvL2Y2qjUgkm0fz6LNl0uZRgzWYhvnGVtQq7jQeKrcL6XEdNE+ZxJcA95yd1 06JvBRs2kqyl5GMQw7/U93J/7AIlZtVeBpYSa0L4isteOEQWLK3dRd8s6l7TXWGEaiOb Gpk67pKUb+QCRAG9/3Z+unm14ixBTNYTwirwd2znu3UVOswokVrAEnORedj3I8Jz0yDQ o8zA76Du8lmfnxIMyF6h72VB2/CdpTclHOKksJt/J7TksxvE8PmUXAff5if37JTWqhiM Se7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=qIP0BrauOwnNJqeHpf4LVAe+zAKSi2h2VekUWDbpSd4=; b=Cqfn4D/ShLZ4FVpzqge2DjG12hwFDxlXXZT9SeYNERyC5/ZY6Np+v4O6SxEy7u6qtk onsCxmc6Qd1E9BG51fCJxdAihm5f6+REKGq76fDxS1T9xhwqUDAip3t8lo3U+6SMSRpO +lu34rVyufrqSNdQ1MlcQ7oL0flG7tIAw6PehOu3yLm/gFO8xuQhff6s6WeRu130UFWn MRvUg4KV307iCeyKEa1M3Kc8JGDb1MK+1iJxNyQPZqr/A5mt5IDjop+sPGEWLy/ixd2W En2YPs1zDkuGhIwIN1ZUnzUGjBgOSku+a57H/s0D3V+2tqEZcUCT6dIfXM0ieLcPaJcY 8WsQ== X-Gm-Message-State: ACrzQf2ogmlcixDl7G7MQUrld+xMxL4AVZoxUrgTRdUXZhQ6FJemPSUE ZjT/xOLy0XVxqQz7X9LZEC+YBGIM2Eo= X-Received: by 2002:a63:5266:0:b0:439:920b:fc65 with SMTP id s38-20020a635266000000b00439920bfc65mr11666637pgl.417.1664633211654; Sat, 01 Oct 2022 07:06:51 -0700 (PDT) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id s14-20020a17090302ce00b0017a09ebd1e2sm3893654plk.237.2022.10.01.07.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 07:06:50 -0700 (PDT) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Oct 2022 07:06:33 -0700 Message-Id: <20221001140633.1722-1-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/tiff: add support for decoding compressed rgb floating point 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 Cc: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: u2pDIqp3Zx4c From: Mark Reid floating point uses a slightly different predictor technique describe here http://chriscox.org/TIFFTN3d1.pdf Here is a link the test files, if someone could add them to fate me https://www.dropbox.com/s/fg59h2os4gb4wug/tiff_fate_samples.zip --- libavcodec/tiff.c | 66 +++++++++++++++++++++- tests/fate/image.mak | 18 ++++++ tests/ref/fate/tiff-lzw-rgbaf32le | 6 ++ tests/ref/fate/tiff-lzw-rgbf32le | 6 ++ tests/ref/fate/tiff-uncompressed-rgbaf32le | 6 ++ tests/ref/fate/tiff-uncompressed-rgbf32le | 6 ++ tests/ref/fate/tiff-zip-rgbaf32le | 6 ++ tests/ref/fate/tiff-zip-rgbf32le | 6 ++ 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/tiff-lzw-rgbaf32le create mode 100644 tests/ref/fate/tiff-lzw-rgbf32le create mode 100644 tests/ref/fate/tiff-uncompressed-rgbaf32le create mode 100644 tests/ref/fate/tiff-uncompressed-rgbf32le create mode 100644 tests/ref/fate/tiff-zip-rgbaf32le create mode 100644 tests/ref/fate/tiff-zip-rgbf32le -- 2.31.1.windows.1 diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 3a610ada85..c1d07f8c3e 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -1913,7 +1913,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, TiffContext *const s = avctx->priv_data; unsigned off, last_off = 0; int le, ret, plane, planes; - int i, j, entries, stride; + int i, j, k, entries, stride; unsigned soff, ssize; uint8_t *dst; GetByteContext stripsizes; @@ -2249,6 +2249,70 @@ again: } } + /* Floating point predictor + TIFF Technical Note 3 http://chriscox.org/TIFFTN3d1.pdf */ + if (s->predictor == 3) { + int channels = s->bppcount; + int lane_offset; + uint8_t *tmpbuf; + int bpc; + + dst = five_planes ? five_planes : p->data[plane]; + soff = s->bpp >> 3; + if (s->planar) { + soff = FFMAX(soff / s->bppcount, 1); + channels = 1; + } + ssize = s->width * soff; + bpc = FFMAX(soff / s->bppcount, 1); /* bytes per component */ + lane_offset = s->width * channels; + + tmpbuf = (uint8_t*)av_malloc(ssize); + if (!tmpbuf) + return AVERROR(ENOMEM); + + if (s->avctx->pix_fmt == AV_PIX_FMT_RGBF32LE || + s->avctx->pix_fmt == AV_PIX_FMT_RGBAF32LE) { + for (i = 0; i < decoded_height; i++) { + /* copy first sample byte for each channel */ + for (j = 0; j < channels; j++) + tmpbuf[j] = dst[j]; + + /* decode horizontal differences */ + for (j = channels; j < ssize; j++) + tmpbuf[j] = dst[j] + tmpbuf[j-channels]; + + /* combine shuffled bytes from their sepearate lanes */ + for (j = 0; j < lane_offset; j++) { + for (k = 0; k < bpc; k++) { + dst[bpc * j + k] = tmpbuf[(bpc - k - 1) * lane_offset + j]; + } + } + dst += stride; + } + } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGBF32BE || + s->avctx->pix_fmt == AV_PIX_FMT_RGBAF32BE) { + /* same as LE only the shuffle at the end is reversed */ + for (i = 0; i < decoded_height; i++) { + for (j = 0; j < channels; j++) + tmpbuf[j] = dst[j]; + + for (j = channels; j < ssize; j++) + tmpbuf[j] = dst[j] + tmpbuf[j-channels]; + + for (j = 0; j < lane_offset; j++) { + for (k = 0; k < bpc; k++) { + dst[bpc * j + k] = tmpbuf[k * lane_offset + j]; + } + } + dst += stride; + } + } else { + av_log(s->avctx, AV_LOG_ERROR, "unsupported floating point pixel format\n"); + } + av_free(tmpbuf); + } + if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) { int c = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<bpp) - 1 : 255); dst = p->data[plane]; diff --git a/tests/fate/image.mak b/tests/fate/image.mak index 03e794dc48..971531520d 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -501,6 +501,24 @@ fate-tiff-fax-g3: CMD = framecrc -i $(TARGET_SAMPLES)/CCITT_fax/G31D.TIF FATE_TIFF += fate-tiff-fax-g3s fate-tiff-fax-g3s: CMD = framecrc -i $(TARGET_SAMPLES)/CCITT_fax/G31DS.TIF +FATE_TIFF += fate-tiff-uncompressed-rgbf32le +fate-tiff-uncompressed-rgbf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/uncompressed_rgbf32le.tif + +FATE_TIFF += fate-tiff-uncompressed-rgbaf32le +fate-tiff-uncompressed-rgbaf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/uncompressed_rgbaf32le.tif + +FATE_TIFF += fate-tiff-lzw-rgbf32le +fate-tiff-lzw-rgbf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/lzw_rgbf32le.tif + +FATE_TIFF += fate-tiff-lzw-rgbaf32le +fate-tiff-lzw-rgbaf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/lzw_rgbaf32le.tif + +FATE_TIFF += fate-tiff-zip-rgbf32le +fate-tiff-zip-rgbf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/zip_rgbf32le.tif + +FATE_TIFF += fate-tiff-zip-rgbaf32le +fate-tiff-zip-rgbaf32le: CMD = framecrc -i $(TARGET_SAMPLES)/tiff/zip_rgbaf32le.tif + FATE_TIFF-$(call DEMDEC, IMAGE2, TIFF) += $(FATE_TIFF) FATE_IMAGE_FRAMECRC += $(FATE_TIFF-yes) diff --git a/tests/ref/fate/tiff-lzw-rgbaf32le b/tests/ref/fate/tiff-lzw-rgbaf32le new file mode 100644 index 0000000000..c99aa02ef0 --- /dev/null +++ b/tests/ref/fate/tiff-lzw-rgbaf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 1024, 0x877e1d5f diff --git a/tests/ref/fate/tiff-lzw-rgbf32le b/tests/ref/fate/tiff-lzw-rgbf32le new file mode 100644 index 0000000000..a6d3fabfda --- /dev/null +++ b/tests/ref/fate/tiff-lzw-rgbf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 768, 0xad26ed90 diff --git a/tests/ref/fate/tiff-uncompressed-rgbaf32le b/tests/ref/fate/tiff-uncompressed-rgbaf32le new file mode 100644 index 0000000000..c99aa02ef0 --- /dev/null +++ b/tests/ref/fate/tiff-uncompressed-rgbaf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 1024, 0x877e1d5f diff --git a/tests/ref/fate/tiff-uncompressed-rgbf32le b/tests/ref/fate/tiff-uncompressed-rgbf32le new file mode 100644 index 0000000000..a6d3fabfda --- /dev/null +++ b/tests/ref/fate/tiff-uncompressed-rgbf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 768, 0xad26ed90 diff --git a/tests/ref/fate/tiff-zip-rgbaf32le b/tests/ref/fate/tiff-zip-rgbaf32le new file mode 100644 index 0000000000..c99aa02ef0 --- /dev/null +++ b/tests/ref/fate/tiff-zip-rgbaf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 1024, 0x877e1d5f diff --git a/tests/ref/fate/tiff-zip-rgbf32le b/tests/ref/fate/tiff-zip-rgbf32le new file mode 100644 index 0000000000..a6d3fabfda --- /dev/null +++ b/tests/ref/fate/tiff-zip-rgbf32le @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8x8 +#sar 0: 0/1 +0, 0, 0, 1, 768, 0xad26ed90