DWORD CDirect2DRMDevice::GetColor(BYTE r, BYTE g, BYTE b) { HRESULT hr; if (m_pddsBackBuffer == NULL) return E_NOTINITIALIZED; // REVIEW: this function is heavy weight when the device is palettized DWORD nBPP = m_ddsd.ddpfPixelFormat.dwRGBBitCount; if (nBPP <= 8) { // palettized PALETTEENTRY rgpe[nMAXPALETTEENTRIES]; LPDIRECTDRAWPALETTE pddp = NULL; if (FAILED(hr = m_pddsBackBuffer->GetPalette(&pddp)) || FAILED(hr = pddp->GetEntries(0, 0, nMAXPALETTEENTRIES, rgpe))) { MMRELEASE(pddp); return hr; } MMRELEASE(pddp); return SimpleFindClosestIndex(rgpe, 1 << nBPP, r, g, b); } else { // RGB return m_pixi.Pack(r, g, b); } return 0; }
int PisteDraw_Paletti_Pyorita(UCHAR eka_vari, UCHAR vika_vari) { UCHAR i; if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n"); return PD_VIRHE; } PALETTEENTRY temp_vari; temp_vari.peRed = PD_paletti_nyt[vika_vari].peRed; temp_vari.peGreen = PD_paletti_nyt[vika_vari].peGreen; temp_vari.peBlue = PD_paletti_nyt[vika_vari].peBlue; for (i=vika_vari;i>eka_vari;i--) { PD_paletti_nyt[i].peRed = PD_paletti_nyt[i-1].peRed; PD_paletti_nyt[i].peGreen = PD_paletti_nyt[i-1].peGreen; PD_paletti_nyt[i].peBlue = PD_paletti_nyt[i-1].peBlue; } PD_paletti_nyt[eka_vari].peRed = temp_vari.peRed; PD_paletti_nyt[eka_vari].peGreen = temp_vari.peGreen; PD_paletti_nyt[eka_vari].peBlue = temp_vari.peBlue; if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n"); return PD_VIRHE; } return 0; }
int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // this is called after the game is exited and the main event // loop while is exited, do all you cleanup and shutdown here // kill all the surfaces // first the palette if (lpddpal) { lpddpal->Release(); lpddpal = NULL; } // end if // now the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // now blow away the IDirectDraw4 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // return success or failure or your own return code here return(1); } // end Game_Shutdown
int DD_Shutdown(void) { // this function release all the resources directdraw // allocated, mainly to com objects // release the clipper first if (lpddclipper) lpddclipper->Release(); // release the palette if (lpddpal) lpddpal->Release(); // release the secondary surface if (lpddsback) lpddsback->Release(); // release the primary surface if (lpddsprimary) lpddsprimary->Release(); // finally, the main dd object if (lpdd) lpdd->Release(); // return success return(1); } // end DD_Shutdown
int PisteDraw_Paletti_Set(void) { if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette set failed!\n"); return PD_VIRHE; } return 0; }
//----------------------------------------------------------------------------- // Name: CleanupGraphics() // Desc: //----------------------------------------------------------------------------- VOID CleanupGraphics() { for( DWORD i=0; i<4; i++ ) if( g_pddsShip[i] ) g_pddsShip[i]->Release(); if( g_pddsNumbers ) g_pddsNumbers->Release(); if( g_pddsFrontBuffer ) g_pddsFrontBuffer->Release(); if( g_pArtPalette ) g_pArtPalette->Release(); if( g_pSplashPalette ) g_pSplashPalette->Release(); if( !g_bFullscreen && g_pddsBackBuffer ) g_pddsBackBuffer->Release(); if( g_pDD ) g_pDD->Release(); }
int PisteDraw_Paletti_Get(PALETTEENTRY *&paletti) { if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette get failed!\n"); return PD_VIRHE; } paletti = (PALETTEENTRY *)PD_paletti_nyt; return 0; }
void ReloadPrimarySurfacePaletteEntries() { if (!primary_surface_palette_ref) return; HRESULT err; ddrawPaletteSetEntries.Unhook(); if (FAILED(err = primary_surface_palette_ref->SetEntries(0, 0, numEntries, entries))) { logOutput << CurrentTimeString() << "ReloadPrimarySurfacePaletteEntries(): could not set entires" << endl; printDDrawError(err); } ddrawPaletteSetEntries.Rehook(); }
int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // this is called after the game is exited and the main event // loop while is exited, do all you cleanup and shutdown here // first the palette if (lpddpal) { lpddpal->Release(); lpddpal = NULL; } // end if // now the lpddsbackground surface if (lpddsbackground) { lpddsbackground->Release(); lpddsbackground = NULL; } // end if // now the lpddsback surface if (lpddsback) { lpddsback->Release(); lpddsback = NULL; } // end if // now the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // now blow away the IDirectDraw4 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // unload the bitmap file, we no longer need it Unload_Bitmap_File(&bitmap); // return success or failure or your own return code here return(1); } // end Game_Shutdown
int PisteDraw_Fade_Paletti_Do(int pros) { UCHAR i; if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n"); return PD_VIRHE; } for (i=0;i<255;i++) { PD_paletti_nyt[i].peRed = (PD_paletti[i].peRed * pros / 100); PD_paletti_nyt[i].peGreen = (PD_paletti[i].peGreen * pros / 100); PD_paletti_nyt[i].peBlue = (PD_paletti[i].peBlue * pros / 100); } if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) { PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n"); return PD_VIRHE; } return 0; }
int Set_Palette_Entry(int index, int red, int blue, int green) { PALETTEENTRY colour; colour.peRed = (BYTE)red; colour.peGreen = (BYTE)green; colour.peBlue = (BYTE)blue; colour.peFlags = PC_NOCOLLAPSE; lpddpal->SetEntries(0,index,1,&colour); memcpy(&colour_palette[index], &colour, sizeof(PALETTEENTRY)); return 1; }
HRESULT STDMETHODCALLTYPE SetPalette(LPDIRECTDRAWSURFACE7 surface, LPDIRECTDRAWPALETTE lpDDPalette) { //logOutput << CurrentTimeString() << "Hooked SetPalette()" << endl; ddrawSurfaceSetPalette.Unhook(); HRESULT hr = surface->SetPalette(lpDDPalette); ddrawSurfaceSetPalette.Rehook(); if (getFrontSurface(surface)) { if (lpDDPalette) lpDDPalette->AddRef(); SetupPalette(lpDDPalette); } return hr; }
static void screen_updatepalette(void) { HRESULT ret; int idx; if (!lpDDPal) return; //log("screen_updatepalette\n"); // for (idx = 1; idx < 17; idx ++) // DD_RGBTOPAL(idx, win_rgbmap[idx]); /* ret = lpDDPal->SetEntries(0, 0, 17, pals+rand()%16); if (ret != DD_OK) error(_("videoupdatepalette: SetPalette failed (%d)\n"), ret);*/ for (idx = 0; idx < 17; idx ++) DD_RGBTOPAL(idx, win_rgbmap[idx]); ret = lpDDPal->SetEntries(0, 0, 17, pals); if (ret != DD_OK) module_logger(&win32DirectDrawVideo, _L|LOG_ERROR|LOG_USER, _("videoupdatepalette: SetPalette failed (%d)\n"), ret); }
HRESULT STDMETHODCALLTYPE PaletteSetEntries(LPDIRECTDRAWPALETTE palette, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) { //logOutput << CurrentTimeString() << "Hooked SetEntries()" << endl; ddrawPaletteSetEntries.Unhook(); HRESULT hr = palette->SetEntries(dwFlags, dwStartingEntry, dwCount, lpEntries); ddrawPaletteSetEntries.Rehook(); // update buffer palette if (SUCCEEDED(hr)) { if (g_CurrentPalette.bInitialized) { memcpy(g_CurrentPalette.entries + dwStartingEntry, lpEntries, 4 * dwCount); // each entry is 4 bytes if DDCAPS_8BITENTRIES flag is not set } } return hr; }
int PisteDraw_Lopeta() { if (!PD_unload) { int i; for (i=0; i<MAX_FONTTEJA; i++) { if (PD_fontit[i] != NULL ) delete PD_fontit[i]; PD_fontit[i] = NULL; } for (i=2;i<MAX_BUFFEREITA;i++) // 0 ja 1 on varattu taustapuskureille PisteDraw_Buffer_Tuhoa(i); if (PD_lpddpal) { PD_lpddpal->Release(); } PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER); PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER2); if (PD_lpddsprimary) { PD_lpddsprimary->Release(); } if (PD_lpdd) { PD_lpdd->Release(); } PD_unload = true; } return 0; }
static void win_SetFullScreenMode(void) { HRESULT ret; // log("win_SetFullScreenMode\n"); if (lpDD) { /* get exclusive mode (for fullscreen and memory locking access) */ ret = lpDD->SetCooperativeLevel(hWndScreen, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_ALLOWMODEX); if (ret != DD_OK) DDFAIL(_("SetCooperativeLevel failed (%d)\n"), ret); /* Set our video mode */ ret = lpDD->SetDisplayMode(fsx, fsy, 8, 0, DDSDM_STANDARDVGAMODE); if (ret != DD_OK) DDFAIL(_("SetDisplayMode\n"), ret); /* Use our palette */ if (lpDDPal) { ret = lpDDPal->SetEntries(0 /*flags */, 0, 256, pals); if (ret != DD_OK) DDFAIL(_("SetEntries failed (%d)\n"), ret); } #warning fix this later // adjust rect for text mode! screenrect.left = 0; screenrect.top = 0; screenrect.right = 256; screenrect.bottom = 192; } }
int Game_Init(void *parms = NULL, int num_parms = 0) { // this is called once after the initial window is created and // before the main event loop is entered, do all your initialization // here // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL))) return(0); // set cooperation to full screen if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) return(0); // set display mode to 640x480x8 if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0))) return(0); // we need a complex surface system with a primary and backbuffer // clear ddsd and set size DDRAW_INIT_STRUCT(ddsd); // enable valid fields ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // set the backbuffer count field to 1, use 2 for triple buffering ddsd.dwBackBufferCount = 1; // request a complex, flippable ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; // create the primary surface if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) return(0); // now query for attached surface from the primary surface // this line is needed by the call ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; // get the attached back buffer surface if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback))) return(0); // build up the palette data array for (int color=1; color < 255; color++) { // fill with random RGB values palette[color].peRed = rand()%256; palette[color].peGreen = rand()%256; palette[color].peBlue = rand()%256; // set flags field to PC_NOCOLLAPSE palette[color].peFlags = PC_NOCOLLAPSE; } // end for color // now fill in entry 0 and 255 with black and white palette[0].peRed = 0; palette[0].peGreen = 0; palette[0].peBlue = 0; palette[0].peFlags = PC_NOCOLLAPSE; palette[255].peRed = 255; palette[255].peGreen = 255; palette[255].peBlue = 255; palette[255].peFlags = PC_NOCOLLAPSE; // create the palette object if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, palette,&lpddpal, NULL))) return(0); // finally attach the palette to the primary surface if (FAILED(lpddsprimary->SetPalette(lpddpal))) return(0); // set clipper up on back buffer since that's where well clip RECT screen_rect= {0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1}; lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect); // load the 8-bit image if (!Load_Bitmap_File(&bitmap,"alley8.bmp")) return(0); // load it's palette into directdraw if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette))) return(0); // clean the surfaces DDraw_Fill_Surface(lpddsprimary,0); DDraw_Fill_Surface(lpddsback,0); // create the buffer to hold the background lpddsbackground = DDraw_Create_Surface(640,480,0,-1); // copy the background bitmap image to the background surface // lock the surface lpddsbackground->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); // get video pointer to primary surfce UCHAR *image_buffer = (UCHAR *)ddsd.lpSurface; // test if memory is linear if (ddsd.lPitch == SCREEN_WIDTH) { // copy memory from double buffer to primary buffer memcpy((void *)image_buffer, (void *)bitmap.buffer, SCREEN_WIDTH*SCREEN_HEIGHT); } // end if else { // non-linear // make copy of source and destination addresses UCHAR *dest_ptr = image_buffer; UCHAR *src_ptr = bitmap.buffer; // memory is non-linear, copy line by line for (int y=0; y < SCREEN_HEIGHT; y++) { // copy line memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH); // advance pointers to next line dest_ptr+=ddsd.lPitch; src_ptr +=SCREEN_WIDTH; } // end for } // end else // now unlock the primary surface if (FAILED(lpddsbackground->Unlock(NULL))) return(0); // unload the bitmap file, we no longer need it Unload_Bitmap_File(&bitmap); // seed random number generator srand(GetTickCount()); // initialize all the aliens (in real life do this in a loop or function) // alien on level 1 of complex aliens[0].x = rand()%SCREEN_WIDTH; aliens[0].y = 116 - 72; aliens[0].velocity = 2+rand()%4; aliens[0].current_frame = 0; aliens[0].counter = 0; aliens[0].width = 72; // set real size aliens[0].height = 80; aliens[0].scale = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0 // fix up feet so they still contact floor aliens[0].y+=(72 - aliens[0].scale*72); // alien on level 2 of complex aliens[1].x = rand()%SCREEN_WIDTH; aliens[1].y = 246 - 72; aliens[1].velocity = 2+rand()%4; aliens[1].current_frame = 0; aliens[1].counter = 0; aliens[1].width = 72; // set real size aliens[1].height = 80; aliens[1].scale = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0 // fix up feet so they still contact floor aliens[1].y+=(72 - aliens[1].scale*72); // alien on level 3 of complex aliens[2].x = rand()%SCREEN_WIDTH; aliens[2].y = 382 - 72; aliens[2].velocity = 2+rand()%4; aliens[2].current_frame = 0; aliens[2].counter = 0; aliens[2].width = 72; // set real size aliens[2].height = 80; aliens[2].scale = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0 // fix up feet so they still contact floor aliens[2].y+=(72 - aliens[2].scale*72); // now load the bitmap containing the alien imagery // then scan the images out into the surfaces of alien[0] // and copy then into the other two, be careful of reference counts! // load the 8-bit image if (!Load_Bitmap_File(&bitmap,"dedsp0.bmp")) return(0); // create each surface and load bits for (int index = 0; index < 3; index++) { // create surface to hold image aliens[0].frames[index] = DDraw_Create_Surface(72,80,0); // now load bits... Scan_Image_Bitmap(&bitmap, // bitmap file to scan image data from aliens[0].frames[index], // surface to hold data index, 0); // cell to scan image from } // end for index // unload the bitmap file, we no longer need it Unload_Bitmap_File(&bitmap); // now for the tricky part. There is no need to create more surfaces with the same // data, so I'm going to copy the surface pointers member for member to each alien // however, be careful, since the reference counts do NOT go up, you still only need // to release() each surface once! for (index = 0; index < 3; index++) aliens[1].frames[index] = aliens[2].frames[index] = aliens[0].frames[index]; // return success or failure or your own return code here return(1); } // end Game_Init
/******************************************************************** * Function : WindowProc() * Purpose : Receive and handle windows messages. ********************************************************************/ long FAR PASCAL WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; switch (message) { case WM_ACTIVATEAPP : ActiveApp = wParam; break; case WM_CREATE : break; case WM_KEYDOWN : switch (wParam) { case VK_PAUSE : /* Start or Stop realtime. */ RealTime = !RealTime; break; case VK_SPACE : /* Flip a single frame. */ SimLoop(); break; case VK_ESCAPE : DestroyWindow(hwnd); break; case VK_LEFT : bLeftKey = TRUE; break; case VK_RIGHT : bRightKey = TRUE; break; case VK_UP : bForwardKey = TRUE; break; case VK_DOWN : bBackKey = TRUE; break; case VK_ADD : nGauge++; break; case VK_SUBTRACT : nGauge--; break; case VK_HOME : nGauge = 0; break; } break; case WM_KEYUP : switch (wParam) { case VK_F1 : nState = 1; break; case VK_F2 : nState = 2; break; case VK_F3 : nState = 3; break; case VK_F4 : nState = 4; break; case VK_F5 : nState = 5; break; case VK_F6 : nState = 6; break; case VK_F7 : nState = 7; break; case VK_F8 : nState = 8; break; case VK_F9 : nState = 9; break; case VK_F10 : nState = 0; break; case VK_LEFT : bLeftKey = FALSE; break; case VK_RIGHT : bRightKey = FALSE; break; case VK_UP : bForwardKey = FALSE; break; case VK_DOWN : bBackKey = FALSE; break; case 'S' : // Screen Snapshot. // This is not done very reliably, infact, it's more of a hack so // I can show some Chrome snapshots on my website. // Open a file named "Snapshot.tga" and write the current content // of the screen as a targa file. HANDLE hFile; hFile = CreateFile("Snapshot.tga", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != NULL) { // Write the Targa header, as appropriate for the current // screen type. DWORD dwWritten; /* Targa File Header : (Little Endian / Intel) * Offset Length Description * 0 1 ID field length * 1 1 Color map type. * 2 1 Image type. * 3 2 First color map entry. * 5 2 Color map length. * 7 1 Color map entry size. * 8 2 Image X origin. * 10 2 Image Y Origin. * 12 2 Image Width. * 14 2 Image Height. * 16 1 Bits per pixel. * 17 1 Image descriptor bits. * (from : "Graphics File Formats", David C. Kay and John R. Levine) */ # define OutB(b)\ { unsigned char b2;\ b2 = b;\ WriteFile(hFile, &b2, sizeof(b2), &dwWritten, NULL);\ } # define OutW(w)\ { unsigned short w2;\ w2 = w;\ WriteFile(hFile, &w2, sizeof(w2), &dwWritten, NULL);\ } OutB(0); // No message ID field length. OutB(0); // Colormap type = 0; true color. OutB(2); // Image type = 2, True color, uncompressed. OutW(0); // First colormap entry is 0, (Because Cmap type = 0). OutW(0); // Colormap length = 0, (CMap type = 0). OutB(0); // CMap entry size is 0 (because CMap type = 0) OutW(0); // OriginX = 0; OutW(0); // OriginY = 0; OutW(XRES); // Image Width is the value of the XRES constant. OutW(YRES); // Image Height is the value of the YRES constant. OutB(24); // Bits per pixel. OutB(0x20); // Image Descriptor Bits (0x20 = left to right, top to bottom). // Each pixel is written as a Blue Green Red triple. // Lock the surface & write each byte. DDSURFACEDESC ddsd; memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { //DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; for (nY = 0; nY < YRES; nY++) { for (nX = 0; nX < XRES; nX++) { unsigned char ucByte; ucByte = *(((unsigned char *)ddsd.lpSurface) + ddsd.lPitch * nY + nX); // Index the colormap & write the BGR triple. OutB(WinColormap[ucByte].peBlue); OutB(WinColormap[ucByte].peGreen); OutB(WinColormap[ucByte].peRed); } } lpBackbuffer->Unlock(NULL); } // Close the file, we're done... CloseHandle(hFile); } } break; case WM_DESTROY : if (lpDirectDrawObject != NULL) { if (lpBackbuffer != NULL) lpBackbuffer->Release(); if (lpPrimary != NULL) lpPrimary->Release(); if (lpPalette != NULL) lpPalette->Release(); lpDirectDrawObject->Release(); } /* Free the world. */ EndWorld(); /* Free the font. */ if (AppFont != NULL) DeleteObject(AppFont); ShowCursor(TRUE); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0L; }
int PisteDraw_Lataa_Kuva(int index, char *filename, bool lataa_paletti) { BITMAP_FILE bitmap; bool ok = false; char paate[4]; for (int i=0;i<4;i++) paate[i] = toupper(filename[strlen(filename)-3+i]); paate[4] = '\0'; if (strcmp(paate,"BMP")==0) { ok = true; if (PD_buffers[index].lpdds) { if (PisteDraw_Load_Bitmap(&bitmap, filename) != 0) { strcpy(virhe,"Could not load picture "); strcat(virhe,filename); strcat(virhe,"!"); PisteLog_Kirjoita("[Error] Piste Draw: "); PisteLog_Kirjoita(virhe); PisteLog_Kirjoita("\n"); return PD_VIRHE; } DD_INIT_STRUCT(PD_ddsd); if (FAILED(PD_buffers[index].lpdds->Lock(NULL,&PD_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL))) { strcpy(virhe,"Could not lock surface after loading a picture!"); PisteLog_Kirjoita("[Error] Piste Draw: Could not lock surface after loading a picture! \n"); return PD_VIRHE; } UCHAR *back_buffer = (UCHAR *)PD_ddsd.lpSurface; int x; int y; int leveys, korkeus; if (bitmap.bitmapinfoheader.biWidth > PD_buffers[index].leveys) leveys = PD_buffers[index].leveys; else leveys = bitmap.bitmapinfoheader.biWidth; if (bitmap.bitmapinfoheader.biHeight > PD_buffers[index].korkeus) korkeus = PD_buffers[index].korkeus; else korkeus = bitmap.bitmapinfoheader.biHeight; for (y=0; y<korkeus; y++) { for (x=0; x<leveys; x++) { back_buffer[x+y*PD_ddsd.lPitch] = bitmap.buffer[x+y*bitmap.bitmapinfoheader.biWidth]; } } if (FAILED(PD_buffers[index].lpdds->Unlock(NULL))) { strcpy(virhe,"Could not unlock surface after loading a picture!"); PisteLog_Kirjoita("[Error] Piste Draw: Could not unlock surface after loading a picture! \n"); return PD_VIRHE; } PisteDraw_Unload_Bitmap_File(&bitmap); if (lataa_paletti) { if (FAILED(PD_lpddpal->SetEntries(0,0,PD_max_varit, bitmap.paletti))) { strcpy(virhe,"Could not set palette after loading a picture!"); PisteLog_Kirjoita("[Error] Piste Draw: Could not set palette after loading a picture! \n"); return PD_VIRHE; } for (int pi=0;pi<256;pi++) { PD_paletti[pi].peBlue = bitmap.paletti[pi].peBlue; PD_paletti[pi].peRed = bitmap.paletti[pi].peRed; PD_paletti[pi].peGreen = bitmap.paletti[pi].peGreen; PD_paletti[pi].peFlags = bitmap.paletti[pi].peFlags; } } } else return PD_VIRHE; } if (strcmp(paate,"PCX")==0) { ok = true; if (PisteDraw_Lataa_PCX(filename, index, lataa_paletti) == PD_VIRHE) { strcpy(virhe,"Could not load picture "); strcat(virhe,filename); strcat(virhe,"!"); PisteLog_Kirjoita("[Error] Piste Draw: "); PisteLog_Kirjoita(virhe); PisteLog_Kirjoita("\n"); return PD_VIRHE; } } if (!ok) { strcpy(virhe,"Could not load bitmap file of type "); strcat(virhe,paate); return PD_VIRHE; } return 0; }
bool SetupPalette(LPDIRECTDRAWPALETTE lpDDPalette) { if (!lpDDPalette) { //logOutput << CurrentTimeString() << "Detaching palette" << endl; g_CurrentPalette.Free(); g_bUsePalette = false; return false; } logOutput << CurrentTimeString() << "initializing palette" << endl; DWORD caps; HRESULT hr; if (FAILED(hr = lpDDPalette->GetCaps(&caps))) { logOutput << CurrentTimeString() << "Failed to get palette caps" << endl; printDDrawError(hr, "SetupPalette"); return false; } if (caps & DDPCAPS_8BITENTRIES) { logOutput << CurrentTimeString() << "8-bit index-palette used (lookup color is an index to another lookup table), not implemented" << endl; return false; } DWORD numEntries = 0; if (caps & DDPCAPS_8BIT) numEntries = 0x100; else if (caps & DDPCAPS_4BIT) numEntries = 0x10; else if (caps & DDPCAPS_2BIT) numEntries = 0x04; else if (caps & DDPCAPS_1BIT) numEntries = 0x02; else { logOutput << CurrentTimeString() << "Unrecognized palette format" << endl; return false; } //logOutput << CurrentTimeString() << "Trying to retrieve " << numEntries << " palette entries" << endl; g_CurrentPalette.Reallocate(numEntries); hr = lpDDPalette->GetEntries(0, 0, numEntries, g_CurrentPalette.entries); if (FAILED(hr)) { logOutput << CurrentTimeString() << "Failed to retrieve palette entries" << endl; printDDrawError(hr, "SetupPalette"); g_CurrentPalette.Free(); return false; } g_CurrentPalette.primary_surface_palette_ref = lpDDPalette; g_CurrentPalette.bInitialized = true; g_bUsePalette = true; logOutput << CurrentTimeString() << "Initialized palette with " << numEntries << " color entries" << endl; return true; }