void D3DSDevice::SetFramebufferInfo( D3DSScreen Screen, u32 frameid ) { if (D3DS_SCREEN_TOP==Screen) { m_FBInfoTop.active_framebuf = frameid; m_FBInfoTop.framebuf0_vaddr = (u32*) m_FBTop[ frameid ]; if (m_b3DEnabled) m_FBInfoTop.framebuf1_vaddr = (u32*) m_FBTop[ 2+frameid ]; else m_FBInfoTop.framebuf1_vaddr = (u32*) m_FBTop[ frameid ]; m_FBInfoTop.framebuf_widthbytesize = 240 * GetBytesPerPixel(m_FBFormatBottom); u8 enabled3d = m_b3DEnabled; m_FBInfoTop.format = ((1)<<8) | ((1^enabled3d)<<6) | ((enabled3d)<<5) | m_FBFormatTop; m_FBInfoTop.framebuf_dispselect = frameid; m_FBInfoTop.unk = 0x00000000; } else { m_FBInfoBottom.active_framebuf = frameid; m_FBInfoBottom.framebuf0_vaddr = (u32*) m_FBBottom[ frameid ]; m_FBInfoBottom.framebuf1_vaddr = 0x00000000; m_FBInfoBottom.framebuf_widthbytesize = 240 * GetBytesPerPixel(m_FBFormatBottom); m_FBInfoBottom.format = m_FBFormatBottom; m_FBInfoBottom.framebuf_dispselect = frameid; m_FBInfoBottom.unk = 0x00000000; } }
HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, UINT32 SrcFormat, BYTE* data) { UINT32 nSrcStep; UINT32 nDstStep; BYTE* pSrcData; BYTE* pDstData; HGDI_BITMAP bitmap; if (!gdi) return NULL; nDstStep = nWidth * GetBytesPerPixel(gdi->dstFormat); pDstData = _aligned_malloc(nHeight * nDstStep, 16); if (!pDstData) return NULL; pSrcData = data; nSrcStep = nWidth * GetBytesPerPixel(SrcFormat); if (!freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0, nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, &gdi->palette, FREERDP_FLIP_NONE)) { _aligned_free(pDstData); return NULL; } bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstFormat, pDstData); return bitmap; }
HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeight) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); if (!hBitmap) return NULL; hBitmap->objectType = GDIOBJECT_BITMAP; hBitmap->format = hdc->format; hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = _aligned_malloc(nWidth * nHeight * GetBytesPerPixel( hBitmap->format), 16); hBitmap->free = _aligned_free; if (!hBitmap->data) { free(hBitmap); return NULL; } hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format); return hBitmap; }
virtual int BuildFrame(OniFrame* pFrame) { update(); pFrame->frameIndex = m_frameId; pFrame->videoMode.pixelFormat = ONI_PIXEL_FORMAT_DEPTH_1_MM; pFrame->videoMode.resolutionX = DEPTH_WIDTH; pFrame->videoMode.resolutionY = DEPTH_HEIGHT; pFrame->videoMode.fps = 30; pFrame->width = DEPTH_WIDTH; pFrame->height = DEPTH_HEIGHT; auto count = bufferSize_ * GetBytesPerPixel(); if ( pFrame->data != 0 && depthBuffer_.size() != 0 && pFrame->dataSize == count ) { fprintf( stderr, "update()%d, %d, %d, %d\n", pFrame->data, &depthBuffer_[0], pFrame->dataSize, count ); xnOSMemCopy( pFrame->data, &depthBuffer_[0], count ); } pFrame->cropOriginX = pFrame->cropOriginY = 0; pFrame->croppingEnabled = FALSE; pFrame->sensorType = ONI_SENSOR_DEPTH; pFrame->stride = DEPTH_WIDTH * GetBytesPerPixel(); pFrame->timestamp = m_frameId*33000; ++m_frameId; return 1; }
void D3DSDevice::FlushBuffers() { u32 bytes_top = 400 * 240 * GetBytesPerPixel( m_FBFormatTop ); u32 bytes_btm = 320 * 240 * GetBytesPerPixel( m_FBFormatBottom ); GSPGPU_FlushDataCache( GetFramebufferPtr(D3DS_FRAMEBUFFER_TOP_LEFT,nullptr,nullptr), bytes_top ); if (m_b3DEnabled) GSPGPU_FlushDataCache( GetFramebufferPtr(D3DS_FRAMEBUFFER_TOP_RIGHT,nullptr,nullptr), bytes_top ); GSPGPU_FlushDataCache( GetFramebufferPtr(D3DS_FRAMEBUFFER_BOTTOM,nullptr,nullptr), bytes_btm ); }
static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, const BYTE* pSrcData, UINT32 DstWidth, UINT32 DstHeight, UINT32 bpp, UINT32 length, BOOL compressed, UINT32 codecId) { UINT32 SrcSize = length; UINT32 SrcFormat; UINT32 bytesPerPixel; rdpGdi* gdi = context->gdi; bitmap->compressed = FALSE; bitmap->format = gdi->dstFormat; bitmap->length = DstWidth * DstHeight * GetBytesPerPixel(bitmap->format); bytesPerPixel = GetBytesPerPixel(bpp); bitmap->data = (BYTE*) _aligned_malloc(bitmap->length, 16); if (!bitmap->data) return FALSE; if (compressed) { if (bpp < 32) { if (!interleaved_decompress(context->codecs->interleaved, pSrcData, SrcSize, DstWidth, DstHeight, bpp, bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, &gdi->palette)) return FALSE; } else { if (!planar_decompress(context->codecs->planar, pSrcData, SrcSize, DstWidth, DstHeight, bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, TRUE)) return FALSE; } } else { SrcFormat = gdi_get_pixel_format(bpp); if (!freerdp_image_copy(bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, pSrcData, SrcFormat, 0, 0, 0, &gdi->palette, FREERDP_FLIP_VERTICAL)) return FALSE; } return TRUE; }
int GetBytesPerRow(int width, int depth) { int bytesPerPixel = GetBytesPerPixel(depth); int bytesPerRow = ((width * bytesPerPixel + 3) & ~3); return bytesPerRow; }
void GenericBuffer::CopyFrom(vk::CommandBuffer commandBuffer, Texture& srcTexture) { auto textureSize = srcTexture.GetWidth() * srcTexture.GetHeight() * GetBytesPerPixel(srcTexture.GetFormat()); if (textureSize != mSize) { throw std::runtime_error("Cannot copy texture of different sizes"); } srcTexture.Barrier(commandBuffer, vk::ImageLayout::eGeneral, vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eColorAttachmentWrite, vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits::eTransferRead); auto info = vk::BufferImageCopy() .setImageSubresource({vk::ImageAspectFlagBits::eColor, 0, 0, 1}) .setImageExtent({srcTexture.GetWidth(), srcTexture.GetHeight(), 1}); commandBuffer.copyImageToBuffer( srcTexture.mImage, vk::ImageLayout::eTransferSrcOptimal, mBuffer, info); srcTexture.Barrier(commandBuffer, vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits::eTransferRead, vk::ImageLayout::eGeneral, vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eColorAttachmentRead); Barrier(commandBuffer, vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eShaderRead); }
INLINE UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos) { HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject; BYTE* data = &(hBmp->data[(nYPos * hBmp->scanline) + nXPos * GetBytesPerPixel( hBmp->format)]); return ReadColor(data, hBmp->format); }
void BitmapTexture::AssignBitmap( bool generateTexture, const unsigned char* pixels ) { DALI_LOG_TRACE_METHOD(Debug::Filter::gImage); DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::Verbose, "BitmapTexture::AssignBitmap()\n"); GLenum pixelFormat = GL_RGBA; GLenum pixelDataType = GL_UNSIGNED_BYTE; if( generateTexture ) { mContext.GenTextures(1, &mId); } DALI_ASSERT_DEBUG( mId != 0 ); mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time mContext.Bind2dTexture(mId); Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat); mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data mContext.TexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, pixels); mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); INCREASE_BY( PerformanceMonitor::TEXTURE_DATA_UPLOADED, GetBytesPerPixel(mPixelFormat) * mWidth * mHeight ); }
EFI_STATUS LcdSetMode ( IN UINT32 ModeNumber ) { EFI_STATUS Status; UINT32 HRes; UINT32 HSync; UINT32 HBackPorch; UINT32 HFrontPorch; UINT32 VRes; UINT32 VSync; UINT32 VBackPorch; UINT32 VFrontPorch; UINT32 BytesPerPixel; LCD_BPP LcdBpp; // Set the video mode timings and other relevant information Status = LcdPlatformGetTimings (ModeNumber, &HRes,&HSync,&HBackPorch,&HFrontPorch, &VRes,&VSync,&VBackPorch,&VFrontPorch); ASSERT_EFI_ERROR (Status); if (EFI_ERROR( Status )) { return EFI_DEVICE_ERROR; } Status = LcdPlatformGetBpp (ModeNumber,&LcdBpp); ASSERT_EFI_ERROR (Status); if (EFI_ERROR( Status )) { return EFI_DEVICE_ERROR; } BytesPerPixel = GetBytesPerPixel(LcdBpp); // Disable the controller MmioWrite32(HDLCD_REG_COMMAND, HDLCD_DISABLE); // Update the frame buffer information with the new settings MmioWrite32(HDLCD_REG_FB_LINE_LENGTH, HRes * BytesPerPixel); MmioWrite32(HDLCD_REG_FB_LINE_PITCH, HRes * BytesPerPixel); MmioWrite32(HDLCD_REG_FB_LINE_COUNT, VRes - 1); // Set the vertical timing information MmioWrite32(HDLCD_REG_V_SYNC, VSync); MmioWrite32(HDLCD_REG_V_BACK_PORCH, VBackPorch); MmioWrite32(HDLCD_REG_V_DATA, VRes - 1); MmioWrite32(HDLCD_REG_V_FRONT_PORCH, VFrontPorch); // Set the horizontal timing information MmioWrite32(HDLCD_REG_H_SYNC, HSync); MmioWrite32(HDLCD_REG_H_BACK_PORCH, HBackPorch); MmioWrite32(HDLCD_REG_H_DATA, HRes - 1); MmioWrite32(HDLCD_REG_H_FRONT_PORCH, HFrontPorch); // Enable the controller MmioWrite32(HDLCD_REG_COMMAND, HDLCD_ENABLE); return EFI_SUCCESS; }
static INLINE UINT32 gdi_SetPixelBmp(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y, UINT32 crColor) { BYTE* p = &hBmp->data[(Y * hBmp->scanline) + X * GetBytesPerPixel( hBmp->format)]; WriteColor(p, hBmp->format, crColor); return crColor; }
HRESULT TestPattern::CreateFrame(IDeckLinkVideoFrame** frame, void (*fillFunc)(IDeckLinkVideoFrame*)) { HRESULT result; int bytesPerPixel = GetBytesPerPixel(m_config->m_pixelFormat); IDeckLinkMutableVideoFrame* newFrame = NULL; IDeckLinkMutableVideoFrame* referenceFrame = NULL; IDeckLinkVideoConversion* frameConverter = NULL; *frame = NULL; result = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * bytesPerPixel, m_config->m_pixelFormat, bmdFrameFlagDefault, &newFrame); if (result != S_OK) { fprintf(stderr, "Failed to create video frame\n"); goto bail; } if (m_config->m_pixelFormat == bmdFormat8BitYUV) { fillFunc(newFrame); } else { // Create a black frame in 8 bit YUV and convert to desired format result = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 2, bmdFormat8BitYUV, bmdFrameFlagDefault, &referenceFrame); if (result != S_OK) { fprintf(stderr, "Failed to create reference video frame\n"); goto bail; } fillFunc(referenceFrame); frameConverter = CreateVideoConversionInstance(); result = frameConverter->ConvertFrame(referenceFrame, newFrame); if (result != S_OK) { fprintf(stderr, "Failed to convert frame\n"); goto bail; } } *frame = newFrame; newFrame = NULL; bail: if (referenceFrame != NULL) referenceFrame->Release(); if (frameConverter != NULL) frameConverter->Release(); if (newFrame != NULL) newFrame->Release(); return result; }
std::size_t Image::GetDataPtrOffset(const Offset3D& offset) const { const auto bpp = static_cast<std::size_t>(GetBytesPerPixel()); const auto x = static_cast<std::size_t>(offset.x); const auto y = static_cast<std::size_t>(offset.y); const auto z = static_cast<std::size_t>(offset.z); const auto w = static_cast<std::size_t>(GetExtent().width); const auto h = static_cast<std::size_t>(GetExtent().height); return (bpp * (x + (y + z * h) * w)); }
XnStatus XnPixelStream::CropImpl(OniFrame* pFrame, const OniCropping* pCropping) { XnUChar* pPixelData = (XnUChar*)pFrame->data; XnUInt32 nCurDataSize = 0; for (XnUInt32 y = pCropping->originY; y < XnUInt32(pCropping->originY + pCropping->height); ++y) { XnUChar* pOrigLine = &pPixelData[y * GetXRes() * GetBytesPerPixel()]; // move line xnOSMemCopy(pPixelData + nCurDataSize, pOrigLine + pCropping->originX * GetBytesPerPixel(), pCropping->width * GetBytesPerPixel()); nCurDataSize += pCropping->width * GetBytesPerPixel(); } // update size pFrame->dataSize = nCurDataSize; return XN_STATUS_OK; }
static int freerdp_image_copy_from_retina(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc) { BYTE* pSrcPixel; BYTE* pDstPixel; int x, y; int nSrcPad; int nDstPad; int srcBitsPerPixel; int srcBytesPerPixel; int dstBitsPerPixel; int dstBytesPerPixel; srcBitsPerPixel = 24; srcBytesPerPixel = 8; if (nSrcStep < 0) nSrcStep = srcBytesPerPixel * nWidth; dstBitsPerPixel = GetBitsPerPixel(DstFormat); dstBytesPerPixel = GetBytesPerPixel(DstFormat); if (nDstStep < 0) nDstStep = dstBytesPerPixel * nWidth; nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; for (y = 0; y < nHeight; y++) { for (x = 0; x < nWidth; x++) { UINT32 R, G, B; UINT32 color; /* simple box filter scaling, could be improved with better algorithm */ B = pSrcPixel[0] + pSrcPixel[4] + pSrcPixel[nSrcStep + 0] + pSrcPixel[nSrcStep + 4]; G = pSrcPixel[1] + pSrcPixel[5] + pSrcPixel[nSrcStep + 1] + pSrcPixel[nSrcStep + 5]; R = pSrcPixel[2] + pSrcPixel[6] + pSrcPixel[nSrcStep + 2] + pSrcPixel[nSrcStep + 6]; pSrcPixel += 8; color = GetColor(DstFormat, R >> 2, G >> 2, B >> 2, 0xFF); WriteColor(pDstPixel, DstFormat, color); pDstPixel += dstBytesPerPixel; } pSrcPixel = &pSrcPixel[nSrcPad + nSrcStep]; pDstPixel = &pDstPixel[nDstPad]; } return 1; }
XnStatus XnSensorIRStream::CalcRequiredSize(XnUInt32* pnRequiredSize) const { // in IR, in all resolutions except SXGA, we get additional 8 lines XnUInt32 nYRes = GetYRes(); if (GetResolution() != XN_RESOLUTION_SXGA) { nYRes += 8; } *pnRequiredSize = GetXRes() * nYRes * GetBytesPerPixel(); return XN_STATUS_OK; }
/* Pointer Class */ static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) { #ifdef WITH_XCURSOR UINT32 CursorFormat; rdpGdi* gdi; size_t size; XcursorImage ci; xfContext* xfc = (xfContext*) context; xfPointer* xpointer = (xfPointer*)pointer; if (!context || !pointer || !context->gdi) return FALSE; if (!xfc->invert) CursorFormat = PIXEL_FORMAT_RGBA32; else CursorFormat = PIXEL_FORMAT_BGRA32; gdi = context->gdi; xf_lock_x11(xfc, FALSE); ZeroMemory(&ci, sizeof(ci)); ci.version = XCURSOR_IMAGE_VERSION; ci.size = sizeof(ci); ci.width = pointer->width; ci.height = pointer->height; ci.xhot = pointer->xPos; ci.yhot = pointer->yPos; size = ci.height * ci.width * GetBytesPerPixel(CursorFormat); if (!(ci.pixels = (XcursorPixel*) _aligned_malloc(size, 16))) { xf_unlock_x11(xfc, FALSE); return FALSE; } if (!freerdp_image_copy_from_pointer_data( (BYTE*) ci.pixels, CursorFormat, 0, 0, 0, pointer->width, pointer->height, pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData, pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette)) { _aligned_free(ci.pixels); xf_unlock_x11(xfc, FALSE); return FALSE; } xpointer->cursor = XcursorImageLoadCursor(xfc->display, &ci); _aligned_free(ci.pixels); xf_unlock_x11(xfc, FALSE); #endif return TRUE; }
XnStatus XnPixelStream::CropImpl(XnStreamData* pStreamOutput, const XnCropping* pCropping) { XnStatus nRetVal = XN_STATUS_OK; XnUChar* pPixelData = (XnUChar*)pStreamOutput->pData; XnUInt32 nCurDataSize = 0; for (XnUInt32 y = pCropping->nYOffset; y < XnUInt32(pCropping->nYOffset + pCropping->nYSize); ++y) { XnUChar* pOrigLine = &pPixelData[y * GetXRes() * GetBytesPerPixel()]; // move line xnOSMemCopy(pPixelData + nCurDataSize, pOrigLine + pCropping->nXOffset * GetBytesPerPixel(), pCropping->nXSize * GetBytesPerPixel()); nCurDataSize += pCropping->nXSize * GetBytesPerPixel(); } // update size pStreamOutput->nDataSize = nCurDataSize; return XN_STATUS_OK; }
// Bitmap buffer has been changed. Upload changes to GPU. void BitmapTexture::AreaUpdated( const RectArea& updateArea, const unsigned char* pixels ) { DALI_LOG_TRACE_METHOD(Debug::Filter::gImage); DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::Verbose, "BitmapTexture::AreaUpdated()\n"); GLenum pixelFormat = GL_RGBA; GLenum pixelDataType = GL_UNSIGNED_BYTE; Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat); mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time mContext.Bind2dTexture(mId); if( ! updateArea.IsEmpty() ) { mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "Update x:%d y:%d w:%d h:%d\n", updateArea.x, updateArea.y, updateArea.width ,updateArea.height ); // TODO: obtain pitch of source image, obtain pixel depth of source image. const unsigned int pitchPixels = mImageWidth; const unsigned int pixelDepth = sizeof(unsigned int); // If the width of the source update area is the same as the pitch, then can // copy the contents in a single contiguous TexSubImage call. if(updateArea.x == 0 && updateArea.width == pitchPixels) { pixels += updateArea.y * pitchPixels * pixelDepth; mContext.TexSubImage2D( GL_TEXTURE_2D,0, updateArea.x, updateArea.y, updateArea.width, updateArea.height, pixelFormat, pixelDataType, pixels ); } else { // Otherwise the source buffer needs to be copied line at a time, as OpenGL ES // does not support source strides. (no GL_UNPACK_ROW_LENGTH supported) unsigned int yBottom = updateArea.y + updateArea.height; pixels += (updateArea.y * pitchPixels + updateArea.x) * pixelDepth; for(unsigned int y = updateArea.y; y < yBottom; y++) { mContext.TexSubImage2D( GL_TEXTURE_2D,0, updateArea.x, y, updateArea.width, 1, pixelFormat, pixelDataType, pixels ); pixels += pitchPixels * pixelDepth; } } INCREASE_BY( PerformanceMonitor::TEXTURE_DATA_UPLOADED, updateArea.Area()* GetBytesPerPixel( mPixelFormat )); } }
static BOOL wl_end_paint(rdpContext* context) { rdpGdi* gdi; char* data; wlfContext* context_w; INT32 x, y; UINT32 w, h; int i; gdi = context->gdi; if (gdi->primary->hdc->hwnd->invalid->null) return TRUE; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; context_w = (wlfContext*) context; data = UwacWindowGetDrawingBuffer(context_w->window); if (!data) return FALSE; for (i = 0; i < h; i++) { memcpy(data + ((i + y) * (gdi->width * GetBytesPerPixel( gdi->dstFormat))) + x * GetBytesPerPixel(gdi->dstFormat), gdi->primary_buffer + ((i + y) * (gdi->width * GetBytesPerPixel( gdi->dstFormat))) + x * GetBytesPerPixel(gdi->dstFormat), w * GetBytesPerPixel(gdi->dstFormat)); } if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS) return FALSE; context_w->haveDamage = TRUE; return wl_update_content(context_w); }
SignalGenerator3DVideoFrame* CSignalGeneratorDlg::CreateBlackFrame () { IDeckLinkMutableVideoFrame* referenceBlack = NULL; IDeckLinkMutableVideoFrame* scheduleBlack = NULL; HRESULT hr; BMDPixelFormat pixelFormat; int bytesPerPixel; IDeckLinkVideoConversion* frameConverter = NULL; SignalGenerator3DVideoFrame* ret = NULL; pixelFormat = (BMDPixelFormat)m_pixelFormatCombo.GetItemData(m_pixelFormatCombo.GetCurSel()); bytesPerPixel = GetBytesPerPixel(pixelFormat); hr = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*bytesPerPixel, pixelFormat, bmdFrameFlagDefault, &scheduleBlack); if (hr != S_OK) goto bail; if (pixelFormat == bmdFormat8BitYUV) { FillBlack(scheduleBlack); } else { hr = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &referenceBlack); if (hr != S_OK) goto bail; FillBlack(referenceBlack); hr = CoCreateInstance(CLSID_CDeckLinkVideoConversion, NULL, CLSCTX_ALL, IID_IDeckLinkVideoConversion, (void**)&frameConverter); if (hr != S_OK) goto bail; hr = frameConverter->ConvertFrame(referenceBlack, scheduleBlack); if (hr != S_OK) goto bail; } ret = new SignalGenerator3DVideoFrame(scheduleBlack); bail: if (referenceBlack) referenceBlack->Release(); if (scheduleBlack) scheduleBlack->Release(); if (frameConverter) frameConverter->Release(); return ret; }
//////////////////////////////////////////////////////////// /// Copie les pixels de la texture sur une surface verrouillée /// /// \param LockedRect : Structure contenant les infos de verrouillage /// \param Rect : Rectangle source à copier /// //////////////////////////////////////////////////////////// void DX9Texture::UpdateSurface(const D3DLOCKED_RECT& LockedRect, const CRectangle& Rect) { // Récupération d'un pointeur sur les pixels source et destination unsigned char* DestPix = reinterpret_cast<unsigned char*>(LockedRect.pBits); const unsigned char* SrcPix = m_Data.GetData() + (Rect.Left() + Rect.Top() * m_Size.x) * GetBytesPerPixel(m_Data.GetFormat()); // Copie des pixels sur la surface unsigned int Bpp = GetBytesPerPixel(m_Data.GetFormat()); for (int i = 0; i < Rect.Height(); ++i) { std::copy(SrcPix, SrcPix + Rect.Width() * Bpp, DestPix); SrcPix += m_Size.x * Bpp; DestPix += LockedRect.Pitch; } }
XnUInt32 MockMapGenerator::GetExpectedBufferSize() { XnUInt32 nPixels = 0; if (m_cropping.bEnabled) { nPixels = m_cropping.nXSize * m_cropping.nYSize; } else { nPixels = m_mapOutputMode.nXRes * m_mapOutputMode.nYRes; } XnUInt32 nBytes = nPixels * GetBytesPerPixel(); return nBytes; }
void Image::ReadPixels(const Offset3D& offset, const Extent3D& extent, const DstImageDescriptor& imageDesc, std::size_t threadCount) const { if (imageDesc.data && IsRegionInside(offset, extent)) { /* Validate required size */ ValidateImageDataSize(extent, imageDesc); /* Get source image parameters */ const auto bpp = GetBytesPerPixel(); const auto srcRowStride = bpp * GetExtent().width; const auto srcDepthStride = srcRowStride * GetExtent().height; auto src = data_.get() + GetDataPtrOffset(offset); if (GetFormat() == imageDesc.format && GetDataType() == imageDesc.dataType) { /* Get destination image parameters */ const auto dstRowStride = bpp * extent.width; const auto dstDepthStride = dstRowStride * extent.height; auto dst = reinterpret_cast<char*>(imageDesc.data); /* Blit region into destination image */ BitBlit( extent, bpp, dst, dstRowStride, dstDepthStride, src, srcRowStride, srcDepthStride ); } else { /* Copy region into temporary sub-image */ Image subImage { extent, GetFormat(), GetDataType() }; BitBlit( extent, bpp, reinterpret_cast<char*>(subImage.GetData()), subImage.GetRowStride(), subImage.GetDepthStride(), src, srcRowStride, srcDepthStride ); /* Convert sub-image */ subImage.Convert(imageDesc.format, imageDesc.dataType, threadCount); /* Copy sub-image into output data */ ::memcpy(imageDesc.data, subImage.GetData(), imageDesc.dataSize); } } }
void ImageAccessor::AssignWritable(PixelFormat format, unsigned int width, unsigned int height, unsigned int pitch, void *buffer) { readOnly_ = false; format_ = format; width_ = width; height_ = height; pitch_ = pitch; buffer_ = reinterpret_cast<uint8_t*>(buffer); if (GetBytesPerPixel() * width_ > pitch_) { throw OrthancException(ErrorCode_ParameterOutOfRange); } }
void Image::Blit(Offset3D dstRegionOffset, const Image& srcImage, Offset3D srcRegionOffset, Extent3D srcRegionExtent) { if (GetFormat() == srcImage.GetFormat() && GetDataType() == srcImage.GetDataType()) { /* First clamp source region to source image dimension */ srcImage.ClampRegion(srcRegionOffset, srcRegionExtent); /* Then shift negative destination region */ if ( ShiftNegative1DRegion(dstRegionOffset.x, GetExtent().width, srcRegionOffset.x, srcRegionExtent.width ) && ShiftNegative1DRegion(dstRegionOffset.y, GetExtent().height, srcRegionOffset.y, srcRegionExtent.height) && ShiftNegative1DRegion(dstRegionOffset.z, GetExtent().depth, srcRegionOffset.z, srcRegionExtent.depth ) ) { /* Check if a temporary copy of the source image must be allocated */ Image srcImageTemp; const Image* srcImageRef = &srcImage; if (srcImageRef == this && Overlap3DRegion(dstRegionOffset, srcRegionOffset, srcRegionExtent)) { /* Copy source image */ srcImageTemp = *this; srcImageRef = &srcImageTemp; } /* Get destination image parameters */ const auto bpp = GetBytesPerPixel(); const auto dstRowStride = bpp * GetExtent().width; const auto dstDepthStride = dstRowStride * GetExtent().height; auto dst = data_.get() + GetDataPtrOffset(dstRegionOffset); /* Get source image parameters */ const auto srcRowStride = bpp * srcImageRef->GetExtent().width; const auto srcDepthStride = srcRowStride * srcImageRef->GetExtent().height; auto src = srcImageRef->data_.get() + srcImageRef->GetDataPtrOffset(srcRegionOffset); /* Blit source image into region */ BitBlit( srcRegionExtent, bpp, dst, dstRowStride, dstDepthStride, src, srcRowStride, srcDepthStride ); } } }
/* class Texture */ std::shared_ptr<Texture> Texture::Create( int width, int height, ColorFormat format, void* pExternalMemory ) { // Cannot use std::make_shared<>() by the protected access modifier. auto texture = std::shared_ptr<Texture>( new Texture() ); texture->m_width = width; texture->m_height = height; texture->m_format = format; texture->m_flags = 0; if ( pExternalMemory ) { texture->SetExternalMemory( pExternalMemory ); } else { texture->m_pMemory = malloc( width * height * GetBytesPerPixel( format ) ); } return texture; }
HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format, UINT32 stride, BYTE* data, void (*fkt_free)(void*)) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); if (!hBitmap) return NULL; hBitmap->objectType = GDIOBJECT_BITMAP; hBitmap->format = format; if (stride > 0) hBitmap->scanline = stride; else hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format); hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = data; hBitmap->free = fkt_free; return hBitmap; }
bool Texture::WriteTexel( int x, int y, byte r, byte g, byte b ) { if ( !HasFlag( FL_LOCKED ) ) { return false; } Assert( ( x >= 0 && x < m_width ) && "out of ranged x-coordinate" ); Assert( ( y >= 0 && y < m_height ) && "out of ranged y-coordinate" ); int stride = GetBytesPerPixel( Format() ); if ( byte* buffer = static_cast< byte* >( m_pMemory ) ) { byte* base = buffer + ( ( ( m_width * y ) + x ) * stride ); *( base + 0 ) = r; *( base + 1 ) = g; *( base + 2 ) = b; //*( base + 3 ) = a; } return true; }