From patchwork Sat Oct 1 23:05:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 38497 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp508593pzh; Sat, 1 Oct 2022 16:05:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5hZw6g1YQ9suW3cl04AxySv7iitD7rGFioxyxzwvJ+tScx2AITRc3xIdBYQjQ0hoKoi32j X-Received: by 2002:a17:907:5c5:b0:77d:ea1:44c with SMTP id wg5-20020a17090705c500b0077d0ea1044cmr11020286ejb.305.1664665539725; Sat, 01 Oct 2022 16:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664665539; cv=none; d=google.com; s=arc-20160816; b=y7NfJCibtLnLjhuiAJZJMiBufJ5GQJIYEnWET8Glt1fiHYWJowV5tP4Sdf2P+AqB8m bv3IEb4AqSB5+XgctAShQkaEasXbcRbjCPt9gRSDyz7DMhzKUjjWHalk57oQ7pXTyreX hQOga3jcUQINaXG0ansJdIrMDZa1BfWTWNnNV4X8cHesUkohfp6jeTgqmPE/wHzVSjdH LzJQWXZZQOh4tZAJzWYjNMTUlfMr/xkdgfsz4HyLw2Kgrwi/PjxBZU6LgSK2pJUQCVoF /4RmnQabY0RO6g5h6muYkMPTCctSxojHiJtkq7bo8aGPTbiGsrg4tTItMPsh98jR0L3o Y14Q== 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=TJuexQitlOulCNCFkQacnyDG4w15ypXtcJj5Hr6XxSs=; b=tVrSXdYycQUnRwnLpwelWKamWVPBMN5jZv41FpWVjBO4d7CtO4cF3h1uycB7vPmag4 A7kMnQY+BL6iRdDrU2AmfW0NI9+mc2of/tlSh44Tcwma4/NYRe+wol8iRP2S3tJiLDmT s/nCPiBDP9J2RJHrluzRsSFYsPNiSNGUIvrrlkRWRtTdwU0pYnIVYuyE06uPstWpEx86 xVwptplxTBNT2XRXqi6tpmd5k5rnIEqTzYu9rMxionxrbBNdPpLRcVWNvifcnwVgaAR2 ce6b0SwocAJAnNS+bXWbeTrGdTcEuve5eqB0wpH3Et8Nxvn8A6MkqxvXIse9TJi2kCu7 IMgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=k40MUaMO; 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 sa38-20020a1709076d2600b0077edef76646si5284040ejc.366.2022.10.01.16.05.38; Sat, 01 Oct 2022 16:05:39 -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=k40MUaMO; 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 E120968BAEF; Sun, 2 Oct 2022 02:05:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ADC8068B647 for ; Sun, 2 Oct 2022 02:05:28 +0300 (EEST) Received: by mail-pg1-f170.google.com with SMTP id e129so6924167pgc.9 for ; Sat, 01 Oct 2022 16:05:28 -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=s4AUG6FOT+W3fT0ppcf/aAZmjdE5moLb7ytvte8lPPg=; b=k40MUaMOEdxgwsVVAPdudV+cgWZSR9JQtIpOpSY/kKzCMEfDl9cWbY7Nz0IvjxYXqT OrgFa47gt0VaBE1+ORhWYyR3rkgHTT+9ZuVO7V60xLQqS3OYsC14UYAUN6DFSQNXnElc N1aqTFUFktZY9Dlr0/Dd6L7Mpg4LIOhRq5vQDmN5eRoKIBscbjnYcgT7N9Pxqr6rCWOi E3Tx+7+/6xEX5DnA1VBW6BL95i+WfaKaIYwAU5xbOE7IDMilw1kPLy9c1r3L8+08F5lq 6CJRVajrvs52OOw3R5G1Hvxa50MFcF+hC/+GQ1S55MADGzsfQWs990/WcOxE/uwYwtrt n2cg== 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=s4AUG6FOT+W3fT0ppcf/aAZmjdE5moLb7ytvte8lPPg=; b=Qt4DIEIOTKRH/mpVpszab/dRGRRy46Fg4IraO3JkOBS9gsqldXb16SGyeStTi/nGfj 1/jEEh2jt75fYByWjmptWmP+AU3jWFqcFiQCNTEdYV6APaqQVpmHXzRUUZi/exWmzNGN FLUwVGFgvCqBbIjb2m6bcSJcQpflneMwKzXaGPEntc2qahL0kzaNZa76Z23sU1czPxrj wSdoLcG8cdJ1SMR1LMCxGFHmi0mgikibBFbG/pdaevlL3oIWj7lZLY2hzYAhgncG1hAT pSgwBAz+I5puVoVuGE0ZrwVFcnza2ic240rbfocatxKvUt3qVF/W8qJcMrwrkQPOPaSD qO+w== X-Gm-Message-State: ACrzQf1DQoNjU5ODnG5wBZYq7yYIREpzJ8/8zeUwYcPzXWoJ9D8uEeL0 PBjSz7B/kQEjHfRwtgcZ058F++s7zKU= X-Received: by 2002:a63:4949:0:b0:442:b733:2fae with SMTP id y9-20020a634949000000b00442b7332faemr6753894pgk.424.1664665525879; Sat, 01 Oct 2022 16:05:25 -0700 (PDT) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id f5-20020aa79685000000b0053e22c7f135sm4399953pfk.141.2022.10.01.16.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 16:05:24 -0700 (PDT) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Oct 2022 16:05:12 -0700 Message-Id: <20221001230512.271-1-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/tiff: add read support for 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: QWAQ92OrnZK7 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 | 68 ++++++++++++++++++++++ tests/fate/image.mak | 20 ++++++- 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, 123 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..ce31a40e37 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -2249,6 +2249,74 @@ again: } } + /* Floating point predictor + TIFF Technical Note 3 http://chriscox.org/TIFFTN3d1.pdf */ + if (s->predictor == 3) { + int channels = s->bppcount; + int group_size; + 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 */ + group_size = s->width * channels; + + tmpbuf = 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 separate groups. Each + byte of every floating point value in a row of pixels is + split and combined into separate groups. A group of all + the sign/exponents bytes in the row and groups for each + of the upper, mid, and lower mantissa bytes in the row. */ + for (j = 0; j < group_size; j++) { + for (int k = 0; k < bpc; k++) { + dst[bpc * j + k] = tmpbuf[(bpc - k - 1) * group_size + 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 < group_size; j++) { + for (int k = 0; k < bpc; k++) { + dst[bpc * j + k] = tmpbuf[k * group_size + 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..167c8ccf2c 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -501,7 +501,25 @@ 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-$(call DEMDEC, IMAGE2, TIFF) += $(FATE_TIFF) +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 FRAMECRC, IMAGE2, TIFF) += $(FATE_TIFF) FATE_IMAGE_FRAMECRC += $(FATE_TIFF-yes) fate-tiff: $(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