Files
Aaru.Compression.Native/winzipjpeg/ArithmeticDecoder.h
Natalia Portillo 12a4d684f5 Add support for various ZIP compression methods
- Implement Deflate64 decompression in zip/deflate64.h and zip/deflate64.c.
- Add ZIP Implode decompression functionality in zip/implode.h and zip/implode.c.
- Introduce ZIP Reduce decompression in zip/reduce.h and zip/reduce.c.
- Implement ZIP Shrink decompression in zip/shrink.h and zip/shrink.c.
- Create a unified ZIP interface in zip/zip.h and zip/zip.c to handle multiple compression methods including PPMd, WavPack, and WinZip JPEG.
- Ensure all new functions adhere to the Aaru Data Preservation Suite licensing and documentation standards.
2026-04-15 00:52:22 +01:00

72 lines
2.7 KiB
C

/*
* ArithmeticDecoder.h
*
* Copyright (c) 2017-present, MacPaw Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef __WINZIP_JPEG_ARITHMETIC_DECODER_H__
#define __WINZIP_JPEG_ARITHMETIC_DECODER_H__
#include "InputStream.h"
#include <stdbool.h>
#include <stdint.h>
typedef struct WinZipJPEGArithmeticDecoder
{
WinZipJPEGReadFunction *readfunc;
void *inputcontext;
bool eof;
uint8_t currbyte, lastbyte;
uint8_t kmin2; // LPS count for reduction of Q by 4
uint8_t kmin1; // LPS count for reduction of Q by 2
uint8_t kmin; // largest LSP[sic] count for smaller Q
// uint8_t kavg; // expected average LPS count
uint8_t kmax; // smallest LPS count for larger Q
uint32_t x; // finite pricesion window on code stream
int32_t lp; // minus log p --- used only for testing
int32_t lr; // minus log of the range
int32_t lrm; // maximum lr before change index
int32_t lx; // decoder - log x
uint32_t dx; // antilog of lr -- used only for testing
} WinZipJPEGArithmeticDecoder;
typedef struct WinZipJPEGContext
{
int i;
int32_t dlrm; // difference between lrm and lr
uint8_t mps; // most probable symbol value - 0 or 1
uint8_t k; // least probable symbol count
} WinZipJPEGContext;
void InitializeWinZipJPEGArithmeticDecoder(WinZipJPEGArithmeticDecoder *self, WinZipJPEGReadFunction *readfunc,
void *inputcontext);
void InitializeWinZipJPEGContext(WinZipJPEGContext *self);
void InitializeWinZipJPEGContexts(WinZipJPEGContext *first, size_t bytes);
void InitializeFixedWinZipJPEGContext(WinZipJPEGContext *self);
int NextBitFromWinZipJPEGArithmeticDecoder(WinZipJPEGArithmeticDecoder *self, WinZipJPEGContext *context);
void FlushWinZipJPEGArithmeticDecoder(WinZipJPEGArithmeticDecoder *self);
static inline bool WinZipJPEGArithmeticDecoderEncounteredEOF(WinZipJPEGArithmeticDecoder *self) { return self->eof; }
#endif