Lines Matching defs:dctxPtr
762 LZ4F_dctx_t* dctxPtr;
764 dctxPtr = (LZ4F_dctx_t*)ALLOCATOR(sizeof(LZ4F_dctx_t));
765 if (dctxPtr==NULL) return (LZ4F_errorCode_t)-LZ4F_ERROR_GENERIC;
767 dctxPtr->version = versionNumber;
768 *LZ4F_decompressionContextPtr = (LZ4F_decompressionContext_t)dctxPtr;
775 LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)LZ4F_decompressionContext;
776 if (dctxPtr != NULL) /* can accept NULL input, like free() */
778 result = (LZ4F_errorCode_t)dctxPtr->dStage;
779 FREEMEM(dctxPtr->tmpIn);
780 FREEMEM(dctxPtr->tmpOutBuffer);
781 FREEMEM(dctxPtr);
807 dctxPtr->frameInfo and dctxPtr->dStage.
810 static size_t LZ4F_decodeHeader(LZ4F_dctx_t* dctxPtr, const void* srcVoidPtr, size_t srcSize)
820 memset(&(dctxPtr->frameInfo), 0, sizeof(dctxPtr->frameInfo));
825 dctxPtr->frameInfo.frameType = LZ4F_skippableFrame;
826 if (srcVoidPtr == (void*)(dctxPtr->header))
828 dctxPtr->tmpInSize = srcSize;
829 dctxPtr->tmpInTarget = 8;
830 dctxPtr->dStage = dstage_storeSFrameSize;
835 dctxPtr->dStage = dstage_getSFrameSize;
842 dctxPtr->frameInfo.frameType = LZ4F_frame;
858 if (srcPtr != dctxPtr->header)
859 memcpy(dctxPtr->header, srcPtr, srcSize);
860 dctxPtr->tmpInSize = srcSize;
861 dctxPtr->tmpInTarget = frameHeaderSize;
862 dctxPtr->dStage = dstage_storeHeader;
882 dctxPtr->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode;
883 dctxPtr->frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)contentChecksumFlag;
884 dctxPtr->frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID;
885 dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID);
887 dctxPtr->frameRemainingSize = dctxPtr->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6);
890 if (contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0);
893 bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB);
894 if (bufferNeeded > dctxPtr->maxBufferSize) /* tmp buffers too small */
896 FREEMEM(dctxPtr->tmpIn);
897 FREEMEM(dctxPtr->tmpOutBuffer);
898 dctxPtr->maxBufferSize = bufferNeeded;
899 dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize);
900 if (dctxPtr->tmpIn == NULL) return (size_t)-LZ4F_ERROR_GENERIC;
901 dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(dctxPtr->maxBufferSize);
902 if (dctxPtr->tmpOutBuffer== NULL) return (size_t)-LZ4F_ERROR_GENERIC;
904 dctxPtr->tmpInSize = 0;
905 dctxPtr->tmpInTarget = 0;
906 dctxPtr->dict = dctxPtr->tmpOutBuffer;
907 dctxPtr->dictSize = 0;
908 dctxPtr->tmpOut = dctxPtr->tmpOutBuffer;
909 dctxPtr->tmpOutStart = 0;
910 dctxPtr->tmpOutSize = 0;
912 dctxPtr->dStage = dstage_getCBlockSize;
931 LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)dCtx;
933 if (dctxPtr->dStage > dstage_storeHeader) /* note : requires dstage_* header related to be at beginning of enum */
938 *frameInfoPtr = dctxPtr->frameInfo;
945 if (dctxPtr->dStage <= dstage_storeHeader) /* note : requires dstage_* header related to be at beginning of enum */
947 *frameInfoPtr = dctxPtr->frameInfo;
961 static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dstSize, const BYTE* dstPtr0, unsigned withinTmp)
963 if (dctxPtr->dictSize==0)
964 dctxPtr->dict = (const BYTE*)dstPtr; /* priority to dictionary continuity */
966 if (dctxPtr->dict + dctxPtr->dictSize == dstPtr) /* dictionary continuity */
968 dctxPtr->dictSize += dstSize;
974 dctxPtr->dict = (const BYTE*)dstPtr0;
975 dctxPtr->dictSize = dstPtr - dstPtr0 + dstSize;
979 if ((withinTmp) && (dctxPtr->dict == dctxPtr->tmpOutBuffer))
981 /* assumption : dctxPtr->dict + dctxPtr->dictSize == dctxPtr->tmpOut + dctxPtr->tmpOutStart */
982 dctxPtr->dictSize += dstSize;
988 size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
989 size_t copySize = 64 KB - dctxPtr->tmpOutSize;
990 const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
991 if (dctxPtr->tmpOutSize > 64 KB) copySize = 0;
994 memcpy(dctxPtr->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize);
996 dctxPtr->dict = dctxPtr->tmpOutBuffer;
997 dctxPtr->dictSize = preserveSize + dctxPtr->tmpOutStart + dstSize;
1001 if (dctxPtr->dict == dctxPtr->tmpOutBuffer) /* copy dst into tmp to complete dict */
1003 if (dctxPtr->dictSize + dstSize > dctxPtr->maxBufferSize) /* tmp buffer not large enough */
1006 memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize);
1007 dctxPtr->dictSize = preserveSize;
1009 memcpy(dctxPtr->tmpOutBuffer + dctxPtr->dictSize, dstPtr, dstSize);
1010 dctxPtr->dictSize += dstSize;
1017 if (preserveSize > dctxPtr->dictSize) preserveSize = dctxPtr->dictSize;
1018 memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize);
1019 memcpy(dctxPtr->tmpOutBuffer + preserveSize, dstPtr, dstSize);
1020 dctxPtr->dict = dctxPtr->tmpOutBuffer;
1021 dctxPtr->dictSize = preserveSize + dstSize;
1049 LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)decompressionContext;
1068 if (dctxPtr->srcExpect != NULL)
1070 if (srcStart != dctxPtr->srcExpect) return (size_t)-LZ4F_ERROR_srcPtr_wrong;
1078 switch(dctxPtr->dStage)
1085 LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, srcPtr, srcEnd-srcPtr);
1090 dctxPtr->tmpInSize = 0;
1091 dctxPtr->tmpInTarget = minFHSize; /* minimum to attempt decode */
1092 dctxPtr->dStage = dstage_storeHeader;
1097 size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1099 memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1100 dctxPtr->tmpInSize += sizeToCopy;
1102 if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget)
1104 nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize; /* rest of header + nextBlockHeader */
1109 LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, dctxPtr->header, dctxPtr->tmpInTarget);
1125 dctxPtr->tmpInSize = 0;
1126 dctxPtr->dStage = dstage_storeCBlockSize;
1130 if (dctxPtr->dStage == dstage_storeCBlockSize)
1133 size_t sizeToCopy = BHSize - dctxPtr->tmpInSize;
1135 memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1137 dctxPtr->tmpInSize += sizeToCopy;
1138 if (dctxPtr->tmpInSize < BHSize) /* not enough input to get full cBlockSize; wait for more */
1140 nextSrcSizeHint = BHSize - dctxPtr->tmpInSize;
1144 selectedIn = dctxPtr->tmpIn;
1152 dctxPtr->dStage = dstage_getSuffix;
1155 if (nextCBlockSize > dctxPtr->maxBlockSize) return (size_t)-LZ4F_ERROR_GENERIC; /* invalid cBlockSize */
1156 dctxPtr->tmpInTarget = nextCBlockSize;
1159 dctxPtr->dStage = dstage_copyDirect;
1162 dctxPtr->dStage = dstage_getCBlock;
1173 size_t sizeToCopy = dctxPtr->tmpInTarget;
1177 if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), srcPtr, sizeToCopy);
1178 if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= sizeToCopy;
1181 if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1182 LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 0);
1186 if (sizeToCopy == dctxPtr->tmpInTarget) /* all copied */
1188 dctxPtr->dStage = dstage_getCBlockSize;
1191 dctxPtr->tmpInTarget -= sizeToCopy; /* still need to copy more */
1192 nextSrcSizeHint = dctxPtr->tmpInTarget + BHSize;
1199 if ((size_t)(srcEnd-srcPtr) < dctxPtr->tmpInTarget)
1201 dctxPtr->tmpInSize = 0;
1202 dctxPtr->dStage = dstage_storeCBlock;
1206 srcPtr += dctxPtr->tmpInTarget;
1207 dctxPtr->dStage = dstage_decodeCBlock;
1213 size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1215 memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1216 dctxPtr->tmpInSize += sizeToCopy;
1218 if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) /* need more input */
1220 nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize;
1224 selectedIn = dctxPtr->tmpIn;
1225 dctxPtr->dStage = dstage_decodeCBlock;
1231 if ((size_t)(dstEnd-dstPtr) < dctxPtr->maxBlockSize) /* not enough place into dst : decode into tmpOut */
1232 dctxPtr->dStage = dstage_decodeCBlock_intoTmp;
1234 dctxPtr->dStage = dstage_decodeCBlock_intoDst;
1243 if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked)
1248 decodedSize = decoder((const char*)selectedIn, (char*)dstPtr, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
1250 if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize);
1251 if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize;
1254 if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1255 LZ4F_updateDict(dctxPtr, dstPtr, decodedSize, dstStart, 0);
1258 dctxPtr->dStage = dstage_getCBlockSize;
1268 if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked)
1274 if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked)
1276 if (dctxPtr->dict == dctxPtr->tmpOutBuffer)
1278 if (dctxPtr->dictSize > 128 KB)
1280 memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB);
1281 dctxPtr->dictSize = 64 KB;
1283 dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + dctxPtr->dictSize;
1287 size_t reservedDictSpace = dctxPtr->dictSize;
1289 dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + reservedDictSpace;
1294 decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
1296 if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize);
1297 if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize;
1298 dctxPtr->tmpOutSize = decodedSize;
1299 dctxPtr->tmpOutStart = 0;
1300 dctxPtr->dStage = dstage_flushOut;
1306 size_t sizeToCopy = dctxPtr->tmpOutSize - dctxPtr->tmpOutStart;
1308 memcpy(dstPtr, dctxPtr->tmpOut + dctxPtr->tmpOutStart, sizeToCopy);
1311 if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1312 LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 1);
1314 dctxPtr->tmpOutStart += sizeToCopy;
1318 if (dctxPtr->tmpOutStart == dctxPtr->tmpOutSize)
1320 dctxPtr->dStage = dstage_getCBlockSize;
1330 size_t suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4;
1331 if (dctxPtr->frameRemainingSize) return (size_t)-LZ4F_ERROR_frameSize_wrong; /* incorrect frame size decoded */
1335 dctxPtr->dStage = dstage_getHeader;
1341 dctxPtr->tmpInSize = 0;
1342 dctxPtr->dStage = dstage_storeSuffix;
1351 if (dctxPtr->dStage == dstage_storeSuffix)
1354 size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
1356 memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1358 dctxPtr->tmpInSize += sizeToCopy;
1359 if (dctxPtr->tmpInSize < 4) /* not enough input to read complete suffix */
1361 nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
1365 selectedIn = dctxPtr->tmpIn;
1371 U32 resultCRC = XXH32_digest(&(dctxPtr->xxh));
1374 dctxPtr->dStage = dstage_getHeader;
1389 dctxPtr->tmpInSize = 4;
1390 dctxPtr->tmpInTarget = 8;
1391 dctxPtr->dStage = dstage_storeSFrameSize;
1395 if (dctxPtr->dStage == dstage_storeSFrameSize)
1398 size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1400 memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
1402 dctxPtr->tmpInSize += sizeToCopy;
1403 if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) /* not enough input to get full sBlockSize; wait for more */
1405 nextSrcSizeHint = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
1409 selectedIn = dctxPtr->header + 4;
1415 dctxPtr->frameInfo.contentSize = SFrameSize;
1416 dctxPtr->tmpInTarget = SFrameSize;
1417 dctxPtr->dStage = dstage_skipSkippable;
1423 size_t skipSize = dctxPtr->tmpInTarget;
1426 dctxPtr->tmpInTarget -= skipSize;
1428 nextSrcSizeHint = dctxPtr->tmpInTarget;
1430 dctxPtr->dStage = dstage_getHeader;
1437 if ( (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked)
1438 &&(dctxPtr->dict != dctxPtr->tmpOutBuffer)
1440 &&((unsigned)(dctxPtr->dStage-1) < (unsigned)(dstage_getSuffix-1))
1443 if (dctxPtr->dStage == dstage_flushOut)
1445 size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
1446 size_t copySize = 64 KB - dctxPtr->tmpOutSize;
1447 const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
1448 if (dctxPtr->tmpOutSize > 64 KB) copySize = 0;
1451 memcpy(dctxPtr->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize);
1453 dctxPtr->dict = dctxPtr->tmpOutBuffer;
1454 dctxPtr->dictSize = preserveSize + dctxPtr->tmpOutStart;
1458 size_t newDictSize = dctxPtr->dictSize;
1459 const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize;
1462 memcpy(dctxPtr->tmpOutBuffer, oldDictEnd - newDictSize, newDictSize);
1464 dctxPtr->dict = dctxPtr->tmpOutBuffer;
1465 dctxPtr->dictSize = newDictSize;
1466 dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + newDictSize;
1472 dctxPtr->srcExpect = srcPtr;
1474 dctxPtr->srcExpect = NULL;