e32tools/elf2e32/source/pagedcompress.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
   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);
   276 	TUint16 numOfPages = (TUint16) ((size + PAGE_SIZE - 1) / PAGE_SIZE);
   277 	if ( size % PAGE_SIZE > 0)
   277 	
   278 		++numOfPages;
   278 	CBytePairCompressedImage* comprImage = CBytePairCompressedImage::NewLC(numOfPages, size);
   279 	
   279 	if (!comprImage)
   280 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(numOfPages, size);
       
   281 	if( NULL == comprImage)
       
   282 	{
   280 	{
   283 		//Print(EError," NULL == comprImage\n");
   281 		//Print(EError," NULL == comprImage\n");
   284 		return;
   282 		return;
   285 	}
   283 	}
   286 	
   284 	
   287 	TUint8* iPageStart;
   285 	TUint pageNum;
   288 	TUint16 iPageLen;
   286 	TUint remain = (TUint)size;
   289 	TUint16 iPage = 0;
   287 	for (pageNum=0; pageNum<numOfPages; ++pageNum)
   290 	
   288 	{
   291 	while(iPage * PAGE_SIZE <= size )
   289 		TUint8* pageStart = bytes + pageNum * PAGE_SIZE;
   292 	{
   290 		TUint pageLen = remain>PAGE_SIZE ? PAGE_SIZE : remain;
   293 		iPageStart = &bytes[iPage * PAGE_SIZE];
   291 		comprImage->AddPage((TUint16)pageNum, pageStart, (TUint16)pageLen);
   294 		iPageLen = (TUint16)( (iPage + 1) * PAGE_SIZE < size ? PAGE_SIZE : size - iPage * PAGE_SIZE);
   292 		remain -= pageLen;
   295 		
       
   296 		comprImage->AddPage(iPage, iPageStart, iPageLen);
       
   297 
       
   298 		++iPage;
       
   299 	}
   293 	}
   300 	
   294 	
   301 	// Write out index table and compressed pages
   295 	// Write out index table and compressed pages
   302 	comprImage->WriteOutTable(os);
   296 	comprImage->WriteOutTable(os);
   303 	
   297 	
   304 	
   298 	
   305 	delete comprImage;
   299 	delete comprImage;
   306 	comprImage = NULL;
   300 	comprImage = NULL;
   307 	
   301 	
   308 }
   302 }
       
   303 
   309 
   304 
   310 int DecompressPages(TUint8 * bytes, std::ifstream& is)
   305 int DecompressPages(TUint8 * bytes, std::ifstream& is)
   311 {
   306 {
   312 	TUint decompressedSize = 0;
   307 	TUint decompressedSize = 0;
   313 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(0, 0);
   308 	CBytePairCompressedImage *comprImage = CBytePairCompressedImage::NewLC(0, 0);