unpacking DIB frame retrived from AVI

This is a discussion on unpacking DIB frame retrived from AVI within the Windows Programming forums, part of the Platform Specific Boards category; HI EveryOne, I was able to solve the problem of unpaking the DIB to Buffer, but now i want to ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    Split RGB from buffered Image

    HI EveryOne,

    I was able to solve the problem of unpaking the DIB to Buffer, but now i want to split RGB of the buffer to three different array.
    Please help me do that....
    Code:
    BOOL CAVIDEMODlg::SplitImageAddToFrame(LPBITMAPINFOHEADER pbmih){
    
    	int s,x,y;
    	BITMAPFILEHEADER bmfh;
    
    	x=pbmih->biWidth;
    	y=abs(pbmih->biHeight);
    
    	bmfh.bfType=0x4d42;
    	bmfh.bfReserved1=bmfh.bfReserved2=0;
    
    	if (pbmih->biClrUsed==0)
    		switch (pbmih->biBitCount) {
    			case  1:bmfh.bfOffBits=8;break;
    			case  4:bmfh.bfOffBits=64;break;
    			case  8:bmfh.bfOffBits=1024;break;
    			case 24:bmfh.bfOffBits=0;break;
    			case 16:
    			case 32:bmfh.bfOffBits=pbmih->biCompression==BI_RGB?12:0;
    		}
    	else
    		bmfh.bfOffBits=pbmih->biClrUsed*4;
    		bmfh.bfOffBits+=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    
    		if (pbmih->biSizeImage==0) {
    		switch (pbmih->biBitCount) {
    			case  1:s=(x+7)/8;break;
    			case  4:s=(x+1)/2;break;
    			case  8:s=x;break;
    			case 16:s=x*2;break;
    			case 24:s=x*3;break;
    			case 32:s=x*4;
    		}
    			bmfh.bfSize=bmfh.bfOffBits+(s+3)/4*4*y;
    		} else {
    			bmfh.bfSize=bmfh.bfOffBits+pbmih->biSizeImage;
    		}
    
    	DWORD ImageSize = ((DWORD)bmfh.bfSize-sizeof(BITMAPFILEHEADER));
    	LPBYTE pImage = (LPBYTE )malloc(ImageSize);
    // pImage is buffer of Image data, now i want to seprate RGB from the buffer
    	memcpy(pImage,pbmih,ImageSize);	
        
    	if(!pImage){
    		return FALSE;
    	}
    
    	//return fclose(fp);
    	
    	return TRUE;
    }
    Last edited by simly01; 04-08-2003 at 10:15 PM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    This has all the information you need, like I posted before.

    There may or may not be a color table after the header. After the table, if any, is the actual DIB data. Here is how you get the size of the table (this is in the reference):
    Code:
    int nNumColors;
    if (!(nNumColors = pBmp->biClrUsed))
    {
       if (pBmp->biBitCount != 24)
          nNumColors = 1 << pBmp->biBitCount;
    }
    int nTableSize = nNumColors * sizeof(RGBQUAD);
    If nTableSize is 0, then there is no table (meaning its a 24bit DIB). The table consists of an array of RGBQUAD data structures. You can get a pointer to this table and the data like so (your code and the reference site has a bug in the pointer calculations):
    Code:
    RGBQUAD *pTable = (RGBQUAD*)((LPBYTE)pBmp + pBmp->biSize);
    LPBYTE *pData =  (LPBYTE)pTable + nTableSize;
    Now you just have to decode the data, which is explained in the reference. Read the "Bit Formats" section.

    Remember that each scanline in the data is DWORD aligned. You can use this code to get a pointer to the beginning of a particular scanline:
    Code:
    int nScanlineSize = (((pBmp->biWidth * pBmp->biBitCount) + 31) & ~31) >> 3;
    LPVOID pScanLine = pData + (nRow * nScanLineSize);
    Also remember that the scanlines are upsidedown - the first scanline is the bottom of the image. Also, if wUsage contains DIB_PAL_COLORS, then the table is an array of DWORDs, not RGBQUADs...(read it in the reference as well).

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 04:37 AM
  2. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21