1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
6 #include "lib/jpegli/common.h"
8 #include "lib/jpegli/decode_internal.h"
9 #include "lib/jpegli/encode_internal.h"
10 #include "lib/jpegli/memory_manager.h"
12 void jpegli_abort(j_common_ptr cinfo
) {
13 if (cinfo
->mem
== nullptr) return;
14 for (int pool_id
= 0; pool_id
< JPOOL_NUMPOOLS
; ++pool_id
) {
15 if (pool_id
== JPOOL_PERMANENT
) continue;
16 (*cinfo
->mem
->free_pool
)(cinfo
, pool_id
);
18 if (cinfo
->is_decompressor
) {
19 cinfo
->global_state
= jpegli::kDecStart
;
21 cinfo
->global_state
= jpegli::kEncStart
;
25 void jpegli_destroy(j_common_ptr cinfo
) {
26 if (cinfo
->mem
== nullptr) return;
27 (*cinfo
->mem
->self_destruct
)(cinfo
);
28 if (cinfo
->is_decompressor
) {
29 cinfo
->global_state
= jpegli::kDecNull
;
30 delete reinterpret_cast<j_decompress_ptr
>(cinfo
)->master
;
32 cinfo
->global_state
= jpegli::kEncNull
;
36 JQUANT_TBL
* jpegli_alloc_quant_table(j_common_ptr cinfo
) {
37 JQUANT_TBL
* table
= jpegli::Allocate
<JQUANT_TBL
>(cinfo
, 1);
38 table
->sent_table
= FALSE
;
42 JHUFF_TBL
* jpegli_alloc_huff_table(j_common_ptr cinfo
) {
43 JHUFF_TBL
* table
= jpegli::Allocate
<JHUFF_TBL
>(cinfo
, 1);
44 table
->sent_table
= FALSE
;
48 int jpegli_bytes_per_sample(JpegliDataType data_type
) {
50 case JPEGLI_TYPE_UINT8
:
52 case JPEGLI_TYPE_UINT16
:
54 case JPEGLI_TYPE_FLOAT
: