78 #include <jasper/jas_config.h>
80 #include <jasper/jas_stream.h>
81 #include <jasper/jas_seq.h>
82 #include <jasper/jas_cm.h>
99 #define JAS_IMAGE_KIBI (JAS_CAST(size_t, 1024))
100 #define JAS_IMAGE_MEBI (JAS_IMAGE_KIBI * JAS_IMAGE_KIBI)
103 #define JAS_IMAGE_INMEMTHRESH (256 * JAS_IMAGE_MEBI)
109 #define JAS_IMAGE_CT_UNKNOWN 0x10000
110 #define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff)
111 #define JAS_IMAGE_CT_OPACITY 0x08000
113 #define JAS_IMAGE_CT_RGB_R 0
114 #define JAS_IMAGE_CT_RGB_G 1
115 #define JAS_IMAGE_CT_RGB_B 2
117 #define JAS_IMAGE_CT_YCBCR_Y 0
118 #define JAS_IMAGE_CT_YCBCR_CB 1
119 #define JAS_IMAGE_CT_YCBCR_CR 2
121 #define JAS_IMAGE_CT_GRAY_Y 0
128 typedef int_fast32_t jas_image_coord_t;
129 #define JAS_IMAGE_COORD_MAX INT_FAST32_MAX
130 #define JAS_IMAGE_COORD_MIN INT_FAST32_MIN
133 typedef int_fast16_t jas_image_colorspc_t;
136 typedef int_fast32_t jas_image_cmpttype_t;
139 typedef int_fast16_t jas_image_smpltype_t;
149 jas_image_coord_t tlx_;
152 jas_image_coord_t tly_;
155 jas_image_coord_t hstep_;
158 jas_image_coord_t vstep_;
161 jas_image_coord_t width_;
164 jas_image_coord_t height_;
179 jas_stream_t *stream_;
185 jas_image_cmpttype_t type_;
194 jas_image_coord_t tlx_;
197 jas_image_coord_t tly_;
200 jas_image_coord_t brx_;
204 jas_image_coord_t bry_;
215 jas_image_cmpt_t **cmpts_;
218 jas_clrspc_t clrspc_;
220 jas_cmprof_t *cmprof_;
232 jas_image_coord_t tlx;
235 jas_image_coord_t tly;
238 jas_image_coord_t hstep;
241 jas_image_coord_t vstep;
244 jas_image_coord_t width;
247 jas_image_coord_t height;
260 } jas_image_cmptparm_t;
266 #define JAS_IMAGE_MAXFMTS 32
273 jas_image_t *(*decode)(jas_stream_t *in,
const char *opts);
276 int (*encode)(jas_image_t *image, jas_stream_t *out,
const char *opts);
279 int (*validate)(jas_stream_t *in);
282 } jas_image_fmtops_t;
300 jas_image_fmtops_t ops;
303 } jas_image_fmtinfo_t;
310 JAS_DLLEXPORT jas_image_t *jas_image_create(
int numcmpts,
311 jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc);
314 jas_image_t *jas_image_create0(
void);
317 JAS_DLLEXPORT jas_image_t *jas_image_copy(jas_image_t *image);
320 JAS_DLLEXPORT
void jas_image_destroy(jas_image_t *image);
323 #define jas_image_width(image) \
324 ((image)->brx_ - (image)->tlx_)
327 #define jas_image_height(image) \
328 ((image)->bry_ - (image)->tly_)
332 #define jas_image_tlx(image) \
337 #define jas_image_tly(image) \
342 #define jas_image_brx(image) \
347 #define jas_image_bry(image) \
351 #define jas_image_numcmpts(image) \
355 #define jas_image_clrspc(image) \
359 #define jas_image_setclrspc(image, clrspc) \
360 ((image)->clrspc_ = (clrspc))
362 #define jas_image_cmpttype(image, cmptno) \
363 ((image)->cmpts_[(cmptno)]->type_)
364 #define jas_image_setcmpttype(image, cmptno, type) \
365 ((image)->cmpts_[(cmptno)]->type_ = (type))
368 #define jas_image_cmptwidth(image, cmptno) \
369 ((image)->cmpts_[cmptno]->width_)
372 #define jas_image_cmptheight(image, cmptno) \
373 ((image)->cmpts_[cmptno]->height_)
376 #define jas_image_cmptsgnd(image, cmptno) \
377 ((image)->cmpts_[cmptno]->sgnd_)
380 #define jas_image_cmptprec(image, cmptno) \
381 ((image)->cmpts_[cmptno]->prec_)
384 #define jas_image_cmpthstep(image, cmptno) \
385 ((image)->cmpts_[cmptno]->hstep_)
388 #define jas_image_cmptvstep(image, cmptno) \
389 ((image)->cmpts_[cmptno]->vstep_)
392 #define jas_image_cmpttlx(image, cmptno) \
393 ((image)->cmpts_[cmptno]->tlx_)
396 #define jas_image_cmpttly(image, cmptno) \
397 ((image)->cmpts_[cmptno]->tly_)
401 #define jas_image_cmptbrx(image, cmptno) \
402 ((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \
403 (image)->cmpts_[cmptno]->hstep_)
407 #define jas_image_cmptbry(image, cmptno) \
408 ((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \
409 (image)->cmpts_[cmptno]->vstep_)
412 JAS_DLLEXPORT
bool jas_image_cmpt_domains_same(jas_image_t *image);
416 JAS_DLLEXPORT uint_fast32_t jas_image_rawsize(jas_image_t *image);
419 JAS_DLLEXPORT jas_image_t *jas_image_decode(jas_stream_t *in,
int fmt,
const char *optstr);
422 JAS_DLLEXPORT
int jas_image_encode(jas_image_t *image, jas_stream_t *out,
int fmt,
428 JAS_DLLEXPORT
int jas_image_readcmpt(jas_image_t *image,
int cmptno, jas_image_coord_t x,
429 jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
433 JAS_DLLEXPORT
int jas_image_writecmpt(jas_image_t *image,
int cmptno, jas_image_coord_t x,
434 jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
438 JAS_DLLEXPORT
void jas_image_delcmpt(jas_image_t *image,
int cmptno);
441 JAS_DLLEXPORT
int jas_image_addcmpt(jas_image_t *image,
int cmptno,
442 jas_image_cmptparm_t *cmptparm);
445 JAS_DLLEXPORT
int jas_image_copycmpt(jas_image_t *dstimage,
int dstcmptno,
446 jas_image_t *srcimage,
int srccmptno);
448 #define JAS_IMAGE_CDT_GETSGND(dtype) (((dtype) >> 7) & 1)
449 #define JAS_IMAGE_CDT_SETSGND(dtype) (((dtype) & 1) << 7)
450 #define JAS_IMAGE_CDT_GETPREC(dtype) ((dtype) & 0x7f)
451 #define JAS_IMAGE_CDT_SETPREC(dtype) ((dtype) & 0x7f)
453 #define jas_image_cmptdtype(image, cmptno) \
454 (JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_))
456 JAS_DLLEXPORT
int jas_image_depalettize(jas_image_t *image,
int cmptno,
int numlutents,
457 int_fast32_t *lutents,
int dtype,
int newcmptno);
459 JAS_DLLEXPORT
int jas_image_readcmptsample(jas_image_t *image,
int cmptno,
int x,
int y);
460 JAS_DLLEXPORT
void jas_image_writecmptsample(jas_image_t *image,
int cmptno,
int x,
int y,
463 JAS_DLLEXPORT
int jas_image_getcmptbytype(jas_image_t *image,
int ctype);
470 JAS_DLLEXPORT
void jas_image_clearfmts(
void);
473 JAS_DLLEXPORT
int jas_image_addfmt(
int id,
char *name,
char *ext,
char *desc,
474 jas_image_fmtops_t *ops);
477 JAS_DLLEXPORT
int jas_image_strtofmt(
char *s);
480 JAS_DLLEXPORT
char *jas_image_fmttostr(
int fmt);
483 JAS_DLLEXPORT jas_image_fmtinfo_t *jas_image_lookupfmtbyid(
int id);
486 JAS_DLLEXPORT jas_image_fmtinfo_t *jas_image_lookupfmtbyname(
const char *name);
489 JAS_DLLEXPORT
int jas_image_fmtfromname(
char *filename);
492 JAS_DLLEXPORT
int jas_image_getfmt(jas_stream_t *in);
495 #define jas_image_cmprof(image) ((image)->cmprof_)
496 int jas_image_ishomosamp(jas_image_t *image);
497 int jas_image_sampcmpt(jas_image_t *image,
int cmptno,
int newcmptno,
498 jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs,
499 jas_image_coord_t vs,
int sgnd,
int prec);
500 int jas_image_writecmpt2(jas_image_t *image,
int cmptno, jas_image_coord_t x,
501 jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
503 int jas_image_readcmpt2(jas_image_t *image,
int cmptno, jas_image_coord_t x,
504 jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
507 #define jas_image_setcmprof(image, cmprof) ((image)->cmprof_ = cmprof)
508 JAS_DLLEXPORT jas_image_t *jas_image_chclrspc(jas_image_t *image, jas_cmprof_t *outprof,
510 void jas_image_dump(jas_image_t *image, FILE *out);
516 #if !defined(EXCLUDE_JPG_SUPPORT)
518 jas_image_t *jpg_decode(jas_stream_t *in,
const char *optstr);
519 int jpg_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
520 int jpg_validate(jas_stream_t *in);
523 #if !defined(EXCLUDE_MIF_SUPPORT)
525 jas_image_t *mif_decode(jas_stream_t *in,
const char *optstr);
526 int mif_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
527 int mif_validate(jas_stream_t *in);
530 #if !defined(EXCLUDE_PNM_SUPPORT)
532 jas_image_t *pnm_decode(jas_stream_t *in,
const char *optstr);
533 int pnm_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
534 int pnm_validate(jas_stream_t *in);
537 #if !defined(EXCLUDE_RAS_SUPPORT)
539 jas_image_t *ras_decode(jas_stream_t *in,
const char *optstr);
540 int ras_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
541 int ras_validate(jas_stream_t *in);
544 #if !defined(EXCLUDE_BMP_SUPPORT)
546 jas_image_t *bmp_decode(jas_stream_t *in,
const char *optstr);
547 int bmp_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
548 int bmp_validate(jas_stream_t *in);
551 #if !defined(EXCLUDE_JP2_SUPPORT)
553 jas_image_t *jp2_decode(jas_stream_t *in,
const char *optstr);
554 int jp2_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
555 int jp2_validate(jas_stream_t *in);
558 #if !defined(EXCLUDE_JPC_SUPPORT)
560 jas_image_t *jpc_decode(jas_stream_t *in,
const char *optstr);
561 int jpc_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
562 int jpc_validate(jas_stream_t *in);
565 #if !defined(EXCLUDE_PGX_SUPPORT)
567 jas_image_t *pgx_decode(jas_stream_t *in,
const char *optstr);
568 int pgx_encode(jas_image_t *image, jas_stream_t *out,
const char *optstr);
569 int pgx_validate(jas_stream_t *in);