/*1* Copyright (c) 1999-2000 Image Power, Inc. and the University of2* British Columbia.3* Copyright (c) 2001-2002 Michael David Adams.4* All rights reserved.5*/67/*8* Modified by Andrey Kiselev <[email protected]> to handle UUID9* box properly.10*/1112/* __START_OF_JASPER_LICENSE__13*14* JasPer License Version 2.015*16* Copyright (c) 2001-2006 Michael David Adams17* Copyright (c) 1999-2000 Image Power, Inc.18* Copyright (c) 1999-2000 The University of British Columbia19*20* All rights reserved.21*22* Permission is hereby granted, free of charge, to any person (the23* "User") obtaining a copy of this software and associated documentation24* files (the "Software"), to deal in the Software without restriction,25* including without limitation the rights to use, copy, modify, merge,26* publish, distribute, and/or sell copies of the Software, and to permit27* persons to whom the Software is furnished to do so, subject to the28* following conditions:29*30* 1. The above copyright notices and this permission notice (which31* includes the disclaimer below) shall be included in all copies or32* substantial portions of the Software.33*34* 2. The name of a copyright holder shall not be used to endorse or35* promote products derived from the Software without specific prior36* written permission.37*38* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS39* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER40* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS41* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING42* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A43* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO44* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL45* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING46* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,47* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION48* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE49* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE50* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.51* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS52* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL53* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS54* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE55* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE56* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL57* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,58* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL59* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH60* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,61* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH62* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY63* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.64*65* __END_OF_JASPER_LICENSE__66*/6768/*69* JP2 Library70*71* $Id: jp2_cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $72*/7374#ifndef JP2_COD_H75#define JP2_COD_H7677/******************************************************************************\78* Includes.79\******************************************************************************/8081#include "jasper/jas_types.h"8283/******************************************************************************\84* Macros.85\******************************************************************************/8687#define JP2_SPTOBPC(s, p) \88((((p) - 1) & 0x7f) | (((s) & 1) << 7))8990/******************************************************************************\91* Box class.92\******************************************************************************/9394#define JP2_BOX_HDRLEN(ext) ((ext) ? 16 : 8)9596/* Box types. */97#define JP2_BOX_JP 0x6a502020 /* Signature */98#define JP2_BOX_FTYP 0x66747970 /* File Type */99#define JP2_BOX_JP2H 0x6a703268 /* JP2 Header */100#define JP2_BOX_IHDR 0x69686472 /* Image Header */101#define JP2_BOX_BPCC 0x62706363 /* Bits Per Component */102#define JP2_BOX_COLR 0x636f6c72 /* Color Specification */103#define JP2_BOX_PCLR 0x70636c72 /* Palette */104#define JP2_BOX_CMAP 0x636d6170 /* Component Mapping */105#define JP2_BOX_CDEF 0x63646566 /* Channel Definition */106#define JP2_BOX_RES 0x72657320 /* Resolution */107#define JP2_BOX_RESC 0x72657363 /* Capture Resolution */108#define JP2_BOX_RESD 0x72657364 /* Default Display Resolution */109#define JP2_BOX_JP2C 0x6a703263 /* Contiguous Code Stream */110#define JP2_BOX_JP2I 0x6a703269 /* Intellectual Property */111#define JP2_BOX_XML 0x786d6c20 /* XML */112#define JP2_BOX_UUID 0x75756964 /* UUID */113#define JP2_BOX_UINF 0x75696e66 /* UUID Info */114#define JP2_BOX_ULST 0x75637374 /* UUID List */115#define JP2_BOX_URL 0x75726c20 /* URL */116117#define JP2_BOX_SUPER 0x01118#define JP2_BOX_NODATA 0x02119120/* JP box data. */121122#define JP2_JP_MAGIC 0x0d0a870a123#define JP2_JP_LEN 12124125typedef struct {126uint_fast32_t magic;127} jp2_jp_t;128129/* FTYP box data. */130131#define JP2_FTYP_MAXCOMPATCODES 32132#define JP2_FTYP_MAJVER 0x6a703220133#define JP2_FTYP_MINVER 0134#define JP2_FTYP_COMPATCODE JP2_FTYP_MAJVER135136typedef struct {137uint_fast32_t majver;138uint_fast32_t minver;139uint_fast32_t numcompatcodes;140uint_fast32_t compatcodes[JP2_FTYP_MAXCOMPATCODES];141} jp2_ftyp_t;142143/* IHDR box data. */144145#define JP2_IHDR_COMPTYPE 7146#define JP2_IHDR_BPCNULL 255147148typedef struct {149uint_fast32_t width;150uint_fast32_t height;151uint_fast16_t numcmpts;152uint_fast8_t bpc;153uint_fast8_t comptype;154uint_fast8_t csunk;155uint_fast8_t ipr;156} jp2_ihdr_t;157158/* BPCC box data. */159160typedef struct {161uint_fast16_t numcmpts;162uint_fast8_t *bpcs;163} jp2_bpcc_t;164165/* COLR box data. */166167#define JP2_COLR_ENUM 1168#define JP2_COLR_ICC 2169#define JP2_COLR_PRI 0170171#define JP2_COLR_SRGB 16172#define JP2_COLR_SGRAY 17173#define JP2_COLR_SYCC 18174175typedef struct {176uint_fast8_t method;177uint_fast8_t pri;178uint_fast8_t approx;179uint_fast32_t csid;180uint_fast8_t *iccp;181int iccplen;182/* XXX - Someday we ought to add ICC profile data here. */183} jp2_colr_t;184185/* PCLR box data. */186187typedef struct {188uint_fast16_t numlutents;189uint_fast8_t numchans;190int_fast32_t *lutdata;191uint_fast8_t *bpc;192} jp2_pclr_t;193194/* CDEF box per-channel data. */195196#define JP2_CDEF_RGB_R 1197#define JP2_CDEF_RGB_G 2198#define JP2_CDEF_RGB_B 3199200#define JP2_CDEF_YCBCR_Y 1201#define JP2_CDEF_YCBCR_CB 2202#define JP2_CDEF_YCBCR_CR 3203204#define JP2_CDEF_GRAY_Y 1205206#define JP2_CDEF_TYPE_COLOR 0207#define JP2_CDEF_TYPE_OPACITY 1208#define JP2_CDEF_TYPE_UNSPEC 65535209#define JP2_CDEF_ASOC_ALL 0210#define JP2_CDEF_ASOC_NONE 65535211212typedef struct {213uint_fast16_t channo;214uint_fast16_t type;215uint_fast16_t assoc;216} jp2_cdefchan_t;217218/* CDEF box data. */219220typedef struct {221uint_fast16_t numchans;222jp2_cdefchan_t *ents;223} jp2_cdef_t;224225typedef struct {226uint_fast16_t cmptno;227uint_fast8_t map;228uint_fast8_t pcol;229} jp2_cmapent_t;230231typedef struct {232uint_fast16_t numchans;233jp2_cmapent_t *ents;234} jp2_cmap_t;235236typedef struct {237uint_fast32_t datalen;238uint_fast8_t uuid[16];239uint_fast8_t *data;240} jp2_uuid_t;241242#define JP2_CMAP_DIRECT 0243#define JP2_CMAP_PALETTE 1244245/* Generic box. */246247struct jp2_boxops_s;248typedef struct {249250struct jp2_boxops_s *ops;251struct jp2_boxinfo_s *info;252253uint_fast32_t type;254255/* The length of the box including the (variable-length) header. */256uint_fast32_t len;257258/* The length of the box data. */259uint_fast32_t datalen;260261union {262jp2_jp_t jp;263jp2_ftyp_t ftyp;264jp2_ihdr_t ihdr;265jp2_bpcc_t bpcc;266jp2_colr_t colr;267jp2_pclr_t pclr;268jp2_cdef_t cdef;269jp2_cmap_t cmap;270jp2_uuid_t uuid;271} data;272273} jp2_box_t;274275typedef struct jp2_boxops_s {276void (*init)(jp2_box_t *box);277void (*destroy)(jp2_box_t *box);278int (*getdata)(jp2_box_t *box, jas_stream_t *in);279int (*putdata)(jp2_box_t *box, jas_stream_t *out);280void (*dumpdata)(jp2_box_t *box, FILE *out);281} jp2_boxops_t;282283/******************************************************************************\284*285\******************************************************************************/286287typedef struct jp2_boxinfo_s {288int type;289char *name;290int flags;291jp2_boxops_t ops;292} jp2_boxinfo_t;293294/******************************************************************************\295* Box class.296\******************************************************************************/297298jp2_box_t *jp2_box_create(int type);299void jp2_box_destroy(jp2_box_t *box);300jp2_box_t *jp2_box_get(jas_stream_t *in);301int jp2_box_put(jp2_box_t *box, jas_stream_t *out);302303#define JP2_DTYPETOBPC(dtype) \304((JAS_IMAGE_CDT_GETSGND(dtype) << 7) | (JAS_IMAGE_CDT_GETPREC(dtype) - 1))305#define JP2_BPCTODTYPE(bpc) \306(JAS_IMAGE_CDT_SETSGND(bpc >> 7) | JAS_IMAGE_CDT_SETPREC((bpc & 0x7f) + 1))307308#define ICC_CS_RGB 0x52474220309#define ICC_CS_YCBCR 0x59436272310#define ICC_CS_GRAY 0x47524159311312jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo);313314315#endif316317318