xref: /aosp_15_r20/external/lzma/CPP/7zip/Compress/BranchMisc.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // BranchMisc.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../../C/CpuArch.h"
6 
7 #include "../Common/StreamUtils.h"
8 
9 #include "BranchMisc.h"
10 
11 namespace NCompress {
12 namespace NBranch {
13 
Z7_COM7F_IMF(CCoder::Init ())14 Z7_COM7F_IMF(CCoder::Init())
15 {
16   _pc = 0;
17   return S_OK;
18 }
19 
20 
Z7_COM7F_IMF2(UInt32,CCoder::Filter (Byte * data,UInt32 size))21 Z7_COM7F_IMF2(UInt32, CCoder::Filter(Byte *data, UInt32 size))
22 {
23   const UInt32 processed = (UInt32)(size_t)(BraFunc(data, size, _pc) - data);
24   _pc += processed;
25   return processed;
26 }
27 
28 
29 #ifndef Z7_EXTRACT_ONLY
30 
Z7_COM7F_IMF(CEncoder::Init ())31 Z7_COM7F_IMF(CEncoder::Init())
32 {
33   _pc = _pc_Init;
34   return S_OK;
35 }
36 
Z7_COM7F_IMF2(UInt32,CEncoder::Filter (Byte * data,UInt32 size))37 Z7_COM7F_IMF2(UInt32, CEncoder::Filter(Byte *data, UInt32 size))
38 {
39   const UInt32 processed = (UInt32)(size_t)(BraFunc(data, size, _pc) - data);
40   _pc += processed;
41   return processed;
42 }
43 
Z7_COM7F_IMF(CEncoder::SetCoderProperties (const PROPID * propIDs,const PROPVARIANT * props,UInt32 numProps))44 Z7_COM7F_IMF(CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps))
45 {
46   UInt32 pc = 0;
47   for (UInt32 i = 0; i < numProps; i++)
48   {
49     const PROPID propID = propIDs[i];
50     if (propID == NCoderPropID::kDefaultProp ||
51         propID == NCoderPropID::kBranchOffset)
52     {
53       const PROPVARIANT &prop = props[i];
54       if (prop.vt != VT_UI4)
55         return E_INVALIDARG;
56       pc = prop.ulVal;
57       if (pc & _alignment)
58         return E_INVALIDARG;
59     }
60   }
61   _pc_Init = pc;
62   return S_OK;
63 }
64 
65 
Z7_COM7F_IMF(CEncoder::WriteCoderProperties (ISequentialOutStream * outStream))66 Z7_COM7F_IMF(CEncoder::WriteCoderProperties(ISequentialOutStream *outStream))
67 {
68   if (_pc_Init == 0)
69     return S_OK;
70   UInt32 buf32[1];
71   SetUi32(buf32, _pc_Init)
72   return WriteStream(outStream, buf32, 4);
73 }
74 
75 #endif
76 
77 
Z7_COM7F_IMF(CDecoder::Init ())78 Z7_COM7F_IMF(CDecoder::Init())
79 {
80   _pc = _pc_Init;
81   return S_OK;
82 }
83 
Z7_COM7F_IMF2(UInt32,CDecoder::Filter (Byte * data,UInt32 size))84 Z7_COM7F_IMF2(UInt32, CDecoder::Filter(Byte *data, UInt32 size))
85 {
86   const UInt32 processed = (UInt32)(size_t)(BraFunc(data, size, _pc) - data);
87   _pc += processed;
88   return processed;
89 }
90 
Z7_COM7F_IMF(CDecoder::SetDecoderProperties2 (const Byte * props,UInt32 size))91 Z7_COM7F_IMF(CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size))
92 {
93   UInt32 val = 0;
94   if (size != 0)
95   {
96     if (size != 4)
97       return E_NOTIMPL;
98     val = GetUi32(props);
99     if (val & _alignment)
100       return E_NOTIMPL;
101   }
102   _pc_Init = val;
103   return S_OK;
104 }
105 
106 }}
107