From patchwork Thu Aug 29 13:10:52 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: 14792 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 7B1A444A068 for ; Thu, 29 Aug 2019 16:12:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 67CF6687F56; Thu, 29 Aug 2019 16:12:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7F1EB687F3C for ; Thu, 29 Aug 2019 16:12:28 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id o184so3825947wme.3 for ; Thu, 29 Aug 2019 06:12:28 -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=luzaZF/dnOpl8sGbCyUw8YonwQzrNqceamHBJEoHNj0=; b=jt9FY5rCH3Ckc8t7Jq4yvm+u3YJ1xCAkBfpGG2EZWWrW4zPIFh5hHOYRWOYFVHDXNg cGHV6QaUoGljZukM9COwfxWw3Y8iDTG8lHI+tQafvjOLcRK/WADcXdYhD0KKhPXY+g70 MD/CbqKPmAU1K34fyuVd+yobO0jjyrnIXSe05xvJepdULGgKF0e5mu9brcSHKB3IOE12 i+SKNPbUNcdF73hTIr81I/bfJXVzAz7yNs2HgjjDa1AE8fV7YrkImSh7SI8WVTWNqPrU q9WvKvaEc4Jh8pAtHKqWy/pzCl0sZzD+/twoBawg5ULljnucO0H6N59IblQWKwSOS1uI MWYg== 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=luzaZF/dnOpl8sGbCyUw8YonwQzrNqceamHBJEoHNj0=; b=jbouL8dCG4u2rcetJMfVai9qVdQLXeayETRpEG4NTR8ljLp3ENdTLUeBfy0U6SNGN4 3RISmRK4WRNC34mHR0hdebJmLz/OHZ5i647eZPTGL4bFnrhTxaA738CZXEWUB+Un6a6M qeKY6iLItWXw8Wb02dzgRGtB5Igyy3sOQDEwEKzrOGCYL7qDeTD9ij2ShsmUaVwJSQ+n rWsoahmGn2dZKjQK25wVK/TWyOB/ANQ34EwgFhZkCcaCb8UnJKviNTYnogQwZnRt4BO1 3myjME+m9QwqiAYVJ2QwzonRY7XyWbqBy32KXPIphgpJWP2HD2f0tLT0NTO2V77fvAdx p45g== X-Gm-Message-State: APjAAAXKktxUEiIBAA0tDDr2e2OrtXg479kE5ahr0naAOAGLj9l6G9mZ 6iZh1EYP157Rw3/xXce45K+IMBIv X-Google-Smtp-Source: APXvYqwpqrPiEez1mou9dKmdh5h0hIC9LpUh7wsLixDhGePdbI/TFv90so1smOdAaQgVlSrBjkglEw== X-Received: by 2002:a1c:7a10:: with SMTP id v16mr11143424wmc.2.1567084347588; Thu, 29 Aug 2019 06:12:27 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:240d:9b00:4ca1:2ce9:2e6c:c246]) by smtp.gmail.com with ESMTPSA id m17sm1676644wrs.9.2019.08.29.06.12.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 06:12:27 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Aug 2019 16:10:52 +0300 Message-Id: <20190829131054.16404-13-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190829131054.16404-1-velocityra@gmail.com> References: <20190829131054.16404-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v17 13/15] 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 | 61 ++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 61a140fe09..dfaef1927d 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -551,6 +551,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) { @@ -666,6 +668,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"); @@ -860,8 +873,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; @@ -913,7 +926,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]; @@ -932,7 +945,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; @@ -945,6 +958,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); @@ -981,7 +1000,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; @@ -994,30 +1013,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) @@ -1890,7 +1903,7 @@ again: avpriv_report_missing_feature(avctx, "DNG JPG-compressed tiled non-bayer-encoded images"); return AVERROR_PATCHWELCOME; } else { - if ((ret = dng_decode(avctx, (AVFrame*)data, avpkt)) > 0) + if ((ret = dng_decode_tiles(avctx, (AVFrame*)data, avpkt)) > 0) *got_frame = 1; return ret; }