diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /third_party/jpeg-xl/lib/jpegli/common.cc | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jpegli/common.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jpegli/common.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/third_party/jpeg-xl/lib/jpegli/common.cc b/third_party/jpeg-xl/lib/jpegli/common.cc new file mode 100644 index 0000000000..5f34372f3e --- /dev/null +++ b/third_party/jpeg-xl/lib/jpegli/common.cc @@ -0,0 +1,59 @@ +// Copyright (c) the JPEG XL Project Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "lib/jpegli/common.h" + +#include "lib/jpegli/decode_internal.h" +#include "lib/jpegli/encode_internal.h" +#include "lib/jpegli/memory_manager.h" + +void jpegli_abort(j_common_ptr cinfo) { + if (cinfo->mem == nullptr) return; + for (int pool_id = 0; pool_id < JPOOL_NUMPOOLS; ++pool_id) { + if (pool_id == JPOOL_PERMANENT) continue; + (*cinfo->mem->free_pool)(cinfo, pool_id); + } + if (cinfo->is_decompressor) { + cinfo->global_state = jpegli::kDecStart; + } else { + cinfo->global_state = jpegli::kEncStart; + } +} + +void jpegli_destroy(j_common_ptr cinfo) { + if (cinfo->mem == nullptr) return; + (*cinfo->mem->self_destruct)(cinfo); + if (cinfo->is_decompressor) { + cinfo->global_state = jpegli::kDecNull; + delete reinterpret_cast<j_decompress_ptr>(cinfo)->master; + } else { + cinfo->global_state = jpegli::kEncNull; + } +} + +JQUANT_TBL* jpegli_alloc_quant_table(j_common_ptr cinfo) { + JQUANT_TBL* table = jpegli::Allocate<JQUANT_TBL>(cinfo, 1); + table->sent_table = FALSE; + return table; +} + +JHUFF_TBL* jpegli_alloc_huff_table(j_common_ptr cinfo) { + JHUFF_TBL* table = jpegli::Allocate<JHUFF_TBL>(cinfo, 1); + table->sent_table = FALSE; + return table; +} + +int jpegli_bytes_per_sample(JpegliDataType data_type) { + switch (data_type) { + case JPEGLI_TYPE_UINT8: + return 1; + case JPEGLI_TYPE_UINT16: + return 2; + case JPEGLI_TYPE_FLOAT: + return 4; + default: + return 0; + } +} |