/work/include/jasper/jas_image.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 1999-2000 Image Power, Inc. and the University of |
3 | | * British Columbia. |
4 | | * Copyright (c) 2001-2003 Michael David Adams. |
5 | | * All rights reserved. |
6 | | */ |
7 | | |
8 | | /* __START_OF_JASPER_LICENSE__ |
9 | | * |
10 | | * JasPer License Version 2.0 |
11 | | * |
12 | | * Copyright (c) 2001-2006 Michael David Adams |
13 | | * Copyright (c) 1999-2000 Image Power, Inc. |
14 | | * Copyright (c) 1999-2000 The University of British Columbia |
15 | | * |
16 | | * All rights reserved. |
17 | | * |
18 | | * Permission is hereby granted, free of charge, to any person (the |
19 | | * "User") obtaining a copy of this software and associated documentation |
20 | | * files (the "Software"), to deal in the Software without restriction, |
21 | | * including without limitation the rights to use, copy, modify, merge, |
22 | | * publish, distribute, and/or sell copies of the Software, and to permit |
23 | | * persons to whom the Software is furnished to do so, subject to the |
24 | | * following conditions: |
25 | | * |
26 | | * 1. The above copyright notices and this permission notice (which |
27 | | * includes the disclaimer below) shall be included in all copies or |
28 | | * substantial portions of the Software. |
29 | | * |
30 | | * 2. The name of a copyright holder shall not be used to endorse or |
31 | | * promote products derived from the Software without specific prior |
32 | | * written permission. |
33 | | * |
34 | | * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS |
35 | | * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER |
36 | | * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS |
37 | | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
38 | | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
39 | | * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO |
40 | | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
41 | | * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
42 | | * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
43 | | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
44 | | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE |
45 | | * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE |
46 | | * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. |
47 | | * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS |
48 | | * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL |
49 | | * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS |
50 | | * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE |
51 | | * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE |
52 | | * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL |
53 | | * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, |
54 | | * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL |
55 | | * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH |
56 | | * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, |
57 | | * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH |
58 | | * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY |
59 | | * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. |
60 | | * |
61 | | * __END_OF_JASPER_LICENSE__ |
62 | | */ |
63 | | |
64 | | /*! |
65 | | * @file jas_image.h |
66 | | * @brief JasPer Image Class |
67 | | */ |
68 | | |
69 | | #ifndef JAS_IMAGE_H |
70 | | #define JAS_IMAGE_H |
71 | | |
72 | | /******************************************************************************\ |
73 | | * Includes. |
74 | | \******************************************************************************/ |
75 | | |
76 | | /* The configuration header file should be included first. */ |
77 | | #include <jasper/jas_config.h> |
78 | | |
79 | | #include <jasper/jas_stream.h> |
80 | | #include <jasper/jas_types.h> |
81 | | #include <jasper/jas_seq.h> /* IWYU pragma: export */ |
82 | | #include <jasper/jas_cm.h> /* IWYU pragma: export */ |
83 | | #include <stdio.h> |
84 | | |
85 | | #ifdef __cplusplus |
86 | | extern "C" { |
87 | | #endif |
88 | | |
89 | | /*! |
90 | | * @addtogroup module_images |
91 | | * @{ |
92 | | */ |
93 | | |
94 | | /******************************************************************************\ |
95 | | * Constants. |
96 | | \******************************************************************************/ |
97 | | |
98 | | /* |
99 | | * Miscellaneous constants. |
100 | | */ |
101 | | |
102 | | /* Basic units */ |
103 | | #define JAS_IMAGE_KIBI (JAS_CAST(size_t, 1024)) |
104 | | #define JAS_IMAGE_MEBI (JAS_IMAGE_KIBI * JAS_IMAGE_KIBI) |
105 | | |
106 | | /* The threshold at which image data is no longer stored in memory. */ |
107 | | #define JAS_IMAGE_INMEMTHRESH (256 * JAS_IMAGE_MEBI) |
108 | | |
109 | | /* |
110 | | * Component types |
111 | | */ |
112 | | |
113 | | #define JAS_IMAGE_CT_UNKNOWN 0x10000 |
114 | 0 | #define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff) |
115 | 0 | #define JAS_IMAGE_CT_OPACITY 0x08000 |
116 | | |
117 | | #define JAS_IMAGE_CT_RGB_R 0 |
118 | | #define JAS_IMAGE_CT_RGB_G 1 |
119 | | #define JAS_IMAGE_CT_RGB_B 2 |
120 | | |
121 | 0 | #define JAS_IMAGE_CT_YCBCR_Y 0 |
122 | 0 | #define JAS_IMAGE_CT_YCBCR_CB 1 |
123 | 0 | #define JAS_IMAGE_CT_YCBCR_CR 2 |
124 | | |
125 | | #define JAS_IMAGE_CT_GRAY_Y 0 |
126 | | |
127 | | /******************************************************************************\ |
128 | | * Simple types. |
129 | | \******************************************************************************/ |
130 | | |
131 | | /*! |
132 | | @brief Image coordinate. |
133 | | */ |
134 | | typedef int_fast32_t jas_image_coord_t; |
135 | | #define JAS_IMAGE_COORD_MAX INT_FAST32_MAX |
136 | | #define JAS_IMAGE_COORD_MIN INT_FAST32_MIN |
137 | | |
138 | | /*! |
139 | | @brief Color space (e.g., RGB, YCbCr). |
140 | | */ |
141 | | typedef int_fast16_t jas_image_colorspc_t; |
142 | | |
143 | | /*! |
144 | | @brief Component type (e.g., color, opacity). |
145 | | */ |
146 | | typedef int_fast32_t jas_image_cmpttype_t; |
147 | | |
148 | | /*! |
149 | | @brief Component sample data format |
150 | | (e.g., real/integer, signedness, precision). |
151 | | */ |
152 | | typedef int_fast16_t jas_image_smpltype_t; |
153 | | |
154 | | /******************************************************************************\ |
155 | | * Image class and supporting classes. |
156 | | \******************************************************************************/ |
157 | | |
158 | | /*! |
159 | | @brief |
160 | | Image component class. |
161 | | |
162 | | @warning |
163 | | Library users should never directly access any of the members of this |
164 | | class. |
165 | | The functions/macros provided by the JasPer library API should always |
166 | | be used. |
167 | | */ |
168 | | typedef struct { |
169 | | |
170 | | /* The x-coordinate of the top-left corner of the component. */ |
171 | | jas_image_coord_t tlx_; |
172 | | |
173 | | /* The y-coordinate of the top-left corner of the component. */ |
174 | | jas_image_coord_t tly_; |
175 | | |
176 | | /* The horizontal sampling period in units of the reference grid. */ |
177 | | jas_image_coord_t hstep_; |
178 | | |
179 | | /* The vertical sampling period in units of the reference grid. */ |
180 | | jas_image_coord_t vstep_; |
181 | | |
182 | | /* The component width in samples. */ |
183 | | jas_image_coord_t width_; |
184 | | |
185 | | /* The component height in samples. */ |
186 | | jas_image_coord_t height_; |
187 | | |
188 | | /* The precision of the sample data (i.e., the number of bits per sample). |
189 | | If the samples are signed values, this quantity includes the sign bit. */ |
190 | | unsigned prec_; |
191 | | |
192 | | /* The signedness of the sample data. */ |
193 | | int sgnd_; |
194 | | |
195 | | /* The stream containing the component data. */ |
196 | | jas_stream_t *stream_; |
197 | | |
198 | | /* The number of characters per sample in the stream. */ |
199 | | unsigned cps_; |
200 | | |
201 | | /* The type of component (e.g., opacity, red, green, blue, luma). */ |
202 | | jas_image_cmpttype_t type_; |
203 | | |
204 | | } jas_image_cmpt_t; |
205 | | |
206 | | /*! |
207 | | @brief Image class. |
208 | | |
209 | | @warning |
210 | | Library users should never directly access any of the members of this |
211 | | class. |
212 | | The functions/macros provided by the JasPer library API should always |
213 | | be used. |
214 | | */ |
215 | | typedef struct { |
216 | | |
217 | | /* The x-coordinate of the top-left corner of the image bounding box. */ |
218 | | jas_image_coord_t tlx_; |
219 | | |
220 | | /* The y-coordinate of the top-left corner of the image bounding box. */ |
221 | | jas_image_coord_t tly_; |
222 | | |
223 | | /* The x-coordinate of the bottom-right corner of the image bounding |
224 | | box (plus one). */ |
225 | | jas_image_coord_t brx_; |
226 | | |
227 | | /* The y-coordinate of the bottom-right corner of the image bounding |
228 | | box (plus one). */ |
229 | | jas_image_coord_t bry_; |
230 | | |
231 | | /* The number of components. */ |
232 | | unsigned numcmpts_; |
233 | | |
234 | | /* The maximum number of components that this image can have (i.e., the |
235 | | allocated size of the components array). */ |
236 | | unsigned maxcmpts_; |
237 | | |
238 | | /* Per-component information. */ |
239 | | jas_image_cmpt_t **cmpts_; |
240 | | |
241 | | /* The color space. */ |
242 | | jas_clrspc_t clrspc_; |
243 | | |
244 | | /* The CM profile. */ |
245 | | jas_cmprof_t *cmprof_; |
246 | | |
247 | | //bool inmem_; |
248 | | |
249 | | } jas_image_t; |
250 | | |
251 | | /*! |
252 | | @brief Component parameters class. |
253 | | |
254 | | @details |
255 | | This data type exists solely/mainly for the purposes of the |
256 | | jas_image_create function. |
257 | | */ |
258 | | typedef struct { |
259 | | |
260 | | /* The x-coordinate of the top-left corner of the component. */ |
261 | | jas_image_coord_t tlx; |
262 | | |
263 | | /* The y-coordinate of the top-left corner of the component. */ |
264 | | jas_image_coord_t tly; |
265 | | |
266 | | /* The horizontal sampling period in units of the reference grid. */ |
267 | | jas_image_coord_t hstep; |
268 | | |
269 | | /* The vertical sampling period in units of the reference grid. */ |
270 | | jas_image_coord_t vstep; |
271 | | |
272 | | /* The width of the component in samples. */ |
273 | | jas_image_coord_t width; |
274 | | |
275 | | /* The height of the component in samples. */ |
276 | | jas_image_coord_t height; |
277 | | |
278 | | /* The precision of the component sample data. */ |
279 | | unsigned prec; |
280 | | |
281 | | /* The signedness of the component sample data. */ |
282 | | int sgnd; |
283 | | |
284 | | } jas_image_cmptparm_t; |
285 | | |
286 | | /******************************************************************************\ |
287 | | * File format related classes. |
288 | | \******************************************************************************/ |
289 | | |
290 | | /*! |
291 | | @brief The maximum number of image data formats supported. |
292 | | */ |
293 | | #define JAS_IMAGE_MAXFMTS 32 |
294 | | |
295 | | /*! |
296 | | @brief Image format-dependent operations. |
297 | | */ |
298 | | typedef struct { |
299 | | |
300 | | /*! Decode image data from a stream. */ |
301 | | jas_image_t *(*decode)(jas_stream_t *in, const char *opts); |
302 | | |
303 | | /*! Encode image data to a stream. */ |
304 | | int (*encode)(jas_image_t *image, jas_stream_t *out, const char *opts); |
305 | | |
306 | | /*! Determine if stream data is in a particular format. */ |
307 | | int (*validate)(jas_stream_t *in); |
308 | | |
309 | | } jas_image_fmtops_t; |
310 | | |
311 | | /*! |
312 | | @brief Image format information. |
313 | | */ |
314 | | typedef struct { |
315 | | |
316 | | /*! The ID for this format. */ |
317 | | int id; |
318 | | |
319 | | /*! The name by which this format is identified. */ |
320 | | char *name; |
321 | | |
322 | | /* The primary file name extension associated with this format. */ |
323 | | /* This member only exists for backward compatibility. */ |
324 | | char *ext; |
325 | | |
326 | | /*! The table of file name extensions associated with this format. */ |
327 | | char **exts; |
328 | | size_t max_exts; |
329 | | size_t num_exts; |
330 | | |
331 | | /*! A boolean flag indicating if this format is enabled. */ |
332 | | int enabled; |
333 | | |
334 | | /*! A brief description of the format. */ |
335 | | char *desc; |
336 | | |
337 | | /*! The operations for this format. */ |
338 | | jas_image_fmtops_t ops; |
339 | | |
340 | | } jas_image_fmtinfo_t; |
341 | | |
342 | | /******************************************************************************\ |
343 | | * Image operations. |
344 | | \******************************************************************************/ |
345 | | |
346 | | /*! |
347 | | @brief Create an image. |
348 | | */ |
349 | | JAS_EXPORT |
350 | | jas_image_t *jas_image_create(unsigned numcmpts, |
351 | | const jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc); |
352 | | |
353 | | /*! |
354 | | @brief Create an "empty" image. |
355 | | */ |
356 | | JAS_EXPORT |
357 | | jas_image_t *jas_image_create0(void); |
358 | | |
359 | | /*! |
360 | | @brief Clone an image. |
361 | | */ |
362 | | JAS_EXPORT |
363 | | jas_image_t *jas_image_copy(jas_image_t *image); |
364 | | |
365 | | /*! |
366 | | @brief Deallocate any resources associated with an image. |
367 | | */ |
368 | | JAS_EXPORT |
369 | | void jas_image_destroy(jas_image_t *image); |
370 | | |
371 | | /*! |
372 | | @brief Get the width of the image in units of the image reference grid. |
373 | | */ |
374 | | #define jas_image_width(image) \ |
375 | 0 | ((image)->brx_ - (image)->tlx_) |
376 | | |
377 | | /*! |
378 | | @brief Get the height of the image in units of the image reference grid. |
379 | | */ |
380 | | #define jas_image_height(image) \ |
381 | 0 | ((image)->bry_ - (image)->tly_) |
382 | | |
383 | | /*! |
384 | | @brief Get the x-coordinate of the top-left corner of the image bounding box |
385 | | on the reference grid. |
386 | | */ |
387 | | #define jas_image_tlx(image) \ |
388 | | ((image)->tlx_) |
389 | | |
390 | | /*! |
391 | | @brief Get the y-coordinate of the top-left corner of the image bounding box |
392 | | on the reference grid. |
393 | | */ |
394 | | #define jas_image_tly(image) \ |
395 | | ((image)->tly_) |
396 | | |
397 | | /*! |
398 | | @brief Get the x-coordinate of the bottom-right corner of the image bounding box |
399 | | on the reference grid (plus one). |
400 | | */ |
401 | | #define jas_image_brx(image) \ |
402 | | ((image)->brx_) |
403 | | |
404 | | /*! |
405 | | @brief Get the y-coordinate of the bottom-right corner of the image bounding |
406 | | box on the reference grid (plus one). |
407 | | */ |
408 | | #define jas_image_bry(image) \ |
409 | | ((image)->bry_) |
410 | | |
411 | | /*! |
412 | | @brief Get the number of image components. |
413 | | */ |
414 | | #define jas_image_numcmpts(image) \ |
415 | | ((image)->numcmpts_) |
416 | | |
417 | | /*! |
418 | | @brief Get the color model used by the image. |
419 | | */ |
420 | | #define jas_image_clrspc(image) \ |
421 | | ((image)->clrspc_) |
422 | | |
423 | | /*! |
424 | | @brief Set the color model for an image. |
425 | | */ |
426 | | #define jas_image_setclrspc(image, clrspc) \ |
427 | 0 | ((image)->clrspc_ = (clrspc)) |
428 | | |
429 | | #define jas_image_cmpttype(image, cmptno) \ |
430 | | ((image)->cmpts_[(cmptno)]->type_) |
431 | | #define jas_image_setcmpttype(image, cmptno, type) \ |
432 | 0 | ((image)->cmpts_[(cmptno)]->type_ = (type)) |
433 | | |
434 | | /*! |
435 | | @brief Get the width of a component. |
436 | | */ |
437 | | #define jas_image_cmptwidth(image, cmptno) \ |
438 | 0 | ((image)->cmpts_[cmptno]->width_) |
439 | | |
440 | | /*! |
441 | | @brief Get the height of a component. |
442 | | */ |
443 | | #define jas_image_cmptheight(image, cmptno) \ |
444 | 0 | ((image)->cmpts_[cmptno]->height_) |
445 | | |
446 | | /*! |
447 | | @brief Get the signedness of the sample data for a component. |
448 | | */ |
449 | | #define jas_image_cmptsgnd(image, cmptno) \ |
450 | 0 | ((image)->cmpts_[cmptno]->sgnd_) |
451 | | |
452 | | /*! |
453 | | @brief Get the precision of the sample data for a component. |
454 | | */ |
455 | | #define jas_image_cmptprec(image, cmptno) \ |
456 | 0 | ((image)->cmpts_[cmptno]->prec_) |
457 | | |
458 | | /*! |
459 | | @brief Get the horizontal subsampling factor for a component. |
460 | | */ |
461 | | #define jas_image_cmpthstep(image, cmptno) \ |
462 | 0 | ((image)->cmpts_[cmptno]->hstep_) |
463 | | |
464 | | /*! |
465 | | @brief Get the vertical subsampling factor for a component. |
466 | | */ |
467 | | #define jas_image_cmptvstep(image, cmptno) \ |
468 | 0 | ((image)->cmpts_[cmptno]->vstep_) |
469 | | |
470 | | /*! |
471 | | @brief Get the x-coordinate of the top-left corner of a component. |
472 | | */ |
473 | | #define jas_image_cmpttlx(image, cmptno) \ |
474 | 0 | ((image)->cmpts_[cmptno]->tlx_) |
475 | | |
476 | | /*! |
477 | | @brief Get the y-coordinate of the top-left corner of a component. |
478 | | */ |
479 | | #define jas_image_cmpttly(image, cmptno) \ |
480 | 0 | ((image)->cmpts_[cmptno]->tly_) |
481 | | |
482 | | /*! |
483 | | @brief Get the x-coordinate of the bottom-right corner of a component |
484 | | (plus "one"). |
485 | | */ |
486 | | #define jas_image_cmptbrx(image, cmptno) \ |
487 | 0 | ((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \ |
488 | 0 | (image)->cmpts_[cmptno]->hstep_) |
489 | | |
490 | | /*! |
491 | | @brief Get the y-coordinate of the bottom-right corner of a component |
492 | | (plus "one"). |
493 | | */ |
494 | | #define jas_image_cmptbry(image, cmptno) \ |
495 | 0 | ((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \ |
496 | 0 | (image)->cmpts_[cmptno]->vstep_) |
497 | | |
498 | | /*! |
499 | | @brief Test if all components are specified at the same positions in space. |
500 | | */ |
501 | | JAS_ATTRIBUTE_PURE |
502 | | JAS_EXPORT |
503 | | bool jas_image_cmpt_domains_same(const jas_image_t *image); |
504 | | |
505 | | /*! |
506 | | @brief Get the raw size of an image |
507 | | (i.e., the nominal size of the image without any compression. |
508 | | */ |
509 | | JAS_ATTRIBUTE_PURE |
510 | | JAS_EXPORT |
511 | | uint_fast32_t jas_image_rawsize(const jas_image_t *image); |
512 | | |
513 | | /*! |
514 | | @brief Create an image from a stream in some specified format. |
515 | | */ |
516 | | JAS_EXPORT |
517 | | jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, const char *optstr); |
518 | | |
519 | | /*! |
520 | | @brief Write an image to a stream in a specified format. |
521 | | */ |
522 | | JAS_EXPORT |
523 | | int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, |
524 | | const char *optstr); |
525 | | |
526 | | /*! |
527 | | @brief Read a rectangular region of an image component. |
528 | | |
529 | | @details |
530 | | The position and size of the rectangular region to be read is specified |
531 | | relative to the component's coordinate system. |
532 | | */ |
533 | | JAS_EXPORT |
534 | | int jas_image_readcmpt(jas_image_t *image, unsigned cmptno, |
535 | | jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, |
536 | | jas_image_coord_t height, jas_matrix_t *data); |
537 | | |
538 | | /*! |
539 | | @brief Write a rectangular region of an image component. |
540 | | */ |
541 | | JAS_EXPORT |
542 | | int jas_image_writecmpt(jas_image_t *image, unsigned cmptno, |
543 | | jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, |
544 | | jas_image_coord_t height, const jas_matrix_t *data); |
545 | | |
546 | | /*! |
547 | | @brief Delete a component from an image. |
548 | | */ |
549 | | JAS_EXPORT |
550 | | void jas_image_delcmpt(jas_image_t *image, unsigned cmptno); |
551 | | |
552 | | /*! |
553 | | @brief Add a component to an image. |
554 | | */ |
555 | | JAS_EXPORT |
556 | | int jas_image_addcmpt(jas_image_t *image, int cmptno, |
557 | | const jas_image_cmptparm_t *cmptparm); |
558 | | |
559 | | /*! |
560 | | @brief Copy a component from one image to another. |
561 | | */ |
562 | | JAS_EXPORT |
563 | | int jas_image_copycmpt(jas_image_t *dstimage, unsigned dstcmptno, |
564 | | jas_image_t *srcimage, unsigned srccmptno); |
565 | | |
566 | | JAS_ATTRIBUTE_CONST |
567 | | static inline bool JAS_IMAGE_CDT_GETSGND(uint_least8_t dtype) |
568 | 0 | { |
569 | 0 | return (dtype >> 7) & 1; |
570 | 0 | } |
571 | | |
572 | | JAS_ATTRIBUTE_CONST |
573 | | static inline uint_least8_t JAS_IMAGE_CDT_SETSGND(bool sgnd) |
574 | 0 | { |
575 | 0 | return (uint_least8_t)sgnd << 7; |
576 | 0 | } |
577 | | |
578 | | JAS_ATTRIBUTE_CONST |
579 | | static inline uint_least8_t JAS_IMAGE_CDT_GETPREC(uint_least8_t dtype) |
580 | 0 | { |
581 | 0 | return dtype & 0x7f; |
582 | 0 | } |
583 | | |
584 | | JAS_ATTRIBUTE_CONST |
585 | | static inline uint_least8_t JAS_IMAGE_CDT_SETPREC(uint_least8_t dtype) |
586 | 0 | { |
587 | 0 | return dtype & 0x7f; |
588 | 0 | } |
589 | | |
590 | | JAS_ATTRIBUTE_PURE |
591 | | static inline uint_least8_t jas_image_cmptdtype(const jas_image_t *image, |
592 | | unsigned cmptno) |
593 | 0 | { |
594 | 0 | return JAS_IMAGE_CDT_SETSGND(image->cmpts_[cmptno]->sgnd_) | |
595 | 0 | JAS_IMAGE_CDT_SETPREC(image->cmpts_[cmptno]->prec_); |
596 | 0 | } |
597 | | |
598 | | /*! |
599 | | @brief Depalettize an image |
600 | | */ |
601 | | JAS_EXPORT |
602 | | int jas_image_depalettize(jas_image_t *image, unsigned cmptno, |
603 | | unsigned numlutents, const int_fast32_t *lutents, unsigned dtype, |
604 | | unsigned newcmptno); |
605 | | |
606 | | /*! |
607 | | @brief Read a component sample for an image. |
608 | | */ |
609 | | JAS_EXPORT |
610 | | int jas_image_readcmptsample(jas_image_t *image, unsigned cmptno, unsigned x, |
611 | | unsigned y); |
612 | | |
613 | | /*! |
614 | | @brief Write a component sample for an image. |
615 | | */ |
616 | | JAS_EXPORT |
617 | | void jas_image_writecmptsample(jas_image_t *image, unsigned cmptno, |
618 | | unsigned x, unsigned y, int_fast32_t v); |
619 | | |
620 | | /*! |
621 | | @brief Get an image component by its type. |
622 | | */ |
623 | | JAS_ATTRIBUTE_PURE |
624 | | JAS_EXPORT |
625 | | int jas_image_getcmptbytype(const jas_image_t *image, jas_image_cmpttype_t ctype); |
626 | | |
627 | | /******************************************************************************\ |
628 | | * Image format-related operations. |
629 | | \******************************************************************************/ |
630 | | |
631 | | /*! |
632 | | @brief Clear the table of image formats. |
633 | | */ |
634 | | JAS_EXPORT |
635 | | void jas_image_clearfmts(void); |
636 | | |
637 | | #if defined(JAS_FOR_INTERNAL_USE_ONLY) |
638 | | void jas_image_clearfmts_internal(jas_image_fmtinfo_t *image_fmtinfos, |
639 | | size_t *image_numfmts); |
640 | | #endif |
641 | | |
642 | | /*! |
643 | | @brief Get a image format entry by its table index. |
644 | | */ |
645 | | JAS_EXPORT |
646 | | const jas_image_fmtinfo_t *jas_image_getfmtbyind(int index); |
647 | | |
648 | | /*! |
649 | | @brief Get the number of image format table entries. |
650 | | */ |
651 | | JAS_EXPORT |
652 | | int jas_image_getnumfmts(void); |
653 | | |
654 | | #if 0 |
655 | | JAS_EXPORT |
656 | | int jas_image_delfmtbyid(int id); |
657 | | #endif |
658 | | |
659 | | /*! |
660 | | @brief Get the number of image format table entries. |
661 | | |
662 | | @warning |
663 | | This function may be removed in future versions of the library. |
664 | | Do not rely on it. |
665 | | */ |
666 | | JAS_EXPORT |
667 | | int jas_image_setfmtenable(int index, int enabled); |
668 | | |
669 | | #if 0 |
670 | | // TODO: should this be added? |
671 | | JAS_EXPORT |
672 | | int jas_image_getfmtindbyname(const char* name); |
673 | | #endif |
674 | | |
675 | | /*! |
676 | | @brief Add entry to table of image formats. |
677 | | */ |
678 | | JAS_EXPORT |
679 | | int jas_image_addfmt(int id, const char *name, const char *ext, |
680 | | const char *desc, const jas_image_fmtops_t *ops); |
681 | | |
682 | | #if defined(JAS_FOR_INTERNAL_USE_ONLY) |
683 | | int jas_image_addfmt_internal(jas_image_fmtinfo_t *image_fmtinfos, |
684 | | size_t *image_numfmts, int id, const char *name, const char *ext, |
685 | | const char *desc, const jas_image_fmtops_t *ops); |
686 | | #endif |
687 | | |
688 | | /*! |
689 | | @brief Get the ID for the image format with the specified name. |
690 | | */ |
691 | | JAS_ATTRIBUTE_PURE |
692 | | JAS_EXPORT |
693 | | int jas_image_strtofmt(const char *s); |
694 | | |
695 | | /*! |
696 | | @brief Get the name of the image format with the specified ID. |
697 | | */ |
698 | | JAS_ATTRIBUTE_CONST |
699 | | JAS_EXPORT |
700 | | const char *jas_image_fmttostr(int fmt); |
701 | | |
702 | | /*! |
703 | | @brief Lookup image format information by the format ID. |
704 | | */ |
705 | | JAS_ATTRIBUTE_CONST |
706 | | JAS_EXPORT |
707 | | const jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id); |
708 | | |
709 | | /*! |
710 | | @brief Lookup image format information by the format name. |
711 | | */ |
712 | | JAS_ATTRIBUTE_PURE |
713 | | JAS_EXPORT |
714 | | const jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name); |
715 | | |
716 | | /*! |
717 | | @brief Guess the format of an image file based on its name. |
718 | | */ |
719 | | JAS_ATTRIBUTE_PURE |
720 | | JAS_EXPORT |
721 | | int jas_image_fmtfromname(const char *filename); |
722 | | |
723 | | /*! |
724 | | @brief Get the format of image data in a stream. |
725 | | |
726 | | @details |
727 | | Note that only enabled codecs are used in determining the image format. |
728 | | */ |
729 | | JAS_ATTRIBUTE_PURE |
730 | | JAS_EXPORT |
731 | | int jas_image_getfmt(jas_stream_t *in); |
732 | | |
733 | | /*! |
734 | | @brief Get the color management profile of an image. |
735 | | */ |
736 | 0 | #define jas_image_cmprof(image) ((image)->cmprof_) |
737 | | |
738 | | /*! |
739 | | @brief |
740 | | Test if the sampling of the image is homogeneous. |
741 | | */ |
742 | | JAS_ATTRIBUTE_PURE |
743 | | JAS_EXPORT |
744 | | int jas_image_ishomosamp(const jas_image_t *image); |
745 | | |
746 | | /*! |
747 | | @brief ??? |
748 | | */ |
749 | | JAS_EXPORT |
750 | | int jas_image_sampcmpt(jas_image_t *image, unsigned cmptno, unsigned newcmptno, |
751 | | jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs, |
752 | | jas_image_coord_t vs, int sgnd, unsigned prec); |
753 | | |
754 | | /*! |
755 | | @brief Write sample data in a component of an image. |
756 | | */ |
757 | | JAS_EXPORT |
758 | | int jas_image_writecmpt2(jas_image_t *image, unsigned cmptno, |
759 | | jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, |
760 | | jas_image_coord_t height, const long *buf); |
761 | | |
762 | | /*! |
763 | | @brief Read sample data in a component of an image. |
764 | | */ |
765 | | JAS_EXPORT |
766 | | int jas_image_readcmpt2(jas_image_t *image, unsigned cmptno, |
767 | | jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, |
768 | | jas_image_coord_t height, long *buf); |
769 | | |
770 | | /*! |
771 | | @brief Set the color management profile for an image. |
772 | | */ |
773 | | #define jas_image_setcmprof(image, cmprof) ((image)->cmprof_ = cmprof) |
774 | | |
775 | | /*! |
776 | | @brief Change the color space for an image. |
777 | | */ |
778 | | JAS_EXPORT |
779 | | jas_image_t *jas_image_chclrspc(jas_image_t *image, |
780 | | const jas_cmprof_t *outprof, jas_cmxform_intent_t intent); |
781 | | |
782 | | /*! |
783 | | @brief Dump the information for an image (for debugging). |
784 | | */ |
785 | | JAS_EXPORT |
786 | | int jas_image_dump(jas_image_t *image, FILE *out); |
787 | | |
788 | | /******************************************************************************\ |
789 | | * Image format-dependent operations. |
790 | | \******************************************************************************/ |
791 | | |
792 | | #if defined(JAS_INCLUDE_JPG_CODEC) |
793 | | /* Format-dependent operations for JPG support. */ |
794 | | //JAS_EXPORT |
795 | | jas_image_t *jpg_decode(jas_stream_t *in, const char *optstr); |
796 | | //JAS_EXPORT |
797 | | int jpg_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
798 | | //JAS_EXPORT |
799 | | int jpg_validate(jas_stream_t *in); |
800 | | #endif |
801 | | |
802 | | #if defined(JAS_INCLUDE_HEIC_CODEC) |
803 | | /* Format-dependent operations for HEIC support. */ |
804 | | //JAS_EXPORT |
805 | | jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr); |
806 | | //JAS_EXPORT |
807 | | int jas_heic_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
808 | | //JAS_EXPORT |
809 | | int jas_heic_validate(jas_stream_t *in); |
810 | | #endif |
811 | | |
812 | | #if defined(JAS_INCLUDE_MIF_CODEC) |
813 | | /* Format-dependent operations for MIF support. */ |
814 | | //JAS_EXPORT |
815 | | jas_image_t *mif_decode(jas_stream_t *in, const char *optstr); |
816 | | //JAS_EXPORT |
817 | | int mif_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
818 | | //JAS_EXPORT |
819 | | int mif_validate(jas_stream_t *in); |
820 | | #endif |
821 | | |
822 | | #if defined(JAS_INCLUDE_PNM_CODEC) |
823 | | /* Format-dependent operations for PNM support. */ |
824 | | //JAS_EXPORT |
825 | | jas_image_t *pnm_decode(jas_stream_t *in, const char *optstr); |
826 | | //JAS_EXPORT |
827 | | int pnm_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
828 | | //JAS_EXPORT |
829 | | int pnm_validate(jas_stream_t *in); |
830 | | #endif |
831 | | |
832 | | #if defined(JAS_INCLUDE_RAS_CODEC) |
833 | | /* Format-dependent operations for Sun Rasterfile support. */ |
834 | | //JAS_EXPORT |
835 | | jas_image_t *ras_decode(jas_stream_t *in, const char *optstr); |
836 | | //JAS_EXPORT |
837 | | int ras_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
838 | | //JAS_EXPORT |
839 | | int ras_validate(jas_stream_t *in); |
840 | | #endif |
841 | | |
842 | | #if defined(JAS_INCLUDE_BMP_CODEC) |
843 | | /* Format-dependent operations for BMP support. */ |
844 | | //JAS_EXPORT |
845 | | jas_image_t *bmp_decode(jas_stream_t *in, const char *optstr); |
846 | | //JAS_EXPORT |
847 | | int bmp_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
848 | | //JAS_EXPORT |
849 | | int bmp_validate(jas_stream_t *in); |
850 | | #endif |
851 | | |
852 | | #if defined(JAS_INCLUDE_JP2_CODEC) |
853 | | /* Format-dependent operations for JP2 support. */ |
854 | | //JAS_EXPORT |
855 | | jas_image_t *jp2_decode(jas_stream_t *in, const char *optstr); |
856 | | //JAS_EXPORT |
857 | | int jp2_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
858 | | //JAS_EXPORT |
859 | | int jp2_validate(jas_stream_t *in); |
860 | | #endif |
861 | | |
862 | | #if defined(JAS_INCLUDE_JPC_CODEC) |
863 | | /* Format-dependent operations for JPEG-2000 code stream support. */ |
864 | | //JAS_EXPORT |
865 | | jas_image_t *jpc_decode(jas_stream_t *in, const char *optstr); |
866 | | //JAS_EXPORT |
867 | | int jpc_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
868 | | //JAS_EXPORT |
869 | | int jpc_validate(jas_stream_t *in); |
870 | | #endif |
871 | | |
872 | | #if defined(JAS_INCLUDE_PGX_CODEC) |
873 | | /* Format-dependent operations for PGX support. */ |
874 | | //JAS_EXPORT |
875 | | jas_image_t *pgx_decode(jas_stream_t *in, const char *optstr); |
876 | | //JAS_EXPORT |
877 | | int pgx_encode(jas_image_t *image, jas_stream_t *out, const char *optstr); |
878 | | //JAS_EXPORT |
879 | | int pgx_validate(jas_stream_t *in); |
880 | | #endif |
881 | | |
882 | | /*! |
883 | | * @} |
884 | | */ |
885 | | |
886 | | #ifdef __cplusplus |
887 | | } |
888 | | #endif |
889 | | |
890 | | #endif |