MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ddgr_gdi_surf_Create

Function ddgr_gdi_surf_Create

dd_grwin32/ddgrWin32GDI.cpp:367–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365// Creates a GDI DIBitmap
366
367bool ddgr_gdi_surf_Create(ddgr_surface *sf) {
368 tGDISurface *bm;
369
370 // set up bitmap header
371 int nw = sf->w;
372 if (nw % 4)
373 nw = ((sf->w / 4) * 4) + 4;
374
375 bm = new tGDISurface;
376
377 if (sf->bpp == BPP_8) {
378 tDIBHeader8 header;
379
380 header.bmi.biSize = sizeof(BITMAPINFOHEADER);
381 header.bmi.biWidth = nw;
382 header.bmi.biHeight = -sf->h; // Always a top down bitmap!!
383 header.bmi.biPlanes = 1;
384 header.bmi.biBitCount = sf->bpp;
385 header.bmi.biCompression = BI_BITFIELDS;
386 header.bmi.biSizeImage = 0;
387 header.bmi.biXPelsPerMeter = 0;
388 header.bmi.biYPelsPerMeter = 0;
389 header.bmi.biClrUsed = 0;
390 header.bmi.biClrImportant = 0;
391
392 bm->hbm = CreateDIBSection(GDI_DATA(hOffscreenDC), (BITMAPINFO *)&header, DIB_RGB_COLORS, &bm->data, NULL, 0);
393 } else {
394 tDIBHeader header;
395 header.bmi.biSize = sizeof(BITMAPINFOHEADER);
396 header.bmi.biWidth = nw;
397 header.bmi.biHeight = -sf->h; // Always a top down bitmap!!
398 header.bmi.biPlanes = 1;
399 header.bmi.biBitCount = sf->bpp;
400 header.bmi.biCompression = BI_BITFIELDS;
401 header.bmi.biSizeImage = 0;
402 header.bmi.biXPelsPerMeter = 0;
403 header.bmi.biYPelsPerMeter = 0;
404 header.bmi.biClrUsed = 0;
405 header.bmi.biClrImportant = 0;
406
407 // setup RGB bit masks
408 if (sf->bpp == BPP_16) {
409 header.red_mask = 0x7c00;
410 header.green_mask = 0x03e0;
411 header.blue_mask = 0x001f;
412 bm->rowsize = nw * 2;
413 } else if (sf->bpp == BPP_32 || sf->bpp == BPP_24) {
414 header.red_mask = 0x00ff0000;
415 header.green_mask = 0x0000ff00;
416 header.blue_mask = 0x000000ff;
417 bm->rowsize = nw * 4;
418 }
419
420 bm->hbm = CreateDIBSection(GDI_DATA(hOffscreenDC), (BITMAPINFO *)&header, DIB_RGB_COLORS, &bm->data, NULL, 0);
421 }
422
423 if (!bm->hbm) {
424 ddgr_PushError("CreateDIBSection failed.");

Callers 2

ddgr_gdi_surf_InitVideoFunction · 0.85
ddgr_surf_CreateFunction · 0.85

Calls 1

ddgr_PushErrorFunction · 0.85

Tested by

no test coverage detected