From patchwork Tue May 22 00:23:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 9046 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp886157jad; Mon, 21 May 2018 17:23:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpPqjlzJhxcNxVnpLd+AQ+45xifhhi083JvB3FJkYEatt0dvAn8UJ6EH8IiliWkrHrE9YAm X-Received: by 2002:adf:a58a:: with SMTP id g10-v6mr17958560wrc.233.1526948637038; Mon, 21 May 2018 17:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526948637; cv=none; d=google.com; s=arc-20160816; b=rT1ixF2FLA9/hOJsarkTtzcBnyu7ezn1dOEafRIwuAkd3ghZGaV0NGcEepXMyCV7k7 CSj+bVVdqrJLOj5FIm9JyALZ5HGFObYaL5bNnJc3+ZqyPoxjVuJY1VG02kS1Y6G96fAG jqWM3IkphWr+axyadizhUxAhfCGr2UcFhacOyKKKyu7le8JyYDh30flFiWRDS+bGB+so wfehvx0WVnFSBP2mByjqRjmeVSPCn13v5IeTkMMy6CiXE0LvbHhwsbPZ5JMV8EnLot1q h8jKdI0t9WrQzN2JwPXC71Lv/O4a4P6e5TVXFu1jOZiMURtukx4xoKgoDYt9y4AaJb6J o1Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to :arc-authentication-results; bh=SjxsUM/7bCTJVIC45g1P14QEwAfFzkb9e6+CtJe6GMk=; b=SXQCn9kCsoVANVVkJLDr4rwPdNXjrGnYIp2AUx/btGrSoVbFnljp4/zc4RdghxfP6Q g/b/OnxShHnAKHxS2tZjPM2bldKSnTKQ4pP8FtsWsPOvLmjL3ibO8uV8/0LO7+RUPeM3 sViuPs2LtNXJjqh9ExU9mHixU9PY4yjVr4d/dQq1DM614EzFrGK27r44WOfrWg4m2m7+ 7iC0UeVAj6hKR4ts3/S416Pbw3GbCACSvkeKpod/7sBP117I0iIuEGA/AqPZFkMbgulM 1ZZvUazEQVKZGnv0rVfeiS6OVneCu1wanGuC/iKwWPWGuiW/KMO85Sftvidb/BQSFrN5 IDVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VriMeqCY; 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 o25-v6si522500wro.406.2018.05.21.17.23.56; Mon, 21 May 2018 17:23:57 -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=20161025 header.b=VriMeqCY; 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 99E7C689CCB; Tue, 22 May 2018 03:23:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B72A6680671 for ; Tue, 22 May 2018 03:23:11 +0300 (EEST) Received: by mail-it0-f51.google.com with SMTP id e185-v6so10033811ita.0 for ; Mon, 21 May 2018 17:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=DQzjmgsVZ35ER5JwEvLpnu08tCvnUB2bpDLpZFoqgPE=; b=VriMeqCYuNyzun7xUJTekw+NvzLmqRexwLKwU3iB2HpSo0VpC9gqrsjFQbjFYQAvjl P+QHgB+csJ1j6dbK/JeY6l/8FhB6dwNwS1ykCTd3bDKef9RkoT/mj8kWmgBsw5iPYOVc kDz07XBqShrSb9UlgLNB+03UJuBAUjofWSOdFgf4Hv53T+7hbnDOA87Am404rFuYtmK8 9XMgFiN64Wu7DGlEqp18rNk7j0ezKuX0OboU1KXEEhxmQ6j0Rev+ZgJoVOqUCMoXJ1lp 9XPB5lXJjcsODahRuUhgwK0HIZFs+OaW/wXKjvCy362JC0NBeVtUlVa9Kop6tbt2xG3c TgIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=DQzjmgsVZ35ER5JwEvLpnu08tCvnUB2bpDLpZFoqgPE=; b=dtTTsME5SXxuU+WVbEe7dW3/umt0+l0zaUDz20711KqKZP5vOfTee7bor4Zx0IGE8a 8pOTrMZIaxkvJn5P/2AsPh8LULoSHsWJ47i+GTYzcRjVRklypNwS1+XiJzhomh/XQtfW CkUT3Us1QnEEtaCqvMqXYN85IjWRoX18NDnEBpB1ZXd4gCsCtsTOvG1OJUThG6RNWUkH J1EnD8halGOrSfk/lDtnG8ez+xoMv4lCU6qVs7ABu+3yaou+J6Z53sr+bhwoIYhrGE26 eVtDg8KCm61kAeMV6tiZsIjtwqGqEHUZbpBuAdBI3G2IYti5SvMEDS10ubRIJV964jsw Ypug== X-Gm-Message-State: ALKqPwcydLGN8JEFAsmGHDXfBDQO09OABRDgGF6pEyfvuDTryzjoel9S t/7jirQDcXILFDQjRh0SsHg9PFXn4ADyLqUrBG0= X-Received: by 2002:a24:7f0d:: with SMTP id r13-v6mr937439itc.39.1526948631056; Mon, 21 May 2018 17:23:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:81c6:0:0:0:0:0 with HTTP; Mon, 21 May 2018 17:23:50 -0700 (PDT) From: Carl Eugen Hoyos Date: Tue, 22 May 2018 02:23:50 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH]lavc/j2kenc: Support AV_PIX_FMT_PAL8 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi! Attached patch allows pal8 encoding into j2k, tested with libopenjpeg, kakadu and jasper. Please comment, Carl Eugen From ffc9968279ecbf8b0b6659e9a07539edb9787e44 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Tue, 22 May 2018 02:21:04 +0200 Subject: [PATCH] lavc/j2kenc: Support AV_PIX_FMT_PAL8. --- libavcodec/j2kenc.c | 40 ++++++++++++++++++++++++++++++++++++---- libavcodec/version.h | 2 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index 3e542af..e91d932 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -71,6 +71,7 @@ #include "libavutil/common.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" +#include "libavutil/intreadwrite.h" #define NMSEDEC_BITS 7 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1) @@ -1054,14 +1055,38 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytestream_put_byte(&s->buf, 1); bytestream_put_byte(&s->buf, 0); bytestream_put_byte(&s->buf, 0); - if (s->ncomponents == 1) { - bytestream_put_be32(&s->buf, 17); - } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) { + if (avctx->pix_fmt == AV_PIX_FMT_RGB24 || avctx->pix_fmt == AV_PIX_FMT_PAL8) { bytestream_put_be32(&s->buf, 16); + } else if (s->ncomponents == 1) { + bytestream_put_be32(&s->buf, 17); } else { bytestream_put_be32(&s->buf, 18); } update_size(chunkstart, s->buf); + if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { + int i; + uint8_t *palette = pict->data[1]; + chunkstart = s->buf; + bytestream_put_be32(&s->buf, 0); + bytestream_put_buffer(&s->buf, "pclr", 4); + bytestream_put_be16(&s->buf, AVPALETTE_COUNT); + bytestream_put_byte(&s->buf, 3); // colour channels + bytestream_put_be24(&s->buf, 0x070707); //colour depths + for (i = 0; i < AVPALETTE_COUNT; i++) { + bytestream_put_be24(&s->buf, HAVE_BIGENDIAN ? AV_RB24(palette + 1) : AV_RL24(palette)); + palette += 4; + } + update_size(chunkstart, s->buf); + chunkstart = s->buf; + bytestream_put_be32(&s->buf, 0); + bytestream_put_buffer(&s->buf, "cmap", 4); + for (i = 0; i < 3; i++) { + bytestream_put_be16(&s->buf, 0); // component + bytestream_put_byte(&s->buf, 1); // palette mapping + bytestream_put_byte(&s->buf, i); // index + } + update_size(chunkstart, s->buf); + } update_size(jp2hstart, s->buf); jp2cstart = s->buf; @@ -1124,6 +1149,12 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif + if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && (s->pred != FF_DWT97_INT || s->format != CODEC_JP2)) { + av_log(s->avctx, AV_LOG_WARNING, "Forcing lossless jp2 for pal8\n"); + s->pred = FF_DWT97_INT; + s->format = CODEC_JP2; + } + // defaults: // TODO: implement setting non-standard precinct size memset(codsty->log2_prec_widths , 15, sizeof(codsty->log2_prec_widths )); @@ -1154,7 +1185,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->pix_fmt == AV_PIX_FMT_RGB24){ s->ncomponents = 3; - } else if (avctx->pix_fmt == AV_PIX_FMT_GRAY8){ + } else if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 || avctx->pix_fmt == AV_PIX_FMT_PAL8){ s->ncomponents = 1; } else{ // planar YUV s->planar = 1; @@ -1223,6 +1254,7 @@ AVCodec ff_jpeg2000_encoder = { AV_PIX_FMT_RGB24, AV_PIX_FMT_YUV444P, AV_PIX_FMT_GRAY8, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, + AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE }, .priv_class = &j2k_class, diff --git a/libavcodec/version.h b/libavcodec/version.h index da893da..2e45d39 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 19 -#define LIBAVCODEC_VERSION_MICRO 102 +#define LIBAVCODEC_VERSION_MICRO 103 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 1.7.10.4