locked
Challanging Question for AVI Read Experts RRS feed

  • Question

  • With same code and same AVI file, the intensity value read are different on different machine.

    On some machine black area is read as 0 and on some machine it is read as non zero value (viz. 4, 5, 7 etc)

    Both the machines uses Main Concept MJPEG codec for reading of AVI files.

     

    Below is code snippet used to open the AVI file

    void CAVIInfoController::SetAVIInfo()
    {
    	TRY
    	{
    		HRESULT hResult = 0;
    		AVIFileInit() ;
    
    		hResult = AVIFileOpen( &m_AviFile, m_strAVIFileName, OF_READ, NULL ) ;
    		if(hResult != 0)
    		{
    			TRACE( _T("AVIFileOpen() Error!!\n") ) ;
    		}
    
    		hResult = AVIFileGetStream(m_AviFile, &m_Stream, streamtypeVIDEO, 0);
    		if(hResult != 0)
    		{
    			TRACE( _T("AVIFileGetStream() Error!!\n"));
    		}
    
    		AVIStreamAddRef(m_Stream );
    
    		hResult = AVIStreamInfo(m_Stream, &m_StreamInfo, sizeof(AVISTREAMINFO));
    		if(hResult != 0)
    		{
    			TRACE( _T("AVIStreamInfo() Error!!\n") ) ;
    		}
    
    		m_nEndFrame = (short)((AVIStreamEnd( m_Stream )) - 1) ;
    
    		long nLength = AVIStreamLength(m_Stream);
    
    		long lSize;
    		hResult = AVIStreamReadFormat(m_Stream, 0, NULL, &lSize);
    
    		m_pBitmapInfoHeader = (BITMAPINFOHEADER*)GlobalAllocPtr(GHND, lSize);
    
    		hResult = AVIStreamReadFormat(m_Stream, 0, (LPVOID)m_pBitmapInfoHeader, &lSize);
    
    		if(m_pBitmapInfoHeader->biBitCount == 16)
    		{
    			m_pBitmapInfoHeader->biBitCount = 24;
    		}
    		m_pBitmapInfoHeader->biCompression = BI_RGB;
    		m_pBitmapInfoHeader->biSizeImage  = (DWORD)m_StreamInfo.dwSampleSize;
    
    		m_pBitmapInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
    		m_GetFrame = AVIStreamGetFrameOpen( m_Stream,m_pBitmapInfoHeader);
    	}
    	CATCH (CException, pEx)
    	{
    		return;
    	}
    	END_CATCH
    
    }

     

     

    Below function is used to retrieve the starting address for particular Frame

     

     

     

    BYTE* CAVIInfoController::GetFrameAVI(UINT nFrameNumber)
    {
    	return (BYTE*)AVIStreamGetFrame(m_GetFrame,nFrameNumber);
    }

     

     

     

    Starting address of bit data is calculated as follows

    BYTE* CAVIInfoController::GetBitAddress( BYTE* pDIB ) 
    {
    	TRY
    	{
    		if ( pDIB == NULL )
    		{
    			return NULL ;
    		}
    
    		WORD wBitCount = ((BITMAPINFOHEADER*)pDIB)->biBitCount ;
    
    		DWORD dwNumColors = 0 ;
    		if ( wBitCount != 24 )
    		{
    			dwNumColors = ((BITMAPINFOHEADER*)pDIB)->biClrUsed ;
    			if ( dwNumColors == 0 )
    			{
    				switch ( wBitCount )
    				{
    					// PixelBitMonochrome
    				case 1 :
    					dwNumColors = 2 ;
    					break;
    
    					// PixelBit16Color
    				case 4 :
    					dwNumColors = 16 ;
    					break;
    
    					// PixelBit256Color
    				case 8 :
    					dwNumColors = 256 ;
    					break;
    				default:
    					dwNumColors = 0;
    					break;
    				}
    			}
    		}
    
    		DWORD dwColorTableSize = (dwNumColors * sizeof( RGBQUAD )) ;
    
    		DWORD dSize = 0;
    		dSize = ((BITMAPINFOHEADER*)pDIB)->biSize ;
    
    		return ((BYTE*)pDIB + dSize + dwColorTableSize) ;
    	}
    	CATCH (CException, pEx)
    	{
    		return NULL;
    	}
    	END_CATCH
    }

     

    What is the possible reasons for intensity being read differently?

    (Does it had something to do with the Luminance from HSL?)

    In case you need sample application, please let me know so that I can mail the same.

    • Moved by Jesse Jiang Thursday, October 21, 2010 2:24 AM (From:Visual C++ General)
    Tuesday, October 19, 2010 7:49 AM

All replies

  • Differences in output color vluaes between machines would likely be due to differences in optimization between machines.  The codec might use vector instructions on some processor architectures that are not available on other architectures, and perhaps there is some small difference in the computed values.  Or the codec might use the GPU for acceleration, and the GPU generated values might be off from the CPU generated values slightly.  If you want to know precisely why the color values generated by the codec are different between machines, you should follow up with the developer of the codec.

    Wednesday, November 10, 2010 7:43 PM