toolsandutils/e32tools/elf2e32/source/pagedcompress.cpp
branchGCC_SURGE
changeset 61 b376866b09e6
parent 0 83f4b4db085c
equal deleted inserted replaced
60:5a90ee674b42 61:b376866b09e6
   268 
   268 
   269 
   269 
   270 }
   270 }
   271 
   271 
   272 
   272 
   273 void CompressPages(TUint8* bytes, TInt size, std::ofstream& os)
   273 void CompressPages(TUint8 * bytes, TInt size, std::ofstream& os)
   274 {
   274 {
   275 	// Build a list of compressed pages
   275 	// Build a list of compressed pages
   276 	TUint16 numOfPages = (TUint16) ((size + PAGE_SIZE - 1) / PAGE_SIZE);
   276 	TUint16 numOfPages = (TUint16) (size / PAGE_SIZE);
   277 	
   277 	if ( size % PAGE_SIZE > 0)
   278 	CBytePairCompressedImage* comprImage = CBytePairCompressedImage::NewLC(numOfPages, size);
   278 		++numOfPages;
   279 	if (!comprImage)
   279 	
       
   280 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(numOfPages, size);
       
   281 	if( NULL == comprImage)
   280 	{
   282 	{
   281 		//Print(EError," NULL == comprImage\n");
   283 		//Print(EError," NULL == comprImage\n");
   282 		return;
   284 		return;
   283 	}
   285 	}
   284 	
   286 	
   285 	TUint pageNum;
   287 	TUint8* iPageStart;
   286 	TUint remain = (TUint)size;
   288 	TUint16 iPageLen;
   287 	for (pageNum=0; pageNum<numOfPages; ++pageNum)
   289 	TUint16 iPage = 0;
   288 	{
   290 	
   289 		TUint8* pageStart = bytes + pageNum * PAGE_SIZE;
   291 	while(iPage * PAGE_SIZE <= size )
   290 		TUint pageLen = remain>PAGE_SIZE ? PAGE_SIZE : remain;
   292 	{
   291 		comprImage->AddPage((TUint16)pageNum, pageStart, (TUint16)pageLen);
   293 		iPageStart = &bytes[iPage * PAGE_SIZE];
   292 		remain -= pageLen;
   294 		iPageLen = (TUint16)( (iPage + 1) * PAGE_SIZE < size ? PAGE_SIZE : size - iPage * PAGE_SIZE);
       
   295 		
       
   296 		comprImage->AddPage(iPage, iPageStart, iPageLen);
       
   297 
       
   298 		++iPage;
   293 	}
   299 	}
   294 	
   300 	
   295 	// Write out index table and compressed pages
   301 	// Write out index table and compressed pages
   296 	comprImage->WriteOutTable(os);
   302 	comprImage->WriteOutTable(os);
   297 	
   303 	
   298 	
   304 	
   299 	delete comprImage;
   305 	delete comprImage;
   300 	comprImage = NULL;
   306 	comprImage = NULL;
   301 	
   307 	
   302 }
   308 }
   303 
       
   304 
   309 
   305 int DecompressPages(TUint8 * bytes, std::ifstream& is)
   310 int DecompressPages(TUint8 * bytes, std::ifstream& is)
   306 {
   311 {
   307 	TUint decompressedSize = 0;
   312 	TUint decompressedSize = 0;
   308 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(0, 0);
   313 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(0, 0);