/*-------------------------------------------------*/ /* GRZipII/libGRZip compressor Rec_Flt.c */ /* Data reordering and Delta Filter */ /*-------------------------------------------------*/ /*-- This file is a part of GRZipII and/or libGRZip, a program and library for lossless, block-sorting data compression. Copyright (C) 2002-2004 Grebnov Ilya. 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. Grebnov Ilya, Ivanovo, Russian Federation. Ilya.Grebnov@magicssoft.ru, http://magicssoft.ru/ This program is based on (at least) the work of: Juergen Abel, Jon L. Bentley, Edgar Binder, Charles Bloom, Mike Burrows, Andrey Cadach, Damien Debin, Sebastian Deorowicz, Peter Fenwick, George Plechanov, Michael Schindler, Robert Sedgewick, Julian Seward, David Wheeler, Vadim Yoockin. For more information on these sources, see the manual. --*/ #include #include #include "libGRZip.h" #define Rec_MaxByte 256 sint32 GRZip_Rec_Test(uint8 * Input,sint32 Size) { uint8 * SInput=Input; uint8 * InputEnd=Input+Size; sint32 Freq0[Rec_MaxByte]; sint32 Freq2[2][Rec_MaxByte]; sint32 Freq4[4][Rec_MaxByte]; memset(Freq0,0,Rec_MaxByte*sizeof(Rec_MaxByte)); memset(Freq2,0,2*Rec_MaxByte*sizeof(Rec_MaxByte)); memset(Freq4,0,4*Rec_MaxByte*sizeof(Rec_MaxByte)); sint32 j,i,Min,Pos2=0,Pos4=0; while (Input>1); while (Inp>1)>(SumDelta+(SumDelta>>4))) Min=3; } if (Min==2) { sint64 Sum=0,SumDelta=0; uint32 MinCode=0xFFFFFFFF,Delta,PredCode=0; uint32 * Inp=(uint32 *)SInput; uint32 * InpEnd=Inp+(Size>>2); while (Inp>2)>(SumDelta+(SumDelta>>4))) Min=4; } return Min; } void GRZip_Rec_Encode(uint8 * Input, sint32 Size, uint8 * Output,sint32 Mode) { if (Mode==3) { sint32 NumRecords=(Size>>1); uint16 Delta,PredCode=0; uint16 * Inp=(uint16 *)Input; uint16 * InpEnd=Inp+NumRecords; while (Inp>8; } sint32 i=2*NumRecords; while (i>2); sint32 P1=NumRecords; sint32 P2=2*NumRecords; sint32 P3=3*NumRecords; uint32 Delta,PredCode=0; uint32 * Inp=(uint32 *)Input; uint32 * InpEnd=Inp+NumRecords; while (Inp>=8; *(Output+P2)=Delta&0xFF;Delta>>=8; *(Output+P3)=Delta&0xFF;*(Output++)=Delta>>8; } sint32 i=4*NumRecords; while (i>1); uint16 Code,PredCode=0; uint16 * Outp=(uint16 *)Output; uint16 * OutpEnd=Outp+NumRecords; while (Outp>1); else Delta>>=1; Code=Delta+PredCode; PredCode=Code; *Outp++=Code; } sint32 i=2*NumRecords; while (i>2); sint32 P1=NumRecords; sint32 P2=2*NumRecords; sint32 P3=3*NumRecords; uint32 Code,PredCode=0; uint32 * Outp=(uint32 *)Output; uint32 * OutpEnd=Outp+NumRecords; while (Outp>1); else Delta>>=1; Code=Delta+PredCode; PredCode=Code; *Outp++=Code; } sint32 i=4*NumRecords; while (i