Path: blob/master/3rdparty/libjasper/jasper/jas_image.h
16337 views
/*1* Copyright (c) 1999-2000 Image Power, Inc. and the University of2* British Columbia.3* Copyright (c) 2001-2003 Michael David Adams.4* All rights reserved.5*/67/* __START_OF_JASPER_LICENSE__8*9* JasPer License Version 2.010*11* Copyright (c) 2001-2006 Michael David Adams12* Copyright (c) 1999-2000 Image Power, Inc.13* Copyright (c) 1999-2000 The University of British Columbia14*15* All rights reserved.16*17* Permission is hereby granted, free of charge, to any person (the18* "User") obtaining a copy of this software and associated documentation19* files (the "Software"), to deal in the Software without restriction,20* including without limitation the rights to use, copy, modify, merge,21* publish, distribute, and/or sell copies of the Software, and to permit22* persons to whom the Software is furnished to do so, subject to the23* following conditions:24*25* 1. The above copyright notices and this permission notice (which26* includes the disclaimer below) shall be included in all copies or27* substantial portions of the Software.28*29* 2. The name of a copyright holder shall not be used to endorse or30* promote products derived from the Software without specific prior31* written permission.32*33* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS34* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER35* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS36* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING37* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A38* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO39* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL40* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING41* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,42* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION43* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE44* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE45* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.46* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS47* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL48* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS49* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE50* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE51* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL52* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,53* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL54* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH55* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,56* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH57* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY58* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.59*60* __END_OF_JASPER_LICENSE__61*/6263/*64* Image Class65*66* $Id: jas_image.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $67*/6869#ifndef JAS_IMAGE_H70#define JAS_IMAGE_H7172/******************************************************************************\73* Includes.74\******************************************************************************/7576#include <jasper/jas_config.h>77#include <jasper/jas_stream.h>78#include <jasper/jas_seq.h>79#include <jasper/jas_cm.h>80#include <stdio.h>8182#ifdef __cplusplus83extern "C" {84#endif8586/******************************************************************************\87* Constants.88\******************************************************************************/8990/*91* Miscellaneous constants.92*/9394/* The threshold at which image data is no longer stored in memory. */95#define JAS_IMAGE_INMEMTHRESH (16 * 1024 * 1024)9697/*98* Component types99*/100101#define JAS_IMAGE_CT_UNKNOWN 0x10000102#define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff)103#define JAS_IMAGE_CT_OPACITY 0x08000104105#define JAS_IMAGE_CT_RGB_R 0106#define JAS_IMAGE_CT_RGB_G 1107#define JAS_IMAGE_CT_RGB_B 2108109#define JAS_IMAGE_CT_YCBCR_Y 0110#define JAS_IMAGE_CT_YCBCR_CB 1111#define JAS_IMAGE_CT_YCBCR_CR 2112113#define JAS_IMAGE_CT_GRAY_Y 0114115/******************************************************************************\116* Simple types.117\******************************************************************************/118119/* Image coordinate. */120typedef int_fast32_t jas_image_coord_t;121122/* Color space (e.g., RGB, YCbCr). */123typedef int_fast16_t jas_image_colorspc_t;124125/* Component type (e.g., color, opacity). */126typedef int_fast32_t jas_image_cmpttype_t;127128/* Component sample data format (e.g., real/integer, signedness, precision). */129typedef int_fast16_t jas_image_smpltype_t;130131/******************************************************************************\132* Image class and supporting classes.133\******************************************************************************/134135/* Image component class. */136137typedef struct {138139jas_image_coord_t tlx_;140/* The x-coordinate of the top-left corner of the component. */141142jas_image_coord_t tly_;143/* The y-coordinate of the top-left corner of the component. */144145jas_image_coord_t hstep_;146/* The horizontal sampling period in units of the reference grid. */147148jas_image_coord_t vstep_;149/* The vertical sampling period in units of the reference grid. */150151jas_image_coord_t width_;152/* The component width in samples. */153154jas_image_coord_t height_;155/* The component height in samples. */156157#ifdef FIX_ME158int smpltype_;159#else160int prec_;161/* The precision of the sample data (i.e., the number of bits per162sample). If the samples are signed values, this quantity163includes the sign bit. */164165int sgnd_;166/* The signedness of the sample data. */167#endif168169jas_stream_t *stream_;170/* The stream containing the component data. */171172int cps_;173/* The number of characters per sample in the stream. */174175jas_image_cmpttype_t type_;176/* The type of component (e.g., opacity, red, green, blue, luma). */177178} jas_image_cmpt_t;179180/* Image class. */181182typedef struct {183184jas_image_coord_t tlx_;185/* The x-coordinate of the top-left corner of the image bounding box. */186187jas_image_coord_t tly_;188/* The y-coordinate of the top-left corner of the image bounding box. */189190jas_image_coord_t brx_;191/* The x-coordinate of the bottom-right corner of the image bounding192box (plus one). */193194jas_image_coord_t bry_;195/* The y-coordinate of the bottom-right corner of the image bounding196box (plus one). */197198int numcmpts_;199/* The number of components. */200201int maxcmpts_;202/* The maximum number of components that this image can have (i.e., the203allocated size of the components array). */204205jas_image_cmpt_t **cmpts_;206/* Per-component information. */207208jas_clrspc_t clrspc_;209210jas_cmprof_t *cmprof_;211212bool inmem_;213214} jas_image_t;215216/* Component parameters class. */217/* This data type exists solely/mainly for the purposes of the218jas_image_create function. */219220typedef struct {221222jas_image_coord_t tlx;223/* The x-coordinate of the top-left corner of the component. */224225jas_image_coord_t tly;226/* The y-coordinate of the top-left corner of the component. */227228jas_image_coord_t hstep;229/* The horizontal sampling period in units of the reference grid. */230231jas_image_coord_t vstep;232/* The vertical sampling period in units of the reference grid. */233234jas_image_coord_t width;235/* The width of the component in samples. */236237jas_image_coord_t height;238/* The height of the component in samples. */239240#ifdef FIX_ME241int smpltype;242#else243int prec;244/* The precision of the component sample data. */245246int sgnd;247/* The signedness of the component sample data. */248#endif249250} jas_image_cmptparm_t;251252/******************************************************************************\253* File format related classes.254\******************************************************************************/255256#define JAS_IMAGE_MAXFMTS 32257/* The maximum number of image data formats supported. */258259/* Image format-dependent operations. */260261typedef struct {262263jas_image_t *(*decode)(jas_stream_t *in, char *opts);264/* Decode image data from a stream. */265266int (*encode)(jas_image_t *image, jas_stream_t *out, char *opts);267/* Encode image data to a stream. */268269int (*validate)(jas_stream_t *in);270/* Determine if stream data is in a particular format. */271272} jas_image_fmtops_t;273274/* Image format information. */275276typedef struct {277278int id;279/* The ID for this format. */280281char *name;282/* The name by which this format is identified. */283284char *ext;285/* The file name extension associated with this format. */286287char *desc;288/* A brief description of the format. */289290jas_image_fmtops_t ops;291/* The operations for this format. */292293} jas_image_fmtinfo_t;294295/******************************************************************************\296* Image operations.297\******************************************************************************/298299/* Create an image. */300jas_image_t *jas_image_create(int numcmpts,301jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc);302303/* Create an "empty" image. */304jas_image_t *jas_image_create0(void);305306/* Clone an image. */307jas_image_t *jas_image_copy(jas_image_t *image);308309/* Deallocate any resources associated with an image. */310void jas_image_destroy(jas_image_t *image);311312/* Get the width of the image in units of the image reference grid. */313#define jas_image_width(image) \314((image)->brx_ - (image)->tlx_)315316/* Get the height of the image in units of the image reference grid. */317#define jas_image_height(image) \318((image)->bry_ - (image)->tly_)319320/* Get the x-coordinate of the top-left corner of the image bounding box321on the reference grid. */322#define jas_image_tlx(image) \323((image)->tlx_)324325/* Get the y-coordinate of the top-left corner of the image bounding box326on the reference grid. */327#define jas_image_tly(image) \328((image)->tly_)329330/* Get the x-coordinate of the bottom-right corner of the image bounding box331on the reference grid (plus one). */332#define jas_image_brx(image) \333((image)->brx_)334335/* Get the y-coordinate of the bottom-right corner of the image bounding box336on the reference grid (plus one). */337#define jas_image_bry(image) \338((image)->bry_)339340/* Get the number of image components. */341#define jas_image_numcmpts(image) \342((image)->numcmpts_)343344/* Get the color model used by the image. */345#define jas_image_clrspc(image) \346((image)->clrspc_)347348/* Set the color model for an image. */349#define jas_image_setclrspc(image, clrspc) \350((image)->clrspc_ = (clrspc))351352#define jas_image_cmpttype(image, cmptno) \353((image)->cmpts_[(cmptno)]->type_)354#define jas_image_setcmpttype(image, cmptno, type) \355((image)->cmpts_[(cmptno)]->type_ = (type))356357/* Get the width of a component. */358#define jas_image_cmptwidth(image, cmptno) \359((image)->cmpts_[cmptno]->width_)360361/* Get the height of a component. */362#define jas_image_cmptheight(image, cmptno) \363((image)->cmpts_[cmptno]->height_)364365/* Get the signedness of the sample data for a component. */366#define jas_image_cmptsgnd(image, cmptno) \367((image)->cmpts_[cmptno]->sgnd_)368369/* Get the precision of the sample data for a component. */370#define jas_image_cmptprec(image, cmptno) \371((image)->cmpts_[cmptno]->prec_)372373/* Get the horizontal subsampling factor for a component. */374#define jas_image_cmpthstep(image, cmptno) \375((image)->cmpts_[cmptno]->hstep_)376377/* Get the vertical subsampling factor for a component. */378#define jas_image_cmptvstep(image, cmptno) \379((image)->cmpts_[cmptno]->vstep_)380381/* Get the x-coordinate of the top-left corner of a component. */382#define jas_image_cmpttlx(image, cmptno) \383((image)->cmpts_[cmptno]->tlx_)384385/* Get the y-coordinate of the top-left corner of a component. */386#define jas_image_cmpttly(image, cmptno) \387((image)->cmpts_[cmptno]->tly_)388389/* Get the x-coordinate of the bottom-right corner of a component390(plus "one"). */391#define jas_image_cmptbrx(image, cmptno) \392((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \393(image)->cmpts_[cmptno]->hstep_)394395/* Get the y-coordinate of the bottom-right corner of a component396(plus "one"). */397#define jas_image_cmptbry(image, cmptno) \398((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \399(image)->cmpts_[cmptno]->vstep_)400401/* Get the raw size of an image (i.e., the nominal size of the image without402any compression. */403uint_fast32_t jas_image_rawsize(jas_image_t *image);404405/* Create an image from a stream in some specified format. */406jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr);407408/* Write an image to a stream in a specified format. */409int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt,410char *optstr);411412/* Read a rectangular region of an image component. */413/* The position and size of the rectangular region to be read is specified414relative to the component's coordinate system. */415int jas_image_readcmpt(jas_image_t *image, int cmptno,416jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,417jas_matrix_t *data);418419/* Write a rectangular region of an image component. */420int jas_image_writecmpt(jas_image_t *image, int cmptno,421jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,422jas_matrix_t *data);423424/* Delete a component from an image. */425void jas_image_delcmpt(jas_image_t *image, int cmptno);426427/* Add a component to an image. */428int jas_image_addcmpt(jas_image_t *image, int cmptno,429jas_image_cmptparm_t *cmptparm);430431/* Copy a component from one image to another. */432int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno,433jas_image_t *srcimage, int srccmptno);434435#define JAS_IMAGE_CDT_GETSGND(dtype) (((dtype) >> 7) & 1)436#define JAS_IMAGE_CDT_SETSGND(dtype) (((dtype) & 1) << 7)437#define JAS_IMAGE_CDT_GETPREC(dtype) ((dtype) & 0x7f)438#define JAS_IMAGE_CDT_SETPREC(dtype) ((dtype) & 0x7f)439440#define jas_image_cmptdtype(image, cmptno) \441(JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_))442443int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,444int_fast32_t *lutents, int dtype, int newcmptno);445446int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y);447void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y,448int_fast32_t v);449450int jas_image_getcmptbytype(jas_image_t *image, int ctype);451452/******************************************************************************\453* Image format-related operations.454\******************************************************************************/455456/* Clear the table of image formats. */457void jas_image_clearfmts(void);458459/* Add entry to table of image formats. */460int jas_image_addfmt(int id, char *name, char *ext, char *desc,461jas_image_fmtops_t *ops);462463/* Get the ID for the image format with the specified name. */464int jas_image_strtofmt(char *s);465466/* Get the name of the image format with the specified ID. */467char *jas_image_fmttostr(int fmt);468469/* Lookup image format information by the format ID. */470jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id);471472/* Lookup image format information by the format name. */473jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name);474475/* Guess the format of an image file based on its name. */476int jas_image_fmtfromname(char *filename);477478/* Get the format of image data in a stream. */479int jas_image_getfmt(jas_stream_t *in);480481482#define jas_image_cmprof(image) ((image)->cmprof_)483int jas_image_ishomosamp(jas_image_t *image);484int jas_image_sampcmpt(jas_image_t *image, int cmptno, int newcmptno,485jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs,486jas_image_coord_t vs, int sgnd, int prec);487int jas_image_writecmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,488jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,489long *buf);490int jas_image_readcmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,491jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,492long *buf);493494#define jas_image_setcmprof(image, cmprof) ((image)->cmprof_ = cmprof)495jas_image_t *jas_image_chclrspc(jas_image_t *image, jas_cmprof_t *outprof,496int intent);497void jas_image_dump(jas_image_t *image, FILE *out);498499/******************************************************************************\500* Image format-dependent operations.501\******************************************************************************/502503#if !defined(EXCLUDE_JPG_SUPPORT)504/* Format-dependent operations for JPG support. */505jas_image_t *jpg_decode(jas_stream_t *in, char *optstr);506int jpg_encode(jas_image_t *image, jas_stream_t *out, char *optstr);507int jpg_validate(jas_stream_t *in);508#endif509510#if !defined(EXCLUDE_MIF_SUPPORT)511/* Format-dependent operations for MIF support. */512jas_image_t *mif_decode(jas_stream_t *in, char *optstr);513int mif_encode(jas_image_t *image, jas_stream_t *out, char *optstr);514int mif_validate(jas_stream_t *in);515#endif516517#if !defined(EXCLUDE_PNM_SUPPORT)518/* Format-dependent operations for PNM support. */519jas_image_t *pnm_decode(jas_stream_t *in, char *optstr);520int pnm_encode(jas_image_t *image, jas_stream_t *out, char *optstr);521int pnm_validate(jas_stream_t *in);522#endif523524#if !defined(EXCLUDE_RAS_SUPPORT)525/* Format-dependent operations for Sun Rasterfile support. */526jas_image_t *ras_decode(jas_stream_t *in, char *optstr);527int ras_encode(jas_image_t *image, jas_stream_t *out, char *optstr);528int ras_validate(jas_stream_t *in);529#endif530531#if !defined(EXCLUDE_BMP_SUPPORT)532/* Format-dependent operations for BMP support. */533jas_image_t *bmp_decode(jas_stream_t *in, char *optstr);534int bmp_encode(jas_image_t *image, jas_stream_t *out, char *optstr);535int bmp_validate(jas_stream_t *in);536#endif537538#if !defined(EXCLUDE_JP2_SUPPORT)539/* Format-dependent operations for JP2 support. */540jas_image_t *jp2_decode(jas_stream_t *in, char *optstr);541int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr);542int jp2_validate(jas_stream_t *in);543#endif544545#if !defined(EXCLUDE_JPC_SUPPORT)546/* Format-dependent operations for JPEG-2000 code stream support. */547jas_image_t *jpc_decode(jas_stream_t *in, char *optstr);548int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr);549int jpc_validate(jas_stream_t *in);550#endif551552#if !defined(EXCLUDE_PGX_SUPPORT)553/* Format-dependent operations for PGX support. */554jas_image_t *pgx_decode(jas_stream_t *in, char *optstr);555int pgx_encode(jas_image_t *image, jas_stream_t *out, char *optstr);556int pgx_validate(jas_stream_t *in);557#endif558559#ifdef __cplusplus560}561#endif562563#endif564565566