/*
** PR_MD_realloc() -- exported as realloc()
**
*/
void *PR_MD_realloc( void* old_blk, size_t size )
{
    if( _pr_callback_funcs ) {
        return (*_pr_callback_funcs->realloc)( old_blk, size );
    } else {
        return GlobalReAllocPtr( old_blk, (DWORD)size, GPTR);
    }
} /* end realloc */
Exemple #2
0
BOOL	CDib::AllocateMemory(BOOL	bRealloc)
{
    if(bRealloc)
        m_lpBuf=(LPBYTE)GlobalReAllocPtr(m_lpBuf,m_dwLength,GHND);
    else
        m_lpBuf=(LPBYTE)GlobalAllocPtr(GHND,m_dwLength);
    if(!m_lpBuf)
    {
        AfxMessageBox("Unable to Allocate Dib Memory");
        m_dwLength=0L;
        m_nBits=0;
        m_lpBuf=NULL;
        return FALSE;
    }
    m_lpBMFH=(LPBITMAPFILEHEADER)m_lpBuf;
    m_lpBMIH=(LPBITMAPINFOHEADER)(m_lpBuf+sizeof(BITMAPFILEHEADER));;
    m_lpBMI=(LPBITMAPINFO)m_lpBMIH;
    return	TRUE;
}
Exemple #3
0
tdata_t
_TIFFrealloc(tdata_t p, tsize_t s)
{
  return (tdata_t) GlobalReAllocPtr(p, (DWORD) s, GHND);
}
Exemple #4
0
void PaintAudio(
		HDC hdc, PRECT prc, PAVISTREAM pavi, LONG lStart, LONG lLen)
	{
#ifndef INTERIM_64_BIT	// CCJ
    LPVOID lpAudio=NULL;
    PCMWAVEFORMAT wf;
    int i;
    int x,y;
    int w,h;
    BYTE b;
    HBRUSH hbr;
    RECT rc = *prc;
    LONG    lBytes;
    LONG    l, lLenOrig = lLen;
    LONG    lWaveBeginTime = AVIStreamStartTime(pavi);
    LONG    lWaveEndTime   = AVIStreamEndTime(pavi);

    //
    // We can't draw before the beginning of the stream - adjust
    //
    if (lStart < lWaveBeginTime) {
		lLen -= lWaveBeginTime - lStart;
		lStart = lWaveBeginTime;
		// right justify the legal samples in the rectangle - don't stretch
		rc.left = rc.right - (int)muldiv32(rc.right - rc.left, lLen, lLenOrig);
	    }

    //
    // We can't draw past the end of the stream
    //
    if (lStart + lLen > lWaveEndTime) {
		lLenOrig = lLen;
		lLen = max(0, lWaveEndTime - lStart);	// maybe nothing to draw!
		// left justify the legal samples in the rectangle - don't stretch
		rc.right = rc.left + (int)muldiv32(rc.right - rc.left, lLen, lLenOrig);
	    }

    // Now start working with samples, not time
    l = lStart;
    lStart = AVIStreamTimeToSample(pavi, lStart);
    lLen   = AVIStreamTimeToSample(pavi, l + lLen) - lStart;

    //
    // Get the format of the wave data
    //
    l = sizeof(wf);
    AVIStreamReadFormat(pavi, lStart, &wf, &l);
    if (!l)
        return;

    w = rc.right - rc.left;
    h = rc.bottom - rc.top;

    //
    // We were starting before the beginning or continuing past the end.
    // We're not painting in the whole original rect --- use a dark background
    //
    if (rc.left > prc->left) {
        SelectObject(hdc, GetStockObject(DKGRAY_BRUSH));
		PatBlt(hdc, prc->left, rc.top, rc.left - prc->left,
						rc.bottom - rc.top, PATCOPY);
    	}
    if (rc.right < prc->right) {
        SelectObject(hdc, GetStockObject(DKGRAY_BRUSH));
		PatBlt(hdc, rc.right, rc.top, prc->right - rc.right,
						rc.bottom - rc.top, PATCOPY);
    	}

#define BACKBRUSH  (GetSysColor(COLOR_BTNFACE))		// background
#define MONOBRUSH  (GetSysColor(COLOR_BTNSHADOW))	// for mono audio
#define LEFTBRUSH  (RGB(0,0,255))			// left channel
#define RIGHTBRUSH (RGB(0,255,0))			// right channel
#define HPOSBRUSH  (RGB(255,0,0))			// current position
    
    //
    // Paint the background
    //
    hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(BACKBRUSH));
    PatBlt(hdc, rc.left, rc.top, w, h, PATCOPY);
    DeleteObject(SelectObject(hdc, hbr));

    //
    // !!! we can only paint PCM data right now.  Sorry!
    //
    if (wf.wf.wFormatTag != WAVE_FORMAT_PCM)
        return;

    //
    // How many bytes are we painting? Alloc some space for them
    //
    lBytes = lLen * wf.wf.nChannels * wf.wBitsPerSample / 8;
    if (!lpAudio)
        lpAudio = GlobalAllocPtr (GHND, lBytes);
    else if ((LONG)GlobalSizePtr(lpAudio) < lBytes)
        lpAudio = GlobalReAllocPtr(lpAudio, lBytes, GMEM_MOVEABLE);
    if (!lpAudio)
        return;

    //
    // Read in the wave data
    //
    AVIStreamRead(pavi, lStart, lLen, lpAudio, lBytes, NULL, &l);
    if (l != lLen)
        return;
    
#define MulDiv(a,b,c) (UINT)((DWORD)(UINT)(a) * (DWORD)(UINT)(b) / (UINT)(c))

    //
    // !!! Flickers less painting it NOW or LATER?
    // First show the current position as a bar
    //
    //hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(HPOSBRUSH));
    //PatBlt(hdc, prc->right / 2, prc->top, 1, prc->bottom - prc->top, PATCOPY);
    //DeleteObject(SelectObject(hdc, hbr));

    //
    // Paint monochrome wave data
    //
    if (wf.wf.nChannels == 1) {

		//
		// Draw the x-axis
		//
        hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(MONOBRUSH));
        y = rc.top + h/2;
        PatBlt(hdc, rc.left, y, w, 1, PATCOPY);
    
		//
		// 8 bit data is centred around 0x80
		//
        if (wf.wBitsPerSample == 8) {
            for (x=0; x<w; x++) {

				// which byte of audio data belongs at this pixel?
                b = *((HPBYTE)lpAudio + muldiv32(x, lLen, w));

                if (b > 0x80) {
                    i = y - MulDiv(b - 0x80, (h / 2), 128);
                    PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
                	}
                else {
                    i = y + MulDiv(0x80 - b, (h / 2), 128);
                    PatBlt(hdc, rc.left + x, y, 1, i - y, PATCOPY);
                	}
            	}
        	}

		//
		// 16 bit data is centred around 0x00
		//
        else if (wf.wBitsPerSample == 16) {
            for (x=0; x<w; x++) {

				// which byte of audio data belongs at this pixel?
	            i = *((HPINT)lpAudio + muldiv32(x,lLen,w));

	            if (i > 0) {
	               i = y - (int) ((LONG)i * (h/2) / 32768);
	               PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
	            	}
	            else {
	               i = (int) ((LONG)i * (h/2) / 32768);
	               PatBlt(hdc, rc.left+x, y, 1, -i, PATCOPY);
	            	}
	            }
        	}
        DeleteObject(SelectObject(hdc, hbr));
	    } // endif mono

    //
    // Draw stereo waveform data
    //
    else if (wf.wf.nChannels == 2) {
		//
		// 8 bit data is centred around 0x80
		//
        if (wf.wBitsPerSample == 8) {

            // Left channel
            hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(LEFTBRUSH));
            y = rc.top + h/4;
            PatBlt(hdc, rc.left, y, w, 1, PATCOPY);

            for (x=0; x<w; x++) {
                b = *((HPBYTE)lpAudio + muldiv32(x,lLen,w) * 2);

                if (b > 0x80) {
                    i = y - MulDiv(b-0x80,(h/4),128);
                    PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
                	}
                else {
                    i = y + MulDiv(0x80-b,(h/4),128);
                    PatBlt(hdc, rc.left+x, y, 1, i-y, PATCOPY);
                	}
            	}
            DeleteObject(SelectObject(hdc, hbr));
                
            // Right channel
            hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(RIGHTBRUSH));
            y = rc.top + h * 3 / 4;
            PatBlt(hdc, rc.left, y, w, 1, PATCOPY);

            for (x=0; x<w; x++) {
                b = *((HPBYTE)lpAudio + muldiv32(x,lLen,w) * 2 + 1);

                if (b > 0x80) {
                    i = y - MulDiv(b-0x80,(h/4),128);
                    PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
                	}
                else {
                    i = y + MulDiv(0x80-b,(h/4),128);
                    PatBlt(hdc, rc.left+x, y, 1, i-y, PATCOPY);
                	}
            	}
            DeleteObject(SelectObject(hdc, hbr));
        }

		//
		// 16 bit data is centred around 0x00
		//
        else if (wf.wBitsPerSample == 16) {

            // Left channel
            hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(LEFTBRUSH));
            y = rc.top + h/4;
            PatBlt(hdc, rc.left, y, w, 1, PATCOPY);

            for (x=0; x<w; x++) {
                i = *((HPINT)lpAudio + muldiv32(x,lLen,w) * 2);
                if (i > 0) {
                    i = y - (int) ((LONG)i * (h/4) / 32768);
                    PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
                	}
                else {
                    i = (int) ((LONG)i * (h/4) / 32768);
                    PatBlt(hdc, rc.left+x, y, 1, -i, PATCOPY);
                	}
            	}
            DeleteObject(SelectObject(hdc, hbr));

            // Right channel
            hbr = (HBRUSH)SelectObject(hdc, CreateSolidBrush(RIGHTBRUSH));
            y = rc.top + h * 3 / 4;
            PatBlt(hdc, rc.left, y, w, 1, PATCOPY);

            for (x=0; x<w; x++) {
                i = *((HPINT)lpAudio + muldiv32(x,lLen,w) * 2 + 1);
                if (i > 0) {
                	i = y - (int) ((LONG)i * (h/4) / 32768);
                	PatBlt(hdc, rc.left+x, i, 1, y-i, PATCOPY);
               	 	}
                else {
                	i = (int) ((LONG)i * (h/4) / 32768);
                	PatBlt(hdc, rc.left+x, y, 1, -i, PATCOPY);
                	}
            	}
            DeleteObject(SelectObject(hdc, hbr));
        	}
    	} // endif stereo

	if (lpAudio) {
		GlobalFreePtr(lpAudio);
    	lpAudio = NULL;
		}
#endif	// INTERIM_64_BIT
	}