godot/thirdparty/jpeg-compressor/jpgd.cpp

// jpgd.cpp - C++ class for JPEG decompression. Written by Richard Geldreich <[email protected]> between 1994-2020.
// Supports progressive and baseline sequential JPEG image files, and the most common chroma subsampling factors: Y, H1V1, H2V1, H1V2, and H2V2.
// Supports box and linear chroma upsampling.
//
// Released under two licenses. You are free to choose which license you want:
// License 1: 
// Public Domain
//
// License 2:
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Alex Evans: Linear memory allocator (taken from jpge.h).
// v1.04, May. 19, 2012: Code tweaks to fix VS2008 static code analysis warnings
// v2.00, March 20, 2020: Fuzzed with zzuf and afl. Fixed several issues, converted most assert()'s to run-time checks. Added chroma upsampling. Removed freq. domain upsampling. gcc/clang warnings.
//
// Important:
// #define JPGD_USE_SSE2 to 0 to completely disable SSE2 usage.
//
#include "jpgd.h"
#include <string.h>
#include <algorithm>
#include <assert.h>

#ifdef _MSC_VER
#pragma warning (disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
#endif

#ifndef JPGD_USE_SSE2

	#if defined(__GNUC__)
		#if defined(__SSE2__)
			#define JPGD_USE_SSE2
		#endif
	#elif defined(_MSC_VER)
		#if defined(_M_X64)
			#define JPGD_USE_SSE2
		#endif
	#endif

#endif

#define JPGD_TRUE
#define JPGD_FALSE

#define JPGD_MAX(a,b)
#define JPGD_MIN(a,b)

namespace jpgd {

	static inline void* jpgd_malloc(size_t nSize) {}
	static inline void jpgd_free(void* p) {}

	// DCT coefficients are stored in this sequence.
	static int g_ZAG[64] =;

	enum JPEG_MARKER
	{};

	enum JPEG_SUBSAMPLING {};

#if JPGD_USE_SSE2
#include "jpgd_idct.h"
#endif

#define CONST_BITS
#define PASS1_BITS
#define SCALEDONE

#define FIX_0_298631336
#define FIX_0_390180644
#define FIX_0_541196100
#define FIX_0_765366865
#define FIX_0_899976223
#define FIX_1_175875602
#define FIX_1_501321110
#define FIX_1_847759065
#define FIX_1_961570560
#define FIX_2_053119869
#define FIX_2_562915447
#define FIX_3_072711026

#define DESCALE(x,n)
#define DESCALE_ZEROSHIFT(x,n)

#define MULTIPLY(var, cnst)

#define CLAMP(i)

	static inline int left_shifti(int val, uint32_t bits)
	{}

	// Compiler creates a fast path 1D IDCT for X non-zero columns
	template <int NONZERO_COLS>
	struct Row
	{};

	template <>
	struct Row<0>
	{};

	template <>
	struct Row<1>
	{};

	// Compiler creates a fast path 1D IDCT for X non-zero rows
	template <int NONZERO_ROWS>
	struct Col
	{};

	template <>
	struct Col<1>
	{};

	static const uint8 s_idct_row_table[] =;

	static const uint8 s_idct_col_table[] =;

	// Scalar "fast pathing" IDCT.
	static void idct(const jpgd_block_coeff_t* pSrc_ptr, uint8* pDst_ptr, int block_max_zag, bool use_simd)
	{}

	// Retrieve one character from the input stream.
	inline uint jpeg_decoder::get_char()
	{}

	// Same as previous method, except can indicate if the character is a pad character or not.
	inline uint jpeg_decoder::get_char(bool* pPadding_flag)
	{}

	// Inserts a previously retrieved character back into the input buffer.
	inline void jpeg_decoder::stuff_char(uint8 q)
	{}

	// Retrieves one character from the input stream, but does not read past markers. Will continue to return 0xFF when a marker is encountered.
	inline uint8 jpeg_decoder::get_octet()
	{}

	// Retrieves a variable number of bits from the input stream. Does not recognize markers.
	inline uint jpeg_decoder::get_bits(int num_bits)
	{}

	// Retrieves a variable number of bits from the input stream. Markers will not be read into the input bit buffer. Instead, an infinite number of all 1's will be returned when a marker is encountered.
	inline uint jpeg_decoder::get_bits_no_markers(int num_bits)
	{}

	// Decodes a Huffman encoded symbol.
	inline int jpeg_decoder::huff_decode(huff_tables* pH)
	{}

	// Decodes a Huffman encoded symbol.
	inline int jpeg_decoder::huff_decode(huff_tables* pH, int& extra_bits)
	{}

	// Tables and macro used to fully decode the DPCM differences.
	static const int s_extend_test[16] =;
	static const int s_extend_offset[16] =;
	//static const int s_extend_mask[] = { 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4), (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10), (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15), (1 << 16) };

#define JPGD_HUFF_EXTEND(x, s)

	// Unconditionally frees all allocated m_blocks.
	void jpeg_decoder::free_all_blocks()
	{}

	// This method handles all errors. It will never return.
	// It could easily be changed to use C++ exceptions.
	JPGD_NORETURN void jpeg_decoder::stop_decoding(jpgd_status status)
	{}
		
	void* jpeg_decoder::alloc(size_t nSize, bool zero)
	{}

	void* jpeg_decoder::alloc_aligned(size_t nSize, uint32_t align, bool zero)
	{}

	void jpeg_decoder::word_clear(void* p, uint16 c, uint n)
	{}

	// Refill the input buffer.
	// This method will sit in a loop until (A) the buffer is full or (B)
	// the stream's read() method reports and end of file condition.
	void jpeg_decoder::prep_in_buffer()
	{}

	// Read a Huffman code table.
	void jpeg_decoder::read_dht_marker()
	{}

	// Read a quantization table.
	void jpeg_decoder::read_dqt_marker()
	{}

	// Read the start of frame (SOF) marker.
	void jpeg_decoder::read_sof_marker()
	{}

	// Used to skip unrecognized markers.
	void jpeg_decoder::skip_variable_marker()
	{}

	// Read a define restart interval (DRI) marker.
	void jpeg_decoder::read_dri_marker()
	{}

	// Read a start of scan (SOS) marker.
	void jpeg_decoder::read_sos_marker()
	{}

	// Finds the next marker.
	int jpeg_decoder::next_marker()
	{}

	// Process markers. Returns when an SOFx, SOI, EOI, or SOS marker is
	// encountered.
	int jpeg_decoder::process_markers()
	{}

	// Finds the start of image (SOI) marker.
	void jpeg_decoder::locate_soi_marker()
	{}

	// Find a start of frame (SOF) marker.
	void jpeg_decoder::locate_sof_marker()
	{}

	// Find a start of scan (SOS) marker.
	int jpeg_decoder::locate_sos_marker()
	{}

	// Reset everything to default/uninitialized state.
	void jpeg_decoder::init(jpeg_decoder_stream* pStream, uint32_t flags)
	{}

#define SCALEBITS
#define ONE_HALF
#define FIX(x)

	// Create a few tables that allow us to quickly convert YCbCr to RGB.
	void jpeg_decoder::create_look_ups()
	{}

	// This method throws back into the stream any bytes that where read
	// into the bit buffer during initial marker scanning.
	void jpeg_decoder::fix_in_buffer()
	{}

	void jpeg_decoder::transform_mcu(int mcu_row)
	{}

	// Loads and dequantizes the next row of (already decoded) coefficients.
	// Progressive images only.
	void jpeg_decoder::load_next_row()
	{}

	// Restart interval processing.
	void jpeg_decoder::process_restart()
	{}

	static inline int dequantize_ac(int c, int q) {}

	// Decodes and dequantizes the next row of coefficients.
	void jpeg_decoder::decode_next_row()
	{}

	// YCbCr H1V1 (1x1:1:1, 3 m_blocks per MCU) to RGB
	void jpeg_decoder::H1V1Convert()
	{}

	// YCbCr H2V1 (2x1:1:1, 4 m_blocks per MCU) to RGB
	void jpeg_decoder::H2V1Convert()
	{}

	// YCbCr H2V1 (2x1:1:1, 4 m_blocks per MCU) to RGB
	void jpeg_decoder::H2V1ConvertFiltered()
	{}

	// YCbCr H2V1 (1x2:1:1, 4 m_blocks per MCU) to RGB
	void jpeg_decoder::H1V2Convert()
	{}

	// YCbCr H2V1 (1x2:1:1, 4 m_blocks per MCU) to RGB
	void jpeg_decoder::H1V2ConvertFiltered()
	{}

	// YCbCr H2V2 (2x2:1:1, 6 m_blocks per MCU) to RGB
	void jpeg_decoder::H2V2Convert()
	{}

	uint32_t jpeg_decoder::H2V2ConvertFiltered()
	{}

	// Y (1 block per MCU) to 8-bit grayscale
	void jpeg_decoder::gray_convert()
	{}

	// Find end of image (EOI) marker, so we can return to the user the exact size of the input stream.
	void jpeg_decoder::find_eoi()
	{}

	int jpeg_decoder::decode_next_mcu_row()
	{}

	int jpeg_decoder::decode(const void** pScan_line, uint* pScan_line_len)
	{}

	// Creates the tables needed for efficient Huffman decoding.
	void jpeg_decoder::make_huff_table(int index, huff_tables* pH)
	{}

	// Verifies the quantization tables needed for this scan are available.
	void jpeg_decoder::check_quant_tables()
	{}

	// Verifies that all the Huffman tables needed for this scan are available.
	void jpeg_decoder::check_huff_tables()
	{}

	// Determines the component order inside each MCU.
	// Also calcs how many MCU's are on each row, etc.
	bool jpeg_decoder::calc_mcu_block_order()
	{}

	// Starts a new scan.
	int jpeg_decoder::init_scan()
	{}

	// Starts a frame. Determines if the number of components or sampling factors
	// are supported.
	void jpeg_decoder::init_frame()
	{}

	// The coeff_buf series of methods originally stored the coefficients
	// into a "virtual" file which was located in EMS, XMS, or a disk file. A cache
	// was used to make this process more efficient. Now, we can store the entire
	// thing in RAM.
	jpeg_decoder::coeff_buf* jpeg_decoder::coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, int block_len_y)
	{}

	inline jpgd_block_coeff_t* jpeg_decoder::coeff_buf_getp(coeff_buf* cb, int block_x, int block_y)
	{}

	// The following methods decode the various types of m_blocks encountered
	// in progressively encoded images.
	void jpeg_decoder::decode_block_dc_first(jpeg_decoder* pD, int component_id, int block_x, int block_y)
	{}

	void jpeg_decoder::decode_block_dc_refine(jpeg_decoder* pD, int component_id, int block_x, int block_y)
	{}

	void jpeg_decoder::decode_block_ac_first(jpeg_decoder* pD, int component_id, int block_x, int block_y)
	{}

	void jpeg_decoder::decode_block_ac_refine(jpeg_decoder* pD, int component_id, int block_x, int block_y)
	{}

	// Decode a scan in a progressively encoded image.
	void jpeg_decoder::decode_scan(pDecode_block_func decode_block_func)
	{}

	// Decode a progressively encoded image.
	void jpeg_decoder::init_progressive()
	{}

	void jpeg_decoder::init_sequential()
	{}

	void jpeg_decoder::decode_start()
	{}

	void jpeg_decoder::decode_init(jpeg_decoder_stream* pStream, uint32_t flags)
	{}

	jpeg_decoder::jpeg_decoder(jpeg_decoder_stream* pStream, uint32_t flags)
	{}

	int jpeg_decoder::begin_decoding()
	{}

	jpeg_decoder::~jpeg_decoder()
	{}

	jpeg_decoder_file_stream::jpeg_decoder_file_stream()
	{}

	void jpeg_decoder_file_stream::close()
	{}

	jpeg_decoder_file_stream::~jpeg_decoder_file_stream()
	{}

	bool jpeg_decoder_file_stream::open(const char* Pfilename)
	{}

	int jpeg_decoder_file_stream::read(uint8* pBuf, int max_bytes_to_read, bool* pEOF_flag)
	{}

	bool jpeg_decoder_mem_stream::open(const uint8* pSrc_data, uint size)
	{}

	int jpeg_decoder_mem_stream::read(uint8* pBuf, int max_bytes_to_read, bool* pEOF_flag)
	{}

	unsigned char* decompress_jpeg_image_from_stream(jpeg_decoder_stream* pStream, int* width, int* height, int* actual_comps, int req_comps, uint32_t flags)
	{}

	unsigned char* decompress_jpeg_image_from_memory(const unsigned char* pSrc_data, int src_data_size, int* width, int* height, int* actual_comps, int req_comps, uint32_t flags)
	{}

	unsigned char* decompress_jpeg_image_from_file(const char* pSrc_filename, int* width, int* height, int* actual_comps, int req_comps, uint32_t flags)
	{}

} // namespace jpgd