From patchwork Thu Aug 1 02:37:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WATANABE Osamu X-Patchwork-Id: 50846 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp865052vqs; Wed, 31 Jul 2024 19:47:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX1qqF4xHuBu+2XKsVzY48tdkV3Qi1GWENm4AI2jmUv+qwdQjaegVnfYL6ya6b901tzRtuzJNp1E5IL9V2KtIzHv6H8MxXnkmikYg== X-Google-Smtp-Source: AGHT+IEC0+qOIbW/WVcqsPi+TBMPRjnBZZ71OITmdW0aDXI2ZTDvrZPneP3gePUqhzkfUdUDVj/C X-Received: by 2002:a17:906:eec5:b0:a77:dafb:2bf9 with SMTP id a640c23a62f3a-a7daf5bec60mr61773366b.49.1722480419778; Wed, 31 Jul 2024 19:46:59 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a7aca9f665esi999139066b.239.2024.07.31.19.46.59; Wed, 31 Jul 2024 19:46:59 -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=@takushoku.onmicrosoft.com header.s=selector2-takushoku-onmicrosoft-com header.b=rXL23G0K; arc=fail (body hash mismatch); 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A4A3768D932; Thu, 1 Aug 2024 05:37:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from TY3P286CU002.outbound.protection.outlook.com (mail-japaneastazon11020124.outbound.protection.outlook.com [52.101.229.124]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2778B68CA8A for ; Thu, 1 Aug 2024 05:37:41 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pUpt7NAX/RlJaPthHMOUaQjklJyzyvAyktf4gqP12c9S3SKjP7NUEV+ysMFqF1rqsZ0PwJN2/kC68saNfGimcclWAiD/czOmY8reu6oddiZtPPhzoBVwcv9d/uweKMKk7hMDScElJhvoqBTifyRr3tVIiniJOQhgaTAnMtK/zDnJN1g0Lvhfe5aoj9yVF7XBFVxzod9/3Bt0hpBrtUI9ORGoXbZt8YaAnQf4EQZVW65SPG+kSkJfSLhaOV3lH17k2+5qvo0m/zNGOFDg9zzSkTGwhRN9/oXyNlA0N4OGvtPwZ+B1pF/yFN2k7skK6KwVUri06rvtkO8uq1Qh4jCK5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WhQ9SxTgQ0EKaU9bOQOAkJVK+HydnY/e/G0iLca+qBw=; b=F96IboTCTAocezzegHL6Ylxqj2WNyf/zrzAc1r+/wtmldbnAx7kZRTJGLBDlgyx2W5nkcduwxabZZzamFW6mDJxcoN36H55Ir9fvxihogAzMCWxh8Xdn9E4rDDgkaSVCz6WsEtySfg9GA6p0BrCCkcwQ2tu9CPZL2AaKY51SEhkBFcCxCML1Yfhj8YFv0Nsn17Wl41oG4EKxi0+vxhtH40NNFOdDSN5r0EDL4+LseY1PPcUBoeef+8i3ku3NA2reya6A9XBoOrozVmwNVZPyv1XFalgJR3HSHU7o1vehiU3sef7CsFaeZQNwOXdfwbSAGVjzjGcSQXtm1DTLhEgurA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=es.takushoku-u.ac.jp; dmarc=pass action=none header.from=es.takushoku-u.ac.jp; dkim=pass header.d=es.takushoku-u.ac.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=takushoku.onmicrosoft.com; s=selector2-takushoku-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WhQ9SxTgQ0EKaU9bOQOAkJVK+HydnY/e/G0iLca+qBw=; b=rXL23G0KLfkFZClIUaQh8w1HCpHthAXtkIpC3ZBWFr0Lb9Ytdyri+McG2B0gpni6hiN0GoS5hmT3zEJM/70BrEtf+tohMsChIOevPJqNwK/q0q9WkvDoFo3o4cXGpOaaL/TNwCVvjZhw5ZvnYTyIcYPzr/xTfaTj7ywlu6/qMNM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=es.takushoku-u.ac.jp; Received: from OS0PR01MB6001.jpnprd01.prod.outlook.com (2603:1096:604:b7::12) by TYCPR01MB6032.jpnprd01.prod.outlook.com (2603:1096:400:49::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Thu, 1 Aug 2024 02:37:36 +0000 Received: from OS0PR01MB6001.jpnprd01.prod.outlook.com ([fe80::181c:c1f4:9b58:f6cc]) by OS0PR01MB6001.jpnprd01.prod.outlook.com ([fe80::181c:c1f4:9b58:f6cc%3]) with mapi id 15.20.7828.021; Thu, 1 Aug 2024 02:37:36 +0000 From: Osamu Watanabe To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Aug 2024 11:37:24 +0900 Message-Id: <20240801023726.188191-1-owatanab@es.takushoku-u.ac.jp> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: TYWPR01CA0038.jpnprd01.prod.outlook.com (2603:1096:400:17f::8) To OS0PR01MB6001.jpnprd01.prod.outlook.com (2603:1096:604:b7::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS0PR01MB6001:EE_|TYCPR01MB6032:EE_ X-MS-Office365-Filtering-Correlation-Id: 1fc3c9a7-d4be-454f-3481-08dcb1d2e687 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|52116014|376014|1800799024|41320700013|38350700014; X-Microsoft-Antispam-Message-Info: i9I4zY0yQxefVQy1HawG645TSQkTE7ukOZSzim7yp4t5c1KmvpsDivJcX76suLnVvAgKtU8jWpPzBZWKS8P0v6nGO0hICwQ+CnVLrpp7vcmZr7IU79PeMHcbOlS/Dcups2hth3l5WmAIT430XbN3LbBNbrIeoUSIFXA7uc+MAutgBPz0qr3bg720hB/eRJNe0OzM9eyC6xoICGtZMzMEsP55FNZBVz/TPV5dfpmNzEyT6L5lngYWma6OuFPIujZmccbPeexKn55V2YVkvVeA0axueFWvOGAQ8kpYxfP/hUI0IXfTQ5taXNfyqj7/QiqNUWtgrQljrsUSoh7/VJr0/3d2FWW36o73cB2GRJ5min2orqmNp9L89QovdnR9jB6xPS3xWWPId6jifjoQguClH9U1CDHJ3mzd3UtvuFcYrtHZcgUXTF1MmZcVEv3QJDqykrf6SQh12QpcITHWtOEFri/Fw19B8W9VuERhB/gqykO9VKB38WBnJjWuctXi9zxrkjQlkKuE2ECdN/BnrgrRhbbMefqNhuYUb2acTgc9FwaGOiTe5FhTcN7RnEU6wL8KqVqn8CXMF5VjxxYaLi20wpW49ryV7p3b019rZRXIwBBq2Lct52IUx767+EMHaKQ4zgT/lF59MUxQMeimdhbHynofkUOBQ/z8MBqyoj8LiHuCVsa0GGy08fwfB6j+pvttvLTfAt3uuzAWCBi97YzPXckK2pf3ux8+u+4XdvEte8l6yzNz+lBLr9MekeKuLLkhZ0La1wzrhxGs9CTUX/9gTenoIgaQ2k+M+KlnaCZRplTmd7lqmeNHXnuffEeXOlpgqj+rfsCEBWdRn5o6rTSa72Hm1f0Qz+vLHLUOyRM2pOepQs6FAudlM6d/VRLVAh/fEVKsM1BkyMuIpWx95zjpGQfI9W4TUCxm2/a1viL+FKf7SPUzzkU/yiklknXXhUs3ChVvlQdv5N/S4dHKsV1vEGrkBWw/rdgPKTiPs8X7APzf3Jt9TGwGVrf/viqIRqdo/ZfjyxThmY73gzIKH144n9w2llGfpj8M9AOZ8YH2SwpefUXH29L8dUCzC6if8klob1EDnl4RuT50i1Wt+PbxfWXctnrxAkuEHeZ0GcYKdshgxdrUNy4/8dTH5YqFpDmH+HUk/ojxhAEQzHHM497RQXNpP8h6zWUmGhUakSjUpFYDWt7p002/O5/hvQLp40qo++Z+lthEDJhrEvm4ldn5Rrr0bLNaiUxdflp6Zo3DZt062lsz0JlwR/ll9fbwL0H/KNj7aqpelBqdekFdZIqPzckNDF+A9QUx2lZac2dP4hYhyg+rb89pcMkQgIwsh2xMqpSvbpjAKRpuL051ZCZ3GMm1kpyT3DddSNyXamdPq30IH92ghiYix//75o0cqQsyCqYK4Y7zZQKJ9kUQXp9EzA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS0PR01MB6001.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(52116014)(376014)(1800799024)(41320700013)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w8b5eDtfcoPMh9tRtZ2auwLLmD+1FNri/u3G7YJy8ofEnMZ06uJfl83oHxLNiNe9KdzeOl6gH5/4sg6QC9qCT8aFh5JcPVdiU9vwxz+nCVhabV7smVcHrOQD1SXTDrMMpMbsp1GmhAPiGEyBsbZcM9DXVNZK6RL+B8rFuAz3OqEEv4FOaNXFnkFPNgM+zXuJvLFssyq/kM+YRdjaawHDmnModuN6hK+zjDu8hKqvKSOE1SpV1HAIOjnKpdxJ3FoMMQNXM4ueCmspgfZpDPQ17KACkpuwS92fguUlLCqfvTDR1i4Trp97WV6IXK+JVlSITFI9HcO2SK32rUMievDswqANUypL+9d+Pp9cQ0TiPuPEOWhykEhDW7yLEoSBsUsuc9i9R9KRqY4MxCZDYJNNAY1k8wRksQtMwr6ChbKbBPKKV+yaOVqxg0MQCvrCl28P+7d6UDi1COGzhqATaOr1/ukf7vDI1V1wX6ZxZSDS9higijHVlmhFd3vgSrHrRwzI88Hg9zUcBzUFRIeg6m80/tJDrw6LLfjD1wE6b8fNZGEsHToOWaN+zU5Uxm8LoksAZ+XjCpqRV2FzemJ6S9A95CkrFjaRfRAG0T4hj/VYp1eD0R7G5mut6kwlNaeh72m9G9ejshjyrAgra65iazHRm8DPN7GYmvx/FQPZuJMFdk02fACyb8nMS3hp8inQPLtVPObZHteciT0mKwxcccwY55jdgb6o3/qkam8uFlTJrd6U1+OoVVEEd3/W41UbiI2ckCyC2Sj8Bc3uzYV0uEcq87dp1+7KWJeXWh913Y3mVL3dfNCcs2e/zin+z+7dkwaAMLF/2AIhMYhJZnELJGsgitlFfL8R9ZcR5n7y/UP+9X8ToGdoCU1RuCcozBemJIhTVLbv0lf/P+hwQpnazjGrXL2nzSqupyipGYssVF1AUhYuxsBsJmyFLqeUyrahEHIbiWKQbsjyZ6KKOq2XSGCSw1X2u7VIQSV3vKaHmPi+jfHcoLqd0sMG6aHKqHhJb8W4ZDG+oLJimFhvDSlafG3efqS7h9TevR75oHUSSS0Y9e0s8mEN74zVxl1scpTLIJBqnH0Y6oe6+SdFHRVCrK5r4bxx839mdF3Y2XvovfvFjCYJSH3MSrxOTzyx2rswPSxYnMDT3DZ9RDjqMWNb1adwWEisy47krEAjhlzEU6fBotPUphNr4drQGcMzT/nmC/F/J9L2bgRzTWYf7FzeIbnY91bIwyUCyN+/0n1hEHik7Jju10NzmglNwYyRho/M6UDnS/I0f1NXdf/ZN2Xk7AqVnuVUqUm8wU5PHkzAOdGUzTxhhUnKDbaj2E5jS8MuKXFWbo/1vtcURFIFQX8vc2IsmDOcVyo6ciaUgZMvvQhsm48xs3jY1DZaqU4965e6Uv8y++1kfuik0T37rQFEBzjDnL7grXN2bu4E47CFbXgMiXX/hizFRU6yho/CjIR/aOpIkbRuTwDL+j4q4pZSeOv44hBbdGv97mY65Sjp4ZL9nWtGGnaqhbsvJlp1KTFDM7E5R+i1ZTkRGGVpeZ+7YyBZUzmt2Tz4gsDjqnk/6oYlvMWeBtYcc0KHgCzn8T04wPBuxve/Y5UcuLUXw83ECwQ1jA== X-OriginatorOrg: es.takushoku-u.ac.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc3c9a7-d4be-454f-3481-08dcb1d2e687 X-MS-Exchange-CrossTenant-AuthSource: OS0PR01MB6001.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 02:37:35.9567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 853333e5-13b1-4738-ae04-bfb589cf2665 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LMvS15kZkdmV8puDzSmRwxKAGZOvtibvJfik49nxM1ElMfsE3x7fpUCxaZuuPykOMskjmGPTb8NwyG2Mx3bU/saN31KqarshFrinh3mmBR8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB6032 Subject: [FFmpeg-devel] [PATCH v6 1/3] avcodec/jpeg2000dec: Add support for CAP and CPF markers 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: Osamu Watanabe , pal@sandflow.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Qd3WdglY5pbx This commit adds support for CAP and CPF markers. Decoder will exit when encountering an illegal codestream. It is confirmed that the decoder passes all the test cases in FATE and ISO/IEC 15444-4. The subject was wrong in the v5 set of patches. The v6 corrects it. Signed-off-by: Osamu Watanabe --- libavcodec/jpeg2000.h | 8 +++ libavcodec/jpeg2000dec.c | 128 ++++++++++++++++++++++++++++++++++++++- libavcodec/jpeg2000dec.h | 7 +++ 3 files changed, 142 insertions(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h index d004c08f10..4bdc38df7c 100644 --- a/libavcodec/jpeg2000.h +++ b/libavcodec/jpeg2000.h @@ -37,12 +37,14 @@ enum Jpeg2000Markers { JPEG2000_SOC = 0xff4f, // start of codestream + JPEG2000_CAP = 0xff50, // extended capabilities JPEG2000_SIZ = 0xff51, // image and tile size JPEG2000_COD, // coding style default JPEG2000_COC, // coding style component JPEG2000_TLM = 0xff55, // tile-part length, main header JPEG2000_PLM = 0xff57, // packet length, main header JPEG2000_PLT, // packet length, tile-part header + JPEG2000_CPF, // corresponding profile JPEG2000_QCD = 0xff5c, // quantization default JPEG2000_QCC, // quantization component JPEG2000_RGN, // region of interest @@ -58,6 +60,12 @@ enum Jpeg2000Markers { JPEG2000_EOC = 0xffd9, // end of codestream }; +enum JPEG2000_Ccap15_b14_15_params { + HTJ2K_HTONLY = 0, // HTONLY, bit 14 and 15 are 0 + HTJ2K_HTDECLARED, // HTDECLARED, bit 14 = 1 and bit 15 = 0 + HTJ2K_MIXED = 3, // MIXED, bit 14 and 15 are 1 +}; + #define JPEG2000_SOP_FIXED_BYTES 0xFF910004 #define JPEG2000_SOP_BYTE_LENGTH 6 diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 091931b1ff..a1f82389fa 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -408,6 +408,73 @@ static int get_siz(Jpeg2000DecoderContext *s) s->avctx->bits_per_raw_sample = s->precision; return 0; } +/* get extended capabilities (CAP) marker segment */ +static int get_cap(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) +{ + uint32_t Pcap; + uint16_t Ccap_i[32] = { 0 }; + uint16_t Ccap_15; + uint8_t P; + + if (bytestream2_get_bytes_left(&s->g) < 6) { + av_log(s->avctx, AV_LOG_ERROR, "Insufficient space for CAP\n"); + return AVERROR_INVALIDDATA; + } + + Pcap = bytestream2_get_be32u(&s->g); + s->isHT = (Pcap >> (31 - (15 - 1))) & 1; + for (int i = 0; i < 32; i++) { + if ((Pcap >> (31 - i)) & 1) + Ccap_i[i] = bytestream2_get_be16u(&s->g); + } + Ccap_15 = Ccap_i[14]; + if (s->isHT == 1) { + av_log(s->avctx, AV_LOG_INFO, "This is an HTJ2K codestream.\n"); + // Bits 14-15 + switch ((Ccap_15 >> 14) & 0x3) { + case 0x3: + s->Ccap15_b14_15 = HTJ2K_MIXED; + break; + case 0x1: + s->Ccap15_b14_15 = HTJ2K_HTDECLARED; + break; + case 0x0: + s->Ccap15_b14_15 = HTJ2K_HTONLY; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "Unknown CCap value.\n"); + return AVERROR(EINVAL); + break; + } + // Bit 13 + if ((Ccap_15 >> 13) & 1) { + av_log(s->avctx, AV_LOG_ERROR, "MULTIHT set is not supported.\n"); + return AVERROR_PATCHWELCOME; + } + // Bit 12 + s->Ccap15_b12 = (Ccap_15 >> 12) & 1; + // Bit 11 + s->Ccap15_b11 = (Ccap_15 >> 11) & 1; + // Bit 5 + s->Ccap15_b05 = (Ccap_15 >> 5) & 1; + // Bit 0-4 + P = Ccap_15 & 0x1F; + if (!P) + s->HT_MAGB = 8; + else if (P < 20) + s->HT_MAGB = P + 8; + else if (P < 31) + s->HT_MAGB = 4 * (P - 19) + 27; + else + s->HT_MAGB = 74; + + if (s->HT_MAGB > 31) { + av_log(s->avctx, AV_LOG_ERROR, "Available internal precision is exceeded (MAGB> 31).\n"); + return AVERROR_PATCHWELCOME; + } + } + return 0; +} /* get common part for COD and COC segments */ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) @@ -802,6 +869,15 @@ static int read_crg(Jpeg2000DecoderContext *s, int n) bytestream2_skip(&s->g, n - 2); return 0; } + +static int read_cpf(Jpeg2000DecoderContext *s, int n) +{ + if (bytestream2_get_bytes_left(&s->g) < (n - 2)) + return AVERROR_INVALIDDATA; + bytestream2_skip(&s->g, n - 2); + return 0; +} + /* Tile-part lengths: see ISO 15444-1:2002, section A.7.1 * Used to know the number of tile parts and lengths. * There may be multiple TLMs in the header. @@ -965,6 +1041,14 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) comp->roi_shift = s->roi_shift[compno]; if (!codsty->init) return AVERROR_INVALIDDATA; + if (s->isHT && (!s->Ccap15_b05) && (!codsty->transform)) { + av_log(s->avctx, AV_LOG_ERROR, "Transformation = 0 (lossy DWT) is found in HTREV HT set\n"); + return AVERROR_INVALIDDATA; + } + if (s->isHT && s->Ccap15_b14_15 != (codsty->cblk_style >> 6) && s->Ccap15_b14_15 != HTJ2K_HTONLY) { + av_log(s->avctx, AV_LOG_ERROR, "SPcod/SPcoc value does not match bit 14-15 values of Ccap15\n"); + return AVERROR_INVALIDDATA; + } if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno], s->avctx)) @@ -2187,22 +2271,57 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) if (!s->tile) s->numXtiles = s->numYtiles = 0; break; + case JPEG2000_CAP: + if (!s->ncomponents) { + av_log(s->avctx, AV_LOG_ERROR, "CAP marker segment shall come after SIZ\n"); + return AVERROR_INVALIDDATA; + } + ret = get_cap(s, codsty); + break; case JPEG2000_COC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "COC marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_coc(s, codsty, properties); break; case JPEG2000_COD: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "COD marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_cod(s, codsty, properties); break; case JPEG2000_RGN: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "RGB marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_rgn(s, len); + if ((!s->Ccap15_b12) && s->isHT) { + av_log(s->avctx, AV_LOG_ERROR, "RGN marker is found in RGNFREE HT set\n"); + return AVERROR_INVALIDDATA; + } break; case JPEG2000_QCC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "QCC marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_qcc(s, len, qntsty, properties); break; case JPEG2000_QCD: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "QCD marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_qcd(s, len, qntsty, properties); break; case JPEG2000_POC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, "POC marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_poc(s, len, poc); break; case JPEG2000_SOT: @@ -2252,9 +2371,16 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) "Cannot have both PPT and PPM marker.\n"); return AVERROR_INVALIDDATA; } - + if ((!s->Ccap15_b11) && s->isHT) { + av_log(s->avctx, AV_LOG_ERROR, "PPT marker is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_ppt(s, len); break; + case JPEG2000_CPF: + // Corresponding profile marker + ret = read_cpf(s, len); + break; default: av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4"PRIX16" at pos 0x%X\n", diff --git a/libavcodec/jpeg2000dec.h b/libavcodec/jpeg2000dec.h index d0ca6e7a79..326a572722 100644 --- a/libavcodec/jpeg2000dec.h +++ b/libavcodec/jpeg2000dec.h @@ -112,6 +112,13 @@ typedef struct Jpeg2000DecoderContext { Jpeg2000Tile *tile; Jpeg2000DSPContext dsp; + uint8_t isHT; // HTJ2K? + uint8_t Ccap15_b14_15; // HTONLY(= 0) or HTDECLARED(= 1) or MIXED(= 3) ? + uint8_t Ccap15_b12; // RGNFREE(= 0) or RGN(= 1)? + uint8_t Ccap15_b11; // HOMOGENEOUS(= 0) or HETEROGENEOUS(= 1) ? + uint8_t Ccap15_b05; // HTREV(= 0) or HTIRV(= 1) ? + uint8_t HT_MAGB; // MAGB value + /*options parameters*/ int reduction_factor; } Jpeg2000DecoderContext;