void CBMPView::OnDraw(CDC* pDC) { Graphics graphicsDC(*pDC); // gdi+ 그리기를 위한 객체 CRect clientRect; GetClientRect(clientRect); Bitmap bmpCanvas(clientRect.right, clientRect.bottom); // 캔버스 비트맵 생성 Graphics graphicsCanvas(&bmpCanvas); // 캔버스 그래픽스 생성 graphicsCanvas.Clear(Color::Azure); // 캔버스 배경색 지정 CBMPDoc *pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: 여기에 그리기 코드를 추가합니다. Bitmap* pBitmap = pDoc->m_bitmap; UINT gapW = abs(clientRect.Width() - (int)pBitmap->GetWidth()); UINT gapH = abs(clientRect.Height() - (int)pBitmap->GetHeight()); UINT gap = gapW > gapH ? gapW : gapH; if (pBitmap) { graphicsCanvas.DrawImage(pBitmap, 0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); } graphicsDC.DrawImage(&bmpCanvas, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom); // 캔버스 그리기 }
void MarkerTool::createCircle() { using namespace Gdiplus; delete[] circleData_; circleData_ = 0; circleStride_ = 0; Bitmap * circle = new Bitmap(penSize_, penSize_, PixelFormat32bppARGB); Graphics gr2(circle); SolidBrush br(Color(255,255,0)); gr2.FillEllipse( &br, 0, 0, circle->GetWidth(), circle->GetHeight()); BitmapData circleData; Rect lc(0,0,circle->GetWidth(),circle->GetHeight()); if ( circle->LockBits(&lc, ImageLockModeRead, PixelFormat32bppARGB, & circleData) == Ok) { if (circleData.Stride > 0) { circleStride_ = circleData.Stride; } else { circleStride_ = - circleData.Stride; } size_t dataSize = circleStride_ * circle->GetHeight(); circleData_ = new uint8_t[dataSize]; memcpy(circleData_, circleData.Scan0, dataSize); circle->UnlockBits(&circleData); } delete circle; }
void GPCreateFlashFrame( Bitmap& bmpSrc, CRect& rcBegin, CRect& rcEnd, Bitmap& bmpDes, CRect& rcDes, double dPercent ) { int nWidth = bmpSrc.GetWidth(); int nHeight = bmpSrc.GetHeight(); double dPercent2 = 1.0 - dPercent; int nWidthDes = bmpDes.GetWidth(); int nHeightDes = bmpDes.GetHeight(); CRect rcBmpSrc(0,0, nWidth, nHeight); CRect rcBmpDes(0,0, nWidthDes, nHeightDes); ASSERT(IsInRect(rcBegin, rcBmpSrc)); ASSERT(IsInRect(rcEnd, rcBmpSrc)); ASSERT(IsInRect(rcDes, rcBmpDes)); ASSERT(rcBegin.Size() == rcEnd.Size()); ASSERT(rcEnd.Size() == rcDes.Size()); int nLoopWidth = rcBegin.Width(); int nLoopHeight = rcBegin.Height(); for (int i = 0; i <nLoopWidth; i++) { for (int j = 0; j < nLoopHeight; j++) { Color clrBegin; bmpSrc.GetPixel(i+ rcBegin.left, j+ rcBegin.top, &clrBegin); Color clrEnd; bmpSrc.GetPixel(i+ rcEnd.left, j+ rcEnd.top, &clrEnd); Color clrDes = Color::MakeARGB(clrBegin.GetA()*dPercent + clrEnd.GetA()* dPercent2, clrBegin.GetR()*dPercent + clrEnd.GetR()* dPercent2, clrBegin.GetG()*dPercent + clrEnd.GetG()* dPercent2, clrBegin.GetB()*dPercent + clrEnd.GetB()* dPercent2); bmpDes.SetPixel(rcDes.left + i, rcDes.top+j, clrDes); } } }
// RawSaveScreen: copy the current screen to a backup bitmap void RawSaveScreen () { if (raw_saved_screen != NULL) delete raw_saved_screen; Bitmap *source = thisroom.ebscene[play.bg_frame]; raw_saved_screen = BitmapHelper::CreateBitmap(source->GetWidth(), source->GetHeight()); raw_saved_screen->Blit(source, 0, 0, 0, 0, source->GetWidth(), source->GetHeight()); }
// OrGate 메시지 처리기입니다. void OrGate::Paint(CClientDC* dc) { /* CBitmap bitmap; bitmap.LoadBitmapW(IDB_OR); BITMAP bmpinfo; bitmap.GetBitmap(&bmpinfo); CDC dcmem; dcmem.CreateCompatibleDC(dc); dcmem.SelectObject(&bitmap); dc->BitBlt(point.x, point.y, bmpinfo.bmWidth, bmpinfo.bmHeight, &dcmem, 0, 0, SRCCOPY); */ /* GDI+ 구현 */ Graphics ScreenG(dc->GetSafeHdc()); Bitmap* pBitmapOR; pBitmapOR = Bitmap::FromResource(AfxGetInstanceHandle(), (WCHAR*)MAKEINTRESOURCE(IDB_OR)); ScreenG.DrawImage(pBitmapOR, Rect(point.x, point.y, pBitmapOR->GetWidth(), pBitmapOR->GetHeight()), 0, 0, pBitmapOR->GetWidth(), pBitmapOR->GetHeight(), UnitPixel); Width = pBitmapOR->GetWidth(); Height = pBitmapOR->GetHeight(); //연결 구현 if (UpWire == point.x + 3 && UpWire == point.y + 7 && DownWire == point.x + 3 && DownWire == point.y + 19) { // ORGate와 선 연결 성공 connect = TRUE; } }
void DrawBitmap(Bitmap &b, Rect& rect, int x, int y) { glPushMatrix(); glTranslatef((float)x,(float)y,0); ////enable textures and set up automatic texture coordinate generation glBindTexture(GL_TEXTURE_2D, b.GetTexture()); glEnable(GL_TEXTURE_2D); glColor4f(1.0f,1.0f,1.0f,1.0f); //Define how alpha blending will work and enable alpha blending. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); float tx1 = min(1.0f, (float)rect.X / (float)b.GetWidth()); float ty1 = min(1.0f, (float)rect.Y / (float)b.GetHeight()); float q = ((float)(rect.Width)/((float)b.GetWidth())); float tx2 = min(1.0f, tx1 + q); float f = (float)(rect.Height)/((float)b.GetHeight()); float ty2 = min(1.0f, (ty1 + f) ); glPolygonMode(GL_FRONT_AND_BACK, GL_POLYGON); glBegin(GL_QUADS); glTexCoord2f(tx1, 1-ty1); glVertex2f(0.0f, 0.0f); glTexCoord2f(tx1, 1-ty2); glVertex2f(0.0f, (float)rect.Height); glTexCoord2f(tx2, 1-ty2); glVertex2f((float)rect.Width, (float)rect.Height); glTexCoord2f(tx2, 1-ty1); glVertex2f((float)rect.Width, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); }
void show_preload () { // ** Do the preload graphic if available color temppal[256]; Bitmap *splashsc = BitmapHelper::CreateRawObjectOwner( load_pcx("preload.pcx",temppal) ); if (splashsc != NULL) { if (splashsc->GetColorDepth() == 8) wsetpalette(0,255,temppal); Bitmap *screen_bmp = BitmapHelper::GetScreenBitmap(); Bitmap *tsc = BitmapHelper::CreateBitmap(splashsc->GetWidth(),splashsc->GetHeight(),screen_bmp->GetColorDepth()); tsc->Blit(splashsc,0,0,0,0,tsc->GetWidth(),tsc->GetHeight()); screen_bmp->Clear(); screen_bmp->StretchBlt(tsc, RectWH(0, 0, scrnwid,scrnhit), Common::kBitmap_Transparency); gfxDriver->ClearDrawList(); if (!gfxDriver->UsesMemoryBackBuffer()) { IDriverDependantBitmap *ddb = gfxDriver->CreateDDBFromBitmap(screen_bmp, false, true); gfxDriver->DrawSprite(0, 0, ddb); render_to_screen(screen_bmp, 0, 0); gfxDriver->DestroyDDB(ddb); } else render_to_screen(screen_bmp, 0, 0); delete splashsc; delete tsc; platform->Delay(500); } }
// Run() void Run() { HDC backDC = backBuf.GetDC(); // 塗りつぶし RECT rc; rc.left = rc.top = 0; rc.right = backBuf.GetWidth(); rc.bottom = backBuf.GetHeight(); FillRect(backDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); // 図形描画 HPEN hPenOld, hPen; hPen = CreatePen(PS_SOLID, 0, RGB(0xff, 0, 0)); hPenOld = (HPEN)SelectObject(backDC, hPen); Vector2 r[4]; Vector2 trans(backBuf.GetWidth()>>1, backBuf.GetHeight()>>1); Matrix2 rot, sc; static int t = 0; t += 5; Matrix2Rotation(rot, t/180.0f*3.14); Matrix2Scaling(sc, 2, 2); for (int i = 0; i < 4; ++i) { r[i] = rect[i] * sc * rot; r[i] = r[i] + trans; } /*Vector3 r[4]; Vector3 trans(backBuf.GetWidth()>>1, backBuf.GetHeight()>>1, 0); Matrix3 rot, sc; static int t = 0; t += 5; Matrix3RotationHV(rot, t/180.0f*3.14); for (int i = 0; i < 4; ++i) { r[i].x = rect[i].x; r[i].y = rect[i].y; r[i] = r[i] * rot; r[i] = r[i] + trans; }*/ for (int i = 0; i < 4; ++i) { MoveToEx(backDC, r[i].x, r[i].y, NULL); LineTo(backDC, r[(i+1)&3].x, r[(i+1)&3].y); } SelectObject(backDC, hPenOld); DeleteObject(hPen); // フリップ HDC hDC = GetDC(wnd.GetHandle()); BitBlt(hDC, 0, 0, rc.right, rc.bottom, backDC, 0, 0, SRCCOPY); ReleaseDC(wnd.GetHandle(), hDC); Sleep(100); }
Texture::Texture(const Bitmap& bmp){ glGenTextures(1, &id); //glBindTexture(GL_TEXTURE_2D, id); Bind(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp.GetWidth(), bmp.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp.GetData()); this->width = bmp.GetWidth(); this->height = bmp.GetHeight(); cout << "Texture " << id << endl; }
static FtkBitmap* load_win32 (const char *filename) { int x = 0; int y = 0; int w = 0; int h = 0; FtkColor bg = {0}; FtkBitmap* bitmap = NULL; WCHAR wfilename[MAX_PATH] = {0}; mbstowcs(wfilename, filename, MAX_PATH); Bitmap* img = Bitmap::FromFile(wfilename); return_val_if_fail(img != NULL, NULL); if(img->GetWidth() == 0 || img->GetHeight() == 0) { delete img; return NULL; } w = img->GetWidth(); h = img->GetHeight(); bg.a = 0xff; bitmap = ftk_bitmap_create(w, h, bg); Rect r(0, 0, w, h); BitmapData bitmapData; #ifdef VC6 img->LockBits(r, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData); #else img->LockBits(&r, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData); #endif FtkColor* src = (FtkColor*)bitmapData.Scan0; FtkColor* dst = ftk_bitmap_bits(bitmap); for(y = 0; y < h; y++) { for(x = 0; x < w; x++) { *dst = *src; dst++; src++; } } img->UnlockBits(&bitmapData); delete img; return bitmap; }
bool CExampleDemoDlg::GetFaceRect(Bitmap* pImageSori) { //_sleep(100); Bitmap* pImageS = pImageSori->Clone(0, 0, pImageSori->GetWidth(), pImageSori->GetHeight(), PixelFormat32bppARGB); // TODO: 在此添加您专用的创建代码 float scalew = 1.; if (pImageS->GetWidth() > 480 || pImageS->GetHeight() > 640) { scalew=min(480.f / pImageS->GetWidth(), 640.f / pImageS->GetHeight()); int width = pImageS->GetWidth()*scalew; int height = pImageS->GetHeight()*scalew; ResizeBitmap(&pImageS, width, height); } Gdiplus::BitmapData TempBitmapData; Gdiplus::Rect rc(0, 0, pImageS->GetWidth(), pImageS->GetHeight()); pImageS->LockBits(&rc, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &TempBitmapData); CPupilGUI cpi = CPupilGUI((BYTE*)TempBitmapData.Scan0, TempBitmapData.Width, TempBitmapData.Height); pImageS->UnlockBits(&TempBitmapData); SAFE_DELETE(pImageS); if (cpi.isface == true) { int x0=cpi.m_face_detection.rFace.left; int y0 = cpi.m_face_detection.rFace.top; int width = (cpi.m_face_detection.rFace.right-x0)/scalew; int height = (cpi.m_face_detection.rFace.bottom-y0)/scalew; if (height+width<700) { return false; } else { return true; } //return GetRect(CRect(x0/scalew, y0/scalew, width/scalew, height/scalew), pImageSori); } else { return false; } }
void DrawingSurface_DrawSurface(ScriptDrawingSurface* target, ScriptDrawingSurface* source, int translev) { if ((translev < 0) || (translev > 99)) quit("!DrawingSurface.DrawSurface: invalid parameter (transparency must be 0-99)"); target->StartDrawing(); Bitmap *surfaceToDraw = source->GetBitmapSurface(); if (surfaceToDraw == abuf) quit("!DrawingSurface.DrawSurface: cannot draw surface onto itself"); if (translev == 0) { // just draw it over the top, no transparency abuf->Blit(surfaceToDraw, 0, 0, 0, 0, surfaceToDraw->GetWidth(), surfaceToDraw->GetHeight()); target->FinishedDrawing(); return; } if (surfaceToDraw->GetColorDepth() <= 8) quit("!DrawingSurface.DrawSurface: 256-colour surfaces cannot be drawn transparently"); // Draw it transparently trans_mode = ((100-translev) * 25) / 10; put_sprite_256(0, 0, surfaceToDraw); target->FinishedDrawing(); }
UINT CLkDuiButton::Create( const TCHAR* wnd_name, // 窗口名称 CLkDuiBase* pBefore, // 上一级子窗口 INT x, INT y, UINT uImageID, UINT nAvgelen) { UINT uRetID = 0; Bitmap* bmp = NULL; if (CLkDuiDC::ImageFromSource(bmp,NULL,uImageID,L"PNG")) { bef_size_.Width =bmp->GetWidth(); bef_size_.Height = bmp->GetHeight(); bef_Avgelen_ = nAvgelen; RECT rc = {x,y,x+bef_Avgelen_,y+bef_size_.Height}; UINT uRetID = CLkDuiBase::Create(wnd_name,pBefore,rc); RECT rcBef = {0,0,bef_size_.Width,bef_size_.Height}; dc_background_ = new CLkDuiDC(hWnd_,rc); dc_beforeground_ = new CLkDuiDC(hWnd_,rcBef); dc_background_->SetColor(bg_color_,TRUE); dc_beforeground_->SetImage(bmp,TRUE); delete bmp; } return uRetID; }
static RenderedBitmap *ThumbFromCoverPage(Doc doc) { ImageData *coverImage = doc.GetCoverImage(); if (!coverImage) return NULL; Bitmap *coverBmp = BitmapFromData(coverImage->data, coverImage->len); if (!coverBmp) return NULL; Bitmap res(THUMBNAIL_DX, THUMBNAIL_DY, PixelFormat24bppRGB); float scale = (float)THUMBNAIL_DX / (float)coverBmp->GetWidth(); int fromDy = THUMBNAIL_DY; if (scale < 1.f) fromDy = (int)((float)coverBmp->GetHeight() * scale); Graphics g(&res); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); g.DrawImage(coverBmp, Rect(0, 0, THUMBNAIL_DX, THUMBNAIL_DY), 0, 0, coverBmp->GetWidth(), fromDy, UnitPixel); HBITMAP hbmp; Status ok = res.GetHBITMAP(Color::White, &hbmp); delete coverBmp; if (ok == Ok) return new RenderedBitmap(hbmp, SizeI(THUMBNAIL_DX, THUMBNAIL_DY)); return NULL; }
static RenderedBitmap *ThumbFromCoverPage(Doc doc, SizeI size) { ImageData *coverImage = doc.GetCoverImage(); if (!coverImage) return nullptr; Bitmap *coverBmp = BitmapFromData(coverImage->data, coverImage->len); if (!coverBmp) return nullptr; Bitmap res(size.dx, size.dy, PixelFormat24bppRGB); float scale = (float)size.dx / (float)coverBmp->GetWidth(); int fromDy = size.dy; if (scale < 1.f) fromDy = (int)((float)coverBmp->GetHeight() * scale); Graphics g(&res); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); Status ok = g.DrawImage(coverBmp, Rect(0, 0, size.dx, size.dy), 0, 0, coverBmp->GetWidth(), fromDy, UnitPixel); if (ok != Ok) { delete coverBmp; return nullptr; } HBITMAP hbmp; ok = res.GetHBITMAP((ARGB)Color::White, &hbmp); delete coverBmp; if (ok == Ok) return new RenderedBitmap(hbmp, SizeI(size.dx, size.dy)); return nullptr; }
RenderedBitmap *LoadRenderedBitmap(const WCHAR *filePath) { if (str::EndsWithI(filePath, L".bmp")) { HBITMAP hbmp = (HBITMAP)LoadImage(NULL, filePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!hbmp) return NULL; return new RenderedBitmap(hbmp, GetBitmapSize(hbmp)); } size_t len; ScopedMem<char> data(file::ReadAll(filePath, &len)); if (!data) return NULL; Bitmap *bmp = BitmapFromData(data, len); if (!bmp) return NULL; HBITMAP hbmp; RenderedBitmap *rendered = NULL; if (bmp->GetHBITMAP(Color::White, &hbmp) == Ok) rendered = new RenderedBitmap(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight())); delete bmp; return rendered; }
/* ** Loads the image from disk ** */ void MeterImage::LoadImage(const std::wstring& imageName, bool bLoadAlways) { m_Image.LoadImage(imageName, bLoadAlways); if (m_Image.IsLoaded()) { // Calculate size of the meter Bitmap* bitmap = m_Image.GetImage(); int imageW = bitmap->GetWidth(); int imageH = bitmap->GetHeight(); if (m_WDefined) { if (!m_HDefined) { m_H = (imageW == 0) ? 0 : (m_DrawMode == DRAWMODE_TILE) ? imageH : m_W * imageH / imageW; } } else { if (m_HDefined) { m_W = (imageH == 0) ? 0 : (m_DrawMode == DRAWMODE_TILE) ? imageW : m_H * imageW / imageH; } else { m_W = imageW; m_H = imageH; } } } }
/* ** Load the image and get the dimensions of the meter from it. ** */ void CMeterBitmap::Initialize() { CMeter::Initialize(); // Load the bitmaps if defined if (!m_ImageName.empty()) { m_Image.LoadImage(m_ImageName, m_NeedsReload); if (m_Image.IsLoaded()) { Bitmap* bitmap = m_Image.GetImage(); m_W = bitmap->GetWidth(); m_H = bitmap->GetHeight(); if (m_H > m_W) { m_H = m_H / m_FrameCount; } else { m_W = m_W / m_FrameCount; } } } else if (m_Image.IsLoaded()) { m_Image.DisposeImage(); } }
void CBMPFrame::ActivateFrame(int nCmdShow) { // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다. CBMPDoc *pDoc = GetActiveDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; CRect winRect, cliRect; GetWindowRect(&winRect); GetClientRect(&cliRect); Bitmap *pBitmap = pDoc->m_bitmap; if (pBitmap) { m_InitW = pBitmap->GetWidth() + winRect.Width() - cliRect.Width() + 4; m_InitH = pBitmap->GetHeight() + winRect.Height() - cliRect.Height() + 4; SetWindowPos(NULL, 0, 0, m_InitW, m_InitH, SWP_NOMOVE | SWP_SHOWWINDOW); } OnIpEcsHighEnd(); OnIpEcsLowEnd(); CMDIChildWndEx::ActivateFrame(nCmdShow); }
//================================================================================= // GetPictureBuffer // // Overloaded version of the above //================================================================================= void PictureHandler::GetPictureBuffer( string& filename, UINT*& imgBuffer, int& width, int& height) { Bitmap* bmp = Bitmap::FromFile((Narrow2Wide(filename)).c_str()); BitmapData* bmpData = new BitmapData; height = bmp->GetHeight(); width = bmp->GetWidth(); long imgSize = height*width; Rect rect(0, 0, width, height); bmp->LockBits( &rect, ImageLockModeWrite, PixelFormat32bppARGB, bmpData); _ASSERT( bmpData->Stride/4 == width ); if( bmpData->Stride/4 != width ) return;//picture format may not be 24 bit jpg or bmp type imgBuffer = new UINT[imgSize]; memcpy( imgBuffer, (UINT*)bmpData->Scan0, imgSize*sizeof(UINT) ); bmp->UnlockBits(bmpData); }
//================================================================================= // GetPictureBuffer // // Returns a buffer of the picture just opened //================================================================================= void PictureHandler::GetPictureBuffer( string& filename, vector<UINT>& imgBuffer, int& width, int& height) { Bitmap* bmp = Bitmap::FromFile((Narrow2Wide(filename)).c_str()); BitmapData* bmpData = new BitmapData; height = bmp->GetHeight(); width = bmp->GetWidth(); long imgSize = height*width; Rect rect(0, 0, width, height); bmp->LockBits( &rect, ImageLockModeWrite, PixelFormat32bppARGB, bmpData); _ASSERT( bmpData->Stride/4 == width ); imgBuffer.resize(imgSize); //memcpy( imgBuffer, (UINT*)bmpData.get()->Scan0, imgSize*sizeof(UINT) ); UINT* tempBuff = (UINT*)bmpData->Scan0; for( int p = 0; p < imgSize; p++ ) imgBuffer[p] = tempBuff[p]; bmp->UnlockBits(bmpData); }
bool IrisBitmap::IrisBitmapStretchBlt(Rect *destRect, Bitmap* destBitmap, Rect *srcRect, Bitmap* srcBitmap, int opacity){ //safety check //if(srcBitmap->GetWidth() < UINT(srcRect->Width + srcRect->X) || srcBitmap->GetHeight() < UINT(srcRect->Height + srcRect->Y)) // return false; //if(destBitmap->GetWidth() < UINT(destRect->Width + destRect->X) || destBitmap->GetHeight() < UINT(destRect->Height + destRect->Y)) // return false; if(opacity > 255) opacity = 255; if(opacity < 0) opacity = 0; // 先获取截取位图 Bitmap *tpBitmap = new Bitmap(srcRect->Width, srcRect->Height, PixelFormat32bppARGB); IrisBitmapBitBlt(0, 0, tpBitmap, srcBitmap, srcRect, 255); // 再缩放之 Bitmap *scaleBitmap = ScaleBitmap(tpBitmap, destRect->Width, destRect->Height); // 复制过去 Rect *rect = new Rect(0, 0, scaleBitmap->GetWidth(), scaleBitmap->GetHeight()); bool r = IrisBitmapBitBlt(destRect->X, destRect->Y, destBitmap, scaleBitmap, rect, opacity); delete scaleBitmap; delete tpBitmap; delete rect; return r; }
ScriptDynamicSprite* DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height) { int gotSlot = spriteset.findFreeSlot(); if (gotSlot <= 0) return NULL; // use DrawingSurface resolution sds->MultiplyCoordinates(&x, &y); sds->MultiplyCoordinates(&width, &height); Bitmap *ds = sds->StartDrawing(); if ((x < 0) || (y < 0) || (x + width > ds->GetWidth()) || (y + height > ds->GetHeight())) quit("!DynamicSprite.CreateFromDrawingSurface: requested area is outside the surface"); int colDepth = ds->GetColorDepth(); Bitmap *newPic = BitmapHelper::CreateBitmap(width, height, colDepth); if (newPic == NULL) return NULL; newPic->Blit(ds, x, y, 0, 0, width, height); sds->FinishedDrawingReadOnly(); add_dynamic_sprite(gotSlot, newPic, (sds->hasAlphaChannel != 0)); ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot); return new_spr; }
void OpenBitmapFromFile( const WCHAR *pFilename, void **pBuffer, uint32_t *width, uint32_t *height) { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); Bitmap *bitmap = new Bitmap(pFilename); *width = bitmap->GetWidth(); *height = bitmap->GetHeight(); *pBuffer = new BYTE[*width * *height * 4]; // width * height * |RGBA| // The folder 'stb_image' contains a PNG open/close module which // is far less painful than this is, yo. Gdiplus::Color clr; for (uint32_t y = 0, idx = 0; y < *height; ++y) { for (uint32_t x = 0; x < *width; ++x, idx += 4) { bitmap->GetPixel(x, *height - y - 1, &clr); ((BYTE*)*pBuffer)[idx + 0] = clr.GetBlue(); ((BYTE*)*pBuffer)[idx + 1] = clr.GetGreen(); ((BYTE*)*pBuffer)[idx + 2] = clr.GetRed(); ((BYTE*)*pBuffer)[idx + 3] = clr.GetAlpha(); } } delete bitmap; bitmap = 0; }
// *************************************************************** // DrawOverlays() // *************************************************************** void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttributes& attr) { for (size_t i = 0; i < tile->Overlays.size(); i++) { Bitmap* bmp = tile->get_Bitmap(i)->m_bitmap; if (bmp) { // to debug the issue with occasional seams // DumpTile Status status; double ROUNDING_TOLERANCE = 0.1; double dx = abs(screenBounds.Width - bmp->GetWidth()); double dy = abs(screenBounds.Height - bmp->GetHeight()); if (dx < ROUNDING_TOLERANCE && dy < ROUNDING_TOLERANCE) { // TODO: better to check that all tiles have the same size and apply this rendering only then status = _graphics->DrawImage(bmp, Utility::Rint(screenBounds.X), Utility::Rint(screenBounds.Y)); } else { status = _graphics->DrawImage(bmp, screenBounds, 0.0f, 0.0f, (REAL)bmp->GetWidth(), (REAL)bmp->GetHeight(), UnitPixel, &attr); } if (status != Gdiplus::Status::Ok) { Debug::WriteLine("Failed to draw tile."); } } } }
void Canvas::StretchNot(const Bitmap &src) { assert(src.IsDefined()); #ifdef USE_GLSL OpenGL::invert_shader->Use(); #else const GLEnable scope(GL_TEXTURE_2D); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); /* invert the texture color */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); /* copy the texture alpha */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); #endif GLTexture &texture = *src.GetNative(); texture.Draw(0, 0, GetWidth(), GetHeight(), 0, 0, src.GetWidth(), src.GetHeight()); }
void DrawingSurface_DrawSurface(ScriptDrawingSurface* target, ScriptDrawingSurface* source, int translev) { if ((translev < 0) || (translev > 99)) quit("!DrawingSurface.DrawSurface: invalid parameter (transparency must be 0-99)"); Bitmap *ds = target->StartDrawing(); Bitmap *surfaceToDraw = source->GetBitmapSurface(); if (surfaceToDraw == target->GetBitmapSurface()) quit("!DrawingSurface.DrawSurface: cannot draw surface onto itself"); if (translev == 0) { // just draw it over the top, no transparency ds->Blit(surfaceToDraw, 0, 0, 0, 0, surfaceToDraw->GetWidth(), surfaceToDraw->GetHeight()); target->FinishedDrawing(); return; } if (surfaceToDraw->GetColorDepth() <= 8) quit("!DrawingSurface.DrawSurface: 256-colour surfaces cannot be drawn transparently"); // Draw it transparently GfxUtil::DrawSpriteWithTransparency(ds, surfaceToDraw, 0, 0, GfxDef::Trans100ToAlpha255(translev)); target->FinishedDrawing(); }
/* ** Draws the meter on the double buffer ** */ bool CMeterRotator::Draw(Graphics& graphics) { if (!CMeter::Draw(graphics)) return false; if (m_Image.IsLoaded()) { // Calculate the center for rotation int x = GetX(); int y = GetY(); REAL cx = (REAL)(x + m_W / 2.0); REAL cy = (REAL)(y + m_H / 2.0); // Calculate the rotation REAL angle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value + m_StartAngle)); graphics.TranslateTransform(cx, cy); graphics.RotateTransform(angle); graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY); Bitmap* drawBitmap = m_Image.GetImage(); UINT width = drawBitmap->GetWidth(); UINT height = drawBitmap->GetHeight(); // Blit the image graphics.DrawImage(drawBitmap, 0, 0, width, height); graphics.ResetTransform(); } return true; }
// cf. http://stackoverflow.com/questions/4598872/creating-hbitmap-from-memory-buffer/4616394#4616394 Bitmap *BitmapFromData(const char *data, size_t len) { ImgFormat format = GfxFormatFromData(data, len); if (Img_TGA == format) return tga::ImageFromData(data, len); if (Img_WebP == format) return webp::ImageFromData(data, len); if (Img_JP2 == format) return fitz::ImageFromData(data, len); if (Img_JPEG == format && JpegUsesArithmeticCoding(data, len)) return fitz::ImageFromData(data, len); ScopedComPtr<IStream> stream(CreateStreamFromData(data, len)); if (!stream) return NULL; if (Img_JXR == format) return WICDecodeImageFromStream(stream); Bitmap *bmp = Bitmap::FromStream(stream); if (bmp && bmp->GetLastStatus() != Ok) { delete bmp; bmp = NULL; } // GDI+ under Windows XP sometimes fails to extract JPEG image dimensions if (bmp && Img_JPEG == format && (0 == bmp->GetWidth() || 0 == bmp->GetHeight())) { delete bmp; bmp = fitz::ImageFromData(data, len); } return bmp; }
// cf. http://stackoverflow.com/questions/4598872/creating-hbitmap-from-memory-buffer/4616394#4616394 Bitmap *BitmapFromData(const char *data, size_t len) { ImgFormat format = GfxFormatFromData(data, len); if (Img_TGA == format) return tga::ImageFromData(data, len); ScopedComPtr<IStream> stream(CreateStreamFromData(data, len)); if (!stream) return NULL; if (Img_JXR == format) return WICDecodeImageFromStream(stream); Bitmap *bmp = Bitmap::FromStream(stream); if (bmp && bmp->GetLastStatus() != Ok) { delete bmp; bmp = NULL; } // GDI+ under Windows XP sometimes fails to extract JPEG image dimensions if (bmp && Img_JPEG == format && 0 == bmp->GetWidth() && 0 == bmp->GetHeight()) { delete bmp; LARGE_INTEGER zero = { 0 }; stream->Seek(zero, STREAM_SEEK_SET, NULL); bmp = WICDecodeImageFromStream(stream); } return bmp; }