Esempio n. 1
0
uint32 CCsoImageStream::ReadFromNextFrame(uint8* dest, uint64 maxBytes)
{
	assert(!IsEOF());

	const uint32 frame = static_cast<uint32>(m_position >> m_frameShift);
	const uint32 offset = static_cast<uint32>(m_position - (frame << m_frameShift));
	// This is how many bytes we will actually be reading from this frame.
	const uint32 bytes = static_cast<uint32>(std::min(maxBytes, static_cast<uint64>(m_frameSize - offset)));

	// Grab the index data for the frame we're about to read.
	const bool compressed = (m_index[frame + 0] & 0x80000000) == 0;
	const uint32 index0 = m_index[frame + 0] & 0x7FFFFFFF;
	const uint32 index1 = m_index[frame + 1] & 0x7FFFFFFF;

	// Calculate where the compressed payload is (if compressed.)
	const uint64 frameRawPos = static_cast<uint64>(index0) << m_indexShift;
	const uint64 frameRawSize = (index1 - index0) << m_indexShift;

	if(!compressed)
	{
		// Just read directly, easy.
		if(ReadBaseAt(frameRawPos + offset, dest, bytes) != bytes)
		{
			throw std::runtime_error("Unable to read uncompressed bytes from CSO.");
		}
	}
	else
	{
		// We don't need to decompress if we already did this same frame last time.
		if(m_zlibBufferFrame != frame)
		{
			// This might be less bytes than frameRawSize in case of padding on the last frame.
			// This is because the index positions must be aligned.
			const uint64 readRawBytes = ReadBaseAt(frameRawPos, m_readBuffer, frameRawSize);
			DecompressFrame(frame, readRawBytes);
		}

		// Now we just copy the offset data from the cache.
		memcpy(dest, m_zlibBuffer + offset, bytes);
	}

	return bytes;
}
Esempio n. 2
0
void main()
{
unsigned char data[5000] ;
int i;
int n,size=2130;
FILE *f,*bmp;
char tstr[]="BM";

	
   InitH263Decoder();
  
   
   //Read from the file
		
   f=fopen("h263","rb");
  
   if(f==NULL)
   {
   printf("error in opening file");
   return;
   }

    n=fread(data,sizeof(char),size,f);
	if(n<size)
	{
	printf("total data read...%d \n terminating...",n);
	return;
	}
  

   
 
  
	for(i=0;i<5;i++)
	{

		printf("\ndecompressing frame...%d",i);
  
		int ret=DecompressFrame(data,size,rgbdata,80000);
		
		if(ret)
			printf("\n success");
		else
		{
			printf("\n failure");
			continue;
		}
  
    

			//Create bitmap file.....
			bmp=fopen("my.bmp","wb");

		  if(bmp==NULL)
		  {
			 printf("unable to create bmp file");
			return;
		  }

		  // Write 2 standard bytes .."BM"
		  fwrite(tstr,1,2,bmp);
		
		  // create and write file header
		  bfh.fsize=FILE_SIZE;
		  bfh.reserved=0;
		  bfh.offset=40+14;

	      fwrite(&bfh,1,sizeof(bfh),bmp);

		  //create and write bmp header
		  bih.bibitcount=24;
		  bih.biclrimp=0;
		  bih.biclrused=0;
		  bih.bicompression=0;
		  bih.biheight=IMAGE_HEIGHT;
		  bih.biplanes=1;  //if does not work change it to 0
		  bih.bisize=40;
		  bih.bisizeimage=0;
		  bih.biwidth=IMAGE_WIDTH;
		  bih.bixpixelspermeter=0;
		  bih.biypixelspermeter=0;

		  fwrite(&bih,1,sizeof(bih),bmp);


		  // now write image data.....
		  fwrite(rgbdata,1,IMAGE_SIZE,bmp);

		  // close the file safely...
		  fclose(bmp);

	}
  
 // Finaly close the decoder safely....
  ExitH263Decoder();
  

  fclose(f);

  
}