Merge pull request #449 from cmitu/cdX-as-cue
[pcsx_rearmed.git] / deps / libchdr / huffman.h
index 71de399..8bcc45a 100644 (file)
@@ -1,87 +1,89 @@
-// license:BSD-3-Clause\r
-// copyright-holders:Aaron Giles\r
-/***************************************************************************\r
-\r
-    huffman.h\r
-\r
-    Static Huffman compression and decompression helpers.\r
-\r
-***************************************************************************/\r
-\r
-#pragma once\r
-\r
-#ifndef __HUFFMAN_H__\r
-#define __HUFFMAN_H__\r
-\r
-#include "bitstream.h"\r
-\r
-\r
-//**************************************************************************\r
-//  CONSTANTS\r
-//**************************************************************************\r
-\r
-enum huffman_error\r
-{\r
-       HUFFERR_NONE = 0,\r
-       HUFFERR_TOO_MANY_BITS,\r
-       HUFFERR_INVALID_DATA,\r
-       HUFFERR_INPUT_BUFFER_TOO_SMALL,\r
-       HUFFERR_OUTPUT_BUFFER_TOO_SMALL,\r
-       HUFFERR_INTERNAL_INCONSISTENCY,\r
-       HUFFERR_TOO_MANY_CONTEXTS\r
-};\r
-\r
-\r
-\r
-//**************************************************************************\r
-//  TYPE DEFINITIONS\r
-//**************************************************************************\r
-\r
-typedef uint16_t lookup_value;\r
-\r
-// a node in the huffman tree\r
-struct node_t\r
-{\r
-       struct node_t*          parent;         // pointer to parent node\r
-       uint32_t                        count;          // number of hits on this node\r
-       uint32_t                        weight;         // assigned weight of this node\r
-       uint32_t                        bits;           // bits used to encode the node\r
-       uint8_t                         numbits;        // number of bits needed for this node\r
-};\r
-\r
-// ======================> huffman_context_base\r
-\r
-// context class for decoding\r
-struct huffman_decoder\r
-{\r
-       // internal state\r
-       uint32_t                        numcodes;             // number of total codes being processed\r
-       uint8_t                         maxbits;              // maximum bits per code\r
-       uint8_t                         prevdata;             // value of the previous data (for delta-RLE encoding)\r
-       int                     rleremaining;         // number of RLE bytes remaining (for delta-RLE encoding)\r
-       lookup_value *          lookup;               // pointer to the lookup table\r
-       struct node_t *     huffnode;             // array of nodes\r
-       uint32_t *              datahisto;            // histogram of data values\r
-\r
-       // array versions of the info we need\r
-       //node_t*                       huffnode_array; //[_NumCodes];\r
-       //lookup_value* lookup_array; //[1 << _MaxBits];        \r
-};\r
-\r
-// ======================> huffman_decoder\r
-\r
-struct huffman_decoder* create_huffman_decoder(int numcodes, int maxbits);\r
-\r
-// single item operations\r
-uint32_t huffman_decode_one(struct huffman_decoder* decoder, struct bitstream* bitbuf);\r
-\r
-enum huffman_error huffman_import_tree_rle(struct huffman_decoder* decoder, struct bitstream* bitbuf);\r
-enum huffman_error huffman_import_tree_huffman(struct huffman_decoder* decoder, struct bitstream* bitbuf);\r
-\r
-int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint32_t totalweight);\r
-enum huffman_error huffman_assign_canonical_codes(struct huffman_decoder* decoder);\r
-enum huffman_error huffman_compute_tree_from_histo(struct huffman_decoder* decoder);\r
-\r
-void huffman_build_lookup_table(struct huffman_decoder* decoder);\r
-\r
-#endif\r
+/* license:BSD-3-Clause
+ * copyright-holders:Aaron Giles
+ ***************************************************************************
+
+    huffman.h
+
+    Static Huffman compression and decompression helpers.
+
+***************************************************************************/
+
+#pragma once
+
+#ifndef __HUFFMAN_H__
+#define __HUFFMAN_H__
+
+#include "bitstream.h"
+
+
+/***************************************************************************
+ *  CONSTANTS
+ ***************************************************************************
+ */
+
+enum huffman_error
+{
+       HUFFERR_NONE = 0,
+       HUFFERR_TOO_MANY_BITS,
+       HUFFERR_INVALID_DATA,
+       HUFFERR_INPUT_BUFFER_TOO_SMALL,
+       HUFFERR_OUTPUT_BUFFER_TOO_SMALL,
+       HUFFERR_INTERNAL_INCONSISTENCY,
+       HUFFERR_TOO_MANY_CONTEXTS
+};
+
+/***************************************************************************
+ *  TYPE DEFINITIONS
+ ***************************************************************************
+ */
+
+typedef uint16_t lookup_value;
+
+/* a node in the huffman tree */
+struct node_t
+{
+       struct node_t*          parent;         /* pointer to parent node */
+       uint32_t                        count;          /* number of hits on this node */
+       uint32_t                        weight;         /* assigned weight of this node */
+       uint32_t                        bits;           /* bits used to encode the node */
+       uint8_t                         numbits;        /* number of bits needed for this node */
+};
+
+/* ======================> huffman_context_base */
+
+/* context class for decoding */
+struct huffman_decoder
+{
+       /* internal state */
+       uint32_t                        numcodes;             /* number of total codes being processed */
+       uint8_t                         maxbits;           /* maximum bits per code */
+       uint8_t                         prevdata;             /* value of the previous data (for delta-RLE encoding) */
+       int                     rleremaining;         /* number of RLE bytes remaining (for delta-RLE encoding) */
+       lookup_value *          lookup;               /* pointer to the lookup table */
+       struct node_t *     huffnode;             /* array of nodes */
+       uint32_t *              datahisto;            /* histogram of data values */
+
+       /* array versions of the info we need */
+#if 0
+       node_t*                 huffnode_array; /* [_NumCodes]; */
+       lookup_value*   lookup_array; /* [1 << _MaxBits]; */
+#endif
+};
+
+/* ======================> huffman_decoder */
+
+struct huffman_decoder* create_huffman_decoder(int numcodes, int maxbits);
+
+/* single item operations */
+uint32_t huffman_decode_one(struct huffman_decoder* decoder, struct bitstream* bitbuf);
+
+enum huffman_error huffman_import_tree_rle(struct huffman_decoder* decoder, struct bitstream* bitbuf);
+enum huffman_error huffman_import_tree_huffman(struct huffman_decoder* decoder, struct bitstream* bitbuf);
+
+int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint32_t totalweight);
+enum huffman_error huffman_assign_canonical_codes(struct huffman_decoder* decoder);
+enum huffman_error huffman_compute_tree_from_histo(struct huffman_decoder* decoder);
+
+void huffman_build_lookup_table(struct huffman_decoder* decoder);
+
+#endif