Files
Aaru.Compression.Native/ppmd/Context.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

111 lines
3.8 KiB
C

/*
* Context.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 __PPMD_CONTEXT_H__
#define __PPMD_CONTEXT_H__
#include "RangeCoder.h"
#include "SubAllocator.h"
#include <stdbool.h>
#include <stdint.h>
#define MAX_O 255
#define INT_BITS 7
#define PERIOD_BITS 7
#define TOT_BITS (INT_BITS + PERIOD_BITS)
#define MAX_FREQ 124
#define INTERVAL (1 << INT_BITS)
#define BIN_SCALE (1 << TOT_BITS)
#define SWAP(t1, t2) \
{ \
PPMdState tmp = (t1); \
(t1) = (t2); \
(t2) = tmp; \
}
typedef struct SEE2Context
{ // SEE-contexts for PPM-contexts with masked symbols
uint16_t Summ;
uint8_t Shift, Count;
} __attribute__((__packed__)) SEE2Context;
typedef struct PPMdContext PPMdContext;
typedef struct PPMdState
{
uint8_t Symbol, Freq;
uint32_t Successor;
} __attribute__((__packed__)) PPMdState;
struct PPMdContext
{
uint8_t LastStateIndex, Flags;
uint16_t SummFreq;
uint32_t States;
uint32_t Suffix;
} __attribute__((__packed__));
typedef struct PPMdCoreModel PPMdCoreModel;
struct PPMdCoreModel
{
PPMdSubAllocator *alloc;
PPMdRangeCoder coder;
uint32_t scale;
PPMdState *FoundState; // found next state transition
int OrderFall, InitEsc, RunLength, InitRL;
uint8_t CharMask[256];
uint8_t LastMaskIndex, EscCount, PrevSuccess;
void (*RescalePPMdContext)(PPMdContext *self, PPMdCoreModel *model);
};
SEE2Context MakeSEE2(int initval, int count);
unsigned int GetSEE2MeanMasked(SEE2Context *self);
unsigned int GetSEE2Mean(SEE2Context *self);
void UpdateSEE2(SEE2Context *self);
PPMdContext *PPMdStateSuccessor(PPMdState *self, PPMdCoreModel *model);
void SetPPMdStateSuccessorPointer(PPMdState *self, PPMdContext *newsuccessor, PPMdCoreModel *model);
PPMdState *PPMdContextStates(PPMdContext *self, PPMdCoreModel *model);
void SetPPMdContextStatesPointer(PPMdContext *self, PPMdState *newstates, PPMdCoreModel *model);
PPMdContext *PPMdContextSuffix(PPMdContext *self, PPMdCoreModel *model);
void SetPPMdContextSuffixPointer(PPMdContext *self, PPMdContext *newsuffix, PPMdCoreModel *model);
PPMdState *PPMdContextOneState(PPMdContext *self);
PPMdContext *NewPPMdContext(PPMdCoreModel *model);
PPMdContext *NewPPMdContextAsChildOf(PPMdCoreModel *model, PPMdContext *suffixcontext, PPMdState *suffixstate,
PPMdState *firststate);
void PPMdDecodeBinSymbol(PPMdContext *self, PPMdCoreModel *model, uint16_t *bs, int freqlimit, bool altnextbit);
int PPMdDecodeSymbol1(PPMdContext *self, PPMdCoreModel *model, bool greaterorequal);
void UpdatePPMdContext1(PPMdContext *self, PPMdCoreModel *model, PPMdState *state);
void PPMdDecodeSymbol2(PPMdContext *self, PPMdCoreModel *model, SEE2Context *see);
void UpdatePPMdContext2(PPMdContext *self, PPMdCoreModel *model, PPMdState *state);
void RescalePPMdContext(PPMdContext *self, PPMdCoreModel *model);
void ClearPPMdModelMask(PPMdCoreModel *self);
#endif