O3DGCErrorCode LoadBinAC(Vector<long> & data, const BinaryStream & bstream, unsigned long & iterator) { size_t sizeSize = bstream.ReadUInt32Bin(iterator) - 8; size_t size = bstream.ReadUInt32Bin(iterator); if (size == 0) { return O3DGC_OK; } unsigned char * buffer = 0; bstream.GetBuffer(iterator, buffer); iterator += sizeSize; data.Allocate(size); Arithmetic_Codec acd; acd.set_buffer(sizeSize, buffer); acd.start_decoder(); Adaptive_Bit_Model bModel; #ifdef DEBUG_VERBOSE printf("-----------\nsize %i\n", size); fprintf(g_fileDebugTF, "size %i\n", size); #endif //DEBUG_VERBOSE for(size_t i = 0; i < size; ++i) { data.PushBack(acd.decode(bModel)); #ifdef DEBUG_VERBOSE printf("%i\t%i\n", i, data[i]); fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]); #endif //DEBUG_VERBOSE } return O3DGC_OK; }
O3DGCErrorCode LoadUIntAC(Vector<long> & data, const unsigned long M, const BinaryStream & bstream, unsigned long & iterator) { unsigned long sizeSize = bstream.ReadUInt32Bin(iterator) - 12; unsigned long size = bstream.ReadUInt32Bin(iterator); if (size == 0) { return O3DGC_OK; } long minValue = bstream.ReadUInt32Bin(iterator); unsigned char * buffer = 0; bstream.GetBuffer(iterator, buffer); iterator += sizeSize; data.Allocate(size); Arithmetic_Codec acd; acd.set_buffer(sizeSize, buffer); acd.start_decoder(); Adaptive_Data_Model mModelValues(M+1); #ifdef DEBUG_VERBOSE printf("-----------\nsize %i\n", size); fprintf(g_fileDebugTF, "size %i\n", size); #endif //DEBUG_VERBOSE for(unsigned long i = 0; i < size; ++i) { data.PushBack(acd.decode(mModelValues)+minValue); #ifdef DEBUG_VERBOSE printf("%i\t%i\n", i, data[i]); fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]); #endif //DEBUG_VERBOSE } return O3DGC_OK; }
O3DGCErrorCode CompressedTriangleFans::SaveUIntAC(const Vector<long> & data, const unsigned long M, BinaryStream & bstream) { unsigned long start = bstream.GetSize(); const unsigned int NMAX = data.GetSize() * 8 + 100; const size_t size = data.GetSize(); long minValue = O3DGC_MAX_LONG; bstream.WriteUInt32Bin(0); bstream.WriteUInt32Bin(size); if (size > 0) { #ifdef DEBUG_VERBOSE printf("-----------\nsize %i, start %i\n", size, start); fprintf(g_fileDebugTF, "-----------\nsize %i, start %i\n", size, start); #endif //DEBUG_VERBOSE for(size_t i = 0; i < size; ++i) { if (minValue > data[i]) { minValue = data[i]; } #ifdef DEBUG_VERBOSE printf("%i\t%i\n", i, data[i]); fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]); #endif //DEBUG_VERBOSE } bstream.WriteUInt32Bin(minValue); if ( m_sizeBufferAC < NMAX ) { delete [] m_bufferAC; m_sizeBufferAC = NMAX; m_bufferAC = new unsigned char [m_sizeBufferAC]; } Arithmetic_Codec ace; ace.set_buffer(NMAX, m_bufferAC); ace.start_encoder(); Adaptive_Data_Model mModelValues(M+1); for(size_t i = 0; i < size; ++i) { ace.encode(data[i]-minValue, mModelValues); } unsigned long encodedBytes = ace.stop_encoder(); for(size_t i = 0; i < encodedBytes; ++i) { bstream.WriteUChar8Bin(m_bufferAC[i]); } } bstream.WriteUInt32Bin(start, bstream.GetSize() - start); return O3DGC_OK; }
O3DGCErrorCode LoadIntACEGC(Vector<long> & data, const unsigned long M, const BinaryStream & bstream, unsigned long & iterator) { size_t sizeSize = bstream.ReadUInt32Bin(iterator) - 12; size_t size = bstream.ReadUInt32Bin(iterator); if (size == 0) { return O3DGC_OK; } long minValue = bstream.ReadUInt32Bin(iterator) - O3DGC_MAX_LONG; unsigned char * buffer = 0; bstream.GetBuffer(iterator, buffer); iterator += sizeSize; data.Allocate(size); Arithmetic_Codec acd; acd.set_buffer(sizeSize, buffer); acd.start_decoder(); Adaptive_Data_Model mModelValues(M+2); Static_Bit_Model bModel0; Adaptive_Bit_Model bModel1; unsigned long value; #ifdef DEBUG_VERBOSE printf("-----------\nsize %i\n", size); fprintf(g_fileDebugTF, "size %i\n", size); #endif //DEBUG_VERBOSE for(size_t i = 0; i < size; ++i) { value = acd.decode(mModelValues); if ( value == M) { value += acd.ExpGolombDecode(0, bModel0, bModel1); } data.PushBack(value + minValue); #ifdef DEBUG_VERBOSE printf("%i\t%i\n", i, data[i]); fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]); #endif //DEBUG_VERBOSE } #ifdef DEBUG_VERBOSE fflush(g_fileDebugTF); #endif //DEBUG_VERBOSE return O3DGC_OK; }