From patchwork Sat Aug 10 22:19:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: velocityra@gmail.com X-Patchwork-Id: 14402 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 647DC448F16 for ; Sun, 11 Aug 2019 01:20:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 54AFA68AC2F; Sun, 11 Aug 2019 01:20:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0652368AC09 for ; Sun, 11 Aug 2019 01:20:22 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id n9so101503592wru.0 for ; Sat, 10 Aug 2019 15:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7LK/KtzEjZog2X4CXR6tzxfEhIvyzsisaWCLLj8sSc0=; b=jbU4wmE44Qs7/OwwZh1A7OBJTB1MJKtG/Cm8iMDXmizB2EWoI/t0eBqVLB1eG6lkzi Jsj6sIWJhPIE24klPGKEbEQj9HxtkD3OpDkWO2FxPpDUDaz2KjfI2EvDUiCCWXZTowHH G/h67NUeuzn/pxltPQPrj/DjB5f33Dldya2IZxo0iW1h5kQvcYz1WDFbaUk+27y4Vziz WkZ68mZko3BHGYEveUH6uSYHFlEf17O0eVr7I4xKakJ1Yc3aD1s54kENc+8MiAO80O87 eCwh7zws8MFKEpnUXD/Edw1cgjj1KSqEDqrvRkWhnhNcq6bsbBfB7xcEqHkI5V2cq2A9 W/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7LK/KtzEjZog2X4CXR6tzxfEhIvyzsisaWCLLj8sSc0=; b=E62rjJLfsZ05NHZLWppr8bLi+fglzbWjzeHgM0Z5p/CNnNrJHS9Ziuz9JPL1ADFrma YFsujRHIx4dk2m46+6k4BEt55lQgccjB2m5uo6oVRTiG4hgmxFeNvSegfGDC3I8pnEBP szFBjkIVndxxd/66IyMsyvXN3JaAKmkVcqvANMhdYWsiNZkfyLTASpTlrI7sAxyCnutu nWcd7qiDkVNvYKeNzKeSa6csslrvuGn3K8MdAQo2bvKWq7YJQvaSKcB/9jTTi/2cA4By 6QrCbXfQN5eXzcHnK87+I6WP1xn9RDcxq22OE6Z3RdUHHrT4QIVEeW3HM8APQDLpPN7R 6nDA== X-Gm-Message-State: APjAAAX75ACC97XiV1auvKNyhYpmeHoYPRXObUUJuqT9tbRU55Rh1XlH U6fNzLBPww+szmJOvAxDZQQOel7toPY= X-Google-Smtp-Source: APXvYqyx4KOim9tSrDmkFDarFXcxJ9/yXHy3PLiptb4q8LV9pp4bx/T1tR1PjgZSMtdOCJ0y6NxlJQ== X-Received: by 2002:a5d:5183:: with SMTP id k3mr28538871wrv.270.1565475622158; Sat, 10 Aug 2019 15:20:22 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:5c0b:c2fa:5389:82dd]) by smtp.gmail.com with ESMTPSA id q20sm40403233wrc.79.2019.08.10.15.20.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Aug 2019 15:20:21 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Aug 2019 01:19:33 +0300 Message-Id: <20190810221934.44996-13-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190810221934.44996-1-velocityra@gmail.com> References: <20190810221934.44996-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 13/14] lavc/tiff: Support DNGs with striped (non-tiled) JPEGs images X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Nick Renieris Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Nick Renieris DNG samples here can now be decoded: - https://www.photographyblog.com/previews/pentax_k1_photos Signed-off-by: Nick Renieris --- libavcodec/tiff.c | 73 +++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 0d931641c2..b9aa4efd02 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -550,6 +550,8 @@ static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, return ret; } +static int dng_decode_strip(AVCodecContext *avctx, AVFrame *frame); + static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int stride, const uint8_t *src, int size, int strip_start, int lines) { @@ -665,6 +667,17 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int strid is_dng = (s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG); + /* Decode JPEG-encoded DNGs with strips */ + if (s->compr == TIFF_NEWJPEG && is_dng) { + if (s->strips > 1) { + av_log(s->avctx, AV_LOG_ERROR, "More than one DNG JPEG strips unsupported\n"); + return AVERROR_PATCHWELCOME; + } + if ((ret = dng_decode_strip(s->avctx, p)) < 0) + return ret; + return 0; + } + for (line = 0; line < lines; line++) { if (src - ssrc > size) { av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); @@ -859,8 +872,8 @@ static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride, } } -static int dng_decode_jpeg_tile(AVCodecContext *avctx, AVFrame *frame, - int tile_byte_count, int x, int y, int w, int h) +static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, + int tile_byte_count, int dst_x, int dst_y, int w, int h) { TiffContext *s = avctx->priv_data; AVPacket jpkt; @@ -912,7 +925,7 @@ static int dng_decode_jpeg_tile(AVCodecContext *avctx, AVFrame *frame, return AVERROR_PATCHWELCOME; } - dst_offset = x + frame->linesize[0] * y / pixel_size; + dst_offset = dst_x + frame->linesize[0] * dst_y / pixel_size; dst_data = frame->data[0] + dst_offset * pixel_size; src_data = s->jpgframe->data[0]; @@ -931,7 +944,7 @@ static int dng_decode_jpeg_tile(AVCodecContext *avctx, AVFrame *frame, return 0; } -static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) +static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt) { TiffContext *s = avctx->priv_data; int tile_idx; @@ -944,6 +957,12 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) int pos_x = 0, pos_y = 0; int ret; + s->jpgframe->width = s->tile_width; + s->jpgframe->height = s->tile_length; + + s->avctx_mjpeg->width = s->tile_width; + s->avctx_mjpeg->height = s->tile_length; + has_width_leftover = (s->width % s->tile_width != 0); has_height_leftover = (s->height % s->tile_length != 0); @@ -980,7 +999,7 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) bytestream2_seek(&s->gb, tile_offset, SEEK_SET); /* Decode JPEG tile and copy it in the reference frame */ - ret = dng_decode_jpeg_tile(avctx, frame, tile_byte_count, pos_x, pos_y, tile_width, tile_length); + ret = dng_decode_jpeg(avctx, frame, tile_byte_count, pos_x, pos_y, tile_width, tile_length); if (ret < 0) return ret; @@ -993,30 +1012,24 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) } } - return 0; -} + /* Frame is ready to be output */ + frame->pict_type = AV_PICTURE_TYPE_I; + frame->key_frame = 1; -static int dng_decode(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt) { - int ret; + return avpkt->size; +} +static int dng_decode_strip(AVCodecContext *avctx, AVFrame *frame) +{ TiffContext *s = avctx->priv_data; - s->jpgframe->width = s->tile_width; - s->jpgframe->height = s->tile_length; - - s->avctx_mjpeg->width = s->tile_width; - s->avctx_mjpeg->height = s->tile_length; - - /* Decode all tiles in a frame */ - ret = dng_decode_tiles(avctx, frame); - if (ret < 0) - return ret; + s->jpgframe->width = s->width; + s->jpgframe->height = s->height; - /* Frame is ready to be output */ - frame->pict_type = AV_PICTURE_TYPE_I; - frame->key_frame = 1; + s->avctx_mjpeg->width = s->width; + s->avctx_mjpeg->height = s->height; - return avpkt->size; + return dng_decode_jpeg(avctx, frame, s->stripsize, 0, 0, s->width, s->height); } static int init_image(TiffContext *s, ThreadFrame *frame) @@ -1880,17 +1893,15 @@ again: /* Handle DNG images with JPEG-compressed tiles */ - if (s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG) { - if (!s->is_jpeg && s->is_tiled) { + if ((s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG) && s->is_tiled) { + if (!s->is_jpeg) { avpriv_report_missing_feature(avctx, "DNG uncompressed tiled images"); return AVERROR_PATCHWELCOME; - } - if (s->is_jpeg && !s->is_bayer) { - avpriv_report_missing_feature(avctx, "DNG JPG-compressed non-bayer-encoded images"); + } else if (!s->is_bayer) { + avpriv_report_missing_feature(avctx, "DNG JPG-compressed tiled non-bayer-encoded images"); return AVERROR_PATCHWELCOME; - } - if (s->is_jpeg && s->is_bayer) { - if ((ret = dng_decode(avctx, (AVFrame*)data, avpkt)) > 0) + } else { + if ((ret = dng_decode_tiles(avctx, (AVFrame*)data, avpkt)) > 0) *got_frame = 1; return ret; }