void CSVGGradientEditCtl::PaintGradient(HDC hDC) { int patx = 4; int paty = 4; int xc, yc; int col, row; xc = 0; col = 0; int width = m_previewRect.Width(); int height = m_previewRect.Height()-17-10; BITMAPINFO bmi = {0}; bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biPlanes = 1; int rowbytes = ROWBYTES(width, 24); LPBYTE bits = (LPBYTE)GlobalAlloc(0, rowbytes * height); for (int x = 0; x < width; x++) { int index = x; if (m_colorSpread[index].alpha == 255) { for (int y = 0; y < height; y++) { RGBTRIPLE* rgbdest = (RGBTRIPLE*)(bits + rowbytes*(height-y-1) + x*3); rgbdest->rgbtRed = m_colorSpread[index].red; rgbdest->rgbtGreen = m_colorSpread[index].green; rgbdest->rgbtBlue = m_colorSpread[index].blue; } } else { yc = 0; row = 0; for (int y = 0; y < height; y++) { RGBTRIPLE* rgbdest = (RGBTRIPLE*)(bits + rowbytes*(height-y-1) + x*3); RGBTRIPLE rgb; rgb.rgbtRed = m_colorSpread[index].red; rgb.rgbtGreen = m_colorSpread[index].green; rgb.rgbtBlue = m_colorSpread[index].blue; if ((col+row) & 1) { rgbdest->rgbtRed = 255; rgbdest->rgbtGreen = 255; rgbdest->rgbtBlue = 255; } else { rgbdest->rgbtRed = 200; rgbdest->rgbtGreen = 200; rgbdest->rgbtBlue = 200; } ::SetMedianPixel(rgbdest, &rgb, 255-m_colorSpread[index].alpha); if (++yc == paty) { yc = 0; row++; } } } if (++xc == patx) { xc = 0; col++; } } SetDIBitsToDevice(hDC, m_previewRect.left, m_previewRect.top, width, height, 0, 0, 0, height, bits, &bmi, DIB_RGB_COLORS); GlobalFree(bits); }
ErrorCode_Bool CVideoFilter::CInputPin::Receive(MediaShow::IMediaSample *pSample) { CriticalSectionLock lock(m_pLock); #if 0 /* while (1) { EnterCriticalSection(&m_pFilter->m_pLock); if (m_pFilter->m_state == LState_Running) break; LeaveCriticalSection(&m_pFilter->m_pLock); } LeaveCriticalSection(&m_pFilter->m_pLock); */ // MessageBeep(-1); LONGLONG timeStart; LONGLONG timeEnd; pSample->GetTime(&timeStart, &timeEnd); // Wait until it's time to display the sample HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_pFilter->m_clock->AdviseTime(m_pFilter->m_tStart/*baseTime*/, timeStart/*streamTime*/, hEvent, NULL); WaitForSingleObject(hEvent, INFINITE); CloseHandle(hEvent); ASSERT(m_pSample == NULL); m_pSample = static_cast<CVideoSample*>(pSample); // m_pSample->AddRef(); // Create an event and wait for it be set by another thread to process m_pSample m_hReceivedEvent = CreateEvent(NULL, FALSE, FALSE, NULL); WaitForSingleObject(m_hReceivedEvent, INFINITE); CloseHandle(m_hReceivedEvent); m_hReceivedEvent = NULL; // m_pSample has been processed, we can delete it DeleteObject(m_pSample->m_hBitmap); delete m_pSample;//->Release(); m_pSample = NULL; #if 0 LVIDEOINFOHEADER2* vih = (LVIDEOINFOHEADER2*)m_mt->pbFormat; int width = vih->bmiHeader.biWidth; int height = vih->bmiHeader.biHeight; BYTE* p = new BYTE[m_pFilter->m_pTexture->m_texwidth*m_pFilter->m_pTexture->m_texheight*3]; for (int y = 0; y < height; y++) { BYTE* dest = p + m_pFilter->m_pTexture->m_texwidth*3*y; BYTE* src = m_pSample->m_bits + ROWBYTES(width, 24)*y; for (int x = 0; x < width; x++) { *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; } } glBindTexture(GL_TEXTURE_2D, m_pFilter->m_pTexture->m_texName); ASSERT(glGetError() == GL_NO_ERROR); glTexSubImage2D(GL_TEXTURE_2D, 0, // level (0=base image) 0, // xoffset 0, // yoffset, m_pFilter->m_pTexture->m_texwidth, m_pFilter->m_pTexture->m_texheight, GL_RGB, GL_UNSIGNED_BYTE, p); if (glGetError() != GL_NO_ERROR) { TRACE("glTexSubImage2D() failed\n"); } delete p; #if 0 m_pFilter->m_pMoviePlayer->m_cwnd.PostMessage(WM_USER+100, 0, 0); #endif #endif #endif return Success_True; }
HRESULT CColorSpectrum::OnDraw(ATL_DRAWINFO& di) { CRect& rc = *(CRect*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_bEnabled) { #define ROWBYTES(width,bitcount) ((((width)*(bitcount)+31) >> 3) & 0xfffc) int width = rc.Width()-20; int height = rc.Height(); FillSolidRect(hDC, rc.left+width, rc.top, 20, height/2, RGB(255, 255, 255)); FillSolidRect(hDC, rc.left+width, rc.top+height/2, 20, rc.Height()-height/2, RGB(0, 0, 0)); int bytesPerRow = ROWBYTES(width, 24); BITMAPINFOHEADER bmi; ZeroMemory(&bmi, sizeof(bmi)); bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = width; bmi.biHeight = height; bmi.biPlanes = 1; bmi.biBitCount = 24; bmi.biCompression = BI_RGB; bmi.biSizeImage = bytesPerRow*height; LPBYTE bits = (LPBYTE)GlobalAlloc(0, bmi.biSizeImage); if (bits) { for (int y = 0; y < height; y++) { RGBTRIPLE* dest = (RGBTRIPLE*)(bits + (height-y-1)*bytesPerRow); for (int x = 0; x < width; x++) { int h = (x * 255)/width; int l = ((height-y-1) * 255)/height; int s = ((height-y-1) * 255)/height; //int s = 127;//(x * width)/255; COLORREF clr = HLStoRGB(HLS(h, l, s)); dest->rgbtRed = GetRValue(clr); dest->rgbtGreen = GetGValue(clr); dest->rgbtBlue = GetBValue(clr); dest++; } } SetDIBitsToDevice(hDC, rc.left, rc.top, width, height, 0, 0, 0, height, bits, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS); GlobalFree(bits); } } return S_OK; }