Debian Codegraph @

src/io/gfx/video.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file video.cpp
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created main.c
10 * - 22nd July 2008: Created util.c from parts of main.c
11 * - 3rd February 2009: Renamed util.c to util.cpp
12 * - 13th July 2009: Created graphics.cpp from parts of util.cpp
13 * - 26th July 2009: Renamed graphics.cpp to video.cpp
14 *
15 * @par Licence:
16 * Copyright (c) 2005-2017 AJ Thomson
17 * Copyright (c) 2015-2026 Carsten Teibes
18 *
19 * OpenJazz is distributed under the terms of
20 * the GNU General Public License, version 2.0
21 *
22 * @par Description:
23 * Contains graphics utility functions.
24 *
25 */
26
27
28 #include "paletteeffects.h"cxx . . $ `<file>/src/io/gfx/paletteeffects.h`/
29 #include "video.h"cxx . . $ `<file>/src/io/gfx/video.h`/
30
31 #ifdef SCALEcxx . . $ `<built-in>:466:9`!
32 #include <scalebit.h>cxx . . $ `<file>/ext/scale2x/scalebit.h`/
33 #endif
34
35 #include "setup.h"cxx . . $ `<file>/src/setup.h`/
36 #include "util.h"cxx . . $ `<file>/src/util.h`/
37 #include "io/log.h"cxx . . $ `<file>/src/io/log.h`/
38
39 #include <string.h>
40
41
42
43 /**
44 * Creates a surface.
45 *
46 * @param pixels Pixel data to copy into the surface. Can be nullptr.
47 * @param width Width of the pixel data and of the surface to be created
48 * @param height Height of the pixel data and of the surface to be created
49 *
50 * @return The completed surface
51 */
52 SDL_Surface* Videocxx . . $ Video#::createSurfacecxx . . $ Video#createSurface(5ec4649223a2dfef). (const unsigned char * pixels, int width, int height) {
53
54 // Create the surface
55 SDL_Surface *ret = nullptr;
56 #if OJ_SDL3
57 ret = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_INDEX8);
58 if(ret) {
59 SDL_Palette *pal = SDL_CreateSurfacePalette(ret);
60 if(!pal) {
61 LOG_FATAL("Could not create surface palette: %s", SDL_GetError());
62 return nullptr;
63 }
64 }
65 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
66 ret = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_INDEX8);
67 #else
68 ret = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, 8, 0, 0, 0, 0);
69 #endif
70
71 if(!ret) {
72 LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Could not create surface: %s", SDL_GetError());
73 return nullptr;
74 }
75
76 // Set the surface's palette
77 videocxx . . $ video..restoreSurfacePalettecxx . . $ Video#restoreSurfacePalette(60a0b30a00b4fc6d).(ret);
78
79 if (pixels) {
80
81 // Upload pixel data to the surface
82 if (SDL_MUSTLOCKcxx . . $ `<external>/18043084669712134795/SDL_surface.h:62:9`!(ret)) SDL_LockSurface(ret);
83
84 for (int y = 0; y < height; y++)
85 memcpy(static_cast<unsigned char*>(ret->pixelscxx . . $ SDL_Surface#pixels.) + (ret->pitchcxx . . $ SDL_Surface#pitch. * y),
86 pixels + (width * y), width);
87
88 if (SDL_MUSTLOCKcxx . . $ `<external>/18043084669712134795/SDL_surface.h:62:9`!(ret)) SDL_UnlockSurface(ret);
89
90 }
91
92 return ret;
93
94 }
95
96 void Videocxx . . $ Video#::destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d). (SDL_Surface *surface) {
97 if (!surface)
98 return;
99
100 #if OJ_SDL3
101 SDL_DestroySurface(surface);
102 #else
103 SDL_FreeSurface(surface);
104 #endif
105 surface = nullptr;
106 }
107
108 void Videocxx . . $ Video#::setClipRectcxx . . $ Video#setClipRect(382a02f39687f508). (SDL_Surface *surface, const SDL_Rect *rect) {
109 #if OJ_SDL3
110 SDL_SetSurfaceClipRect(surface, rect);
111 #else
112 SDL_SetClipRect(surface, rect);
113 #endif
114 }
115
116 static void showCursorcxx . . $ showCursor(b45ddcbc8423892c).(bool enable) {
117 #if OJ_SDL3
118 if(enable) {
119 SDL_ShowCursor();
120 } else {
121 SDL_HideCursor();
122 }
123 #else
124 SDL_ShowCursor(enable? SDL_ENABLEcxx . . $ `<external>/12778062723415653681/SDL_events.h:1143:9`!: SDL_DISABLEcxx . . $ `<external>/12778062723415653681/SDL_events.h:1142:9`!);
125 #endif
126 }
127
128
129 /**
130 * Create the video output object.
131 */
132 Videocxx . . $ Video#::Videocxx . . $ Video#Video(49f6e7a06ebc5aa8). () :
133 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
134 windowcxx . . $ Video#window.(nullptr), renderercxx . . $ Video#renderer.(nullptr), texturecxx . . $ Video#texture.(nullptr),
135 #endif
136 #if OJ_SDL2cxx . . $ `<built-in>:465:9`!
137 textureSurfacecxx . . $ Video#textureSurface.(nullptr),
138 #endif
139 screencxx . . $ Video#screen.(nullptr), scaleFactorcxx . . $ Video#scaleFactor.(MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!), scaleMethodcxx . . $ Video#scaleMethod.(scalerTypecxx . . $ scalerType#::Nonecxx . . $ scalerType#None.),
140 fullscreencxx . . $ Video#fullscreen.(false), isPlayingMoviecxx . . $ Video#isPlayingMovie.(false) {
141
142 minWcxx . . $ Video#minW. = maxWcxx . . $ Video#maxW. = screenWcxx . . $ Video#screenW. = DEFAULT_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:54:10`!;
143 minHcxx . . $ Video#minH. = maxHcxx . . $ Video#maxH. = screenHcxx . . $ Video#screenH. = DEFAULT_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:57:10`!;
144
145 // Generate the logical palette
146 #if OJ_SDL3
147 logicalPalette = SDL_CreatePalette(MAX_PALETTE_COLORS);
148 for (int i = 0; i < MAX_PALETTE_COLORS; i++) {
149 logicalPalette->colors[i].r = logicalPalette->colors[i].g =
150 logicalPalette->colors[i].b = i;
151 logicalPalette->colors[i].a = 0xFF;
152 }
153
154 texturePalette = SDL_CreatePalette(MAX_PALETTE_COLORS);
155 currentPalette = logicalPalette->colors;
156 #else
157 for (int i = 0; i < MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!; i++) {
158 logicalPalettecxx . . $ Video#logicalPalette.[i].rcxx . . $ SDL_Color#r. = logicalPalettecxx . . $ Video#logicalPalette.[i].gcxx . . $ SDL_Color#g. = logicalPalettecxx . . $ Video#logicalPalette.[i].bcxx . . $ SDL_Color#b. = i;
159 #if OJ_SDL2cxx . . $ `<built-in>:465:9`!
160 logicalPalettecxx . . $ Video#logicalPalette.[i].acxx . . $ SDL_Color#a. = 0xFF;
161 #endif
162 }
163
164 currentPalettecxx . . $ Video#currentPalette. = logicalPalettecxx . . $ Video#logicalPalette.;
165 #endif
166 }
167
168
169 /**
170 * Find the minimum and maximum horizontal and vertical resolutions.
171 */
172 void Videocxx . . $ Video#::findResolutionscxx . . $ Video#findResolutions(49f6e7a06ebc5aa8). () {
173
174 #ifdef NO_RESIZE
175 minW = maxW = DEFAULT_SCREEN_WIDTH;
176 minH = maxH = DEFAULT_SCREEN_HEIGHT;
177
178 LOG_DEBUG("Using fixed resolution %dx%d.",
179 DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
180
181 // no need to sanitize
182 return;
183 #elif OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
184 minWcxx . . $ Video#minW. = SWcxx . . $ `src/io/gfx/video.h:38:9`!;
185 minHcxx . . $ Video#minH. = SHcxx . . $ `src/io/gfx/video.h:39:9`!;
186
187 bool queryOk = false;
188 #if OJ_SDL3
189 const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(SDL_GetDisplayForWindow(window));
190 queryOk = mode != nullptr;
191 if(queryOk) {
192 maxW = mode->w;
193 maxH = mode->h;
194 }
195 #else
196 SDL_DisplayMode mode;
197 queryOk = SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(windowcxx . . $ Video#window.), &mode) == 0;
198 if(queryOk) {
199 maxWcxx . . $ Video#maxW. = mode.w;
200 maxHcxx . . $ Video#maxH. = mode.h;
201 }
202 #endif
203 if (!queryOk) {
204 LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Could not query display mode, using defaults.");
205
206 maxWcxx . . $ Video#maxW. = DEFAULT_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:54:10`!;
207 maxHcxx . . $ Video#maxH. = DEFAULT_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:57:10`!;
208 }
209 #else
210 SDL_Rect **resolutions = SDL_ListModes(nullptr, fullscreen? FULLSCREEN_FLAGS: WINDOWED_FLAGS);
211
212 // All resolutions available, set to arbitrary limit
213 if (resolutions == reinterpret_cast<SDL_Rect**>(-1)) {
214 LOG_DEBUG("No display mode limit found.");
215 minW = SW;
216 minH = SH;
217 maxW = MAX_SCREEN_WIDTH;
218 maxH = MAX_SCREEN_HEIGHT;
219 } else {
220
221 for (int i = 0; resolutions[i] != nullptr; i++) {
222
223 // Save largest resolution
224 if (i == 0) {
225 maxW = resolutions[i]->w;
226 maxH = resolutions[i]->h;
227 }
228
229 // Save smallest resolution
230 if (resolutions[i + 1] == nullptr) {
231 minW = resolutions[i]->w;
232 minH = resolutions[i]->h;
233 }
234
235 }
236
237 }
238 #endif
239
240 // Sanitize
241 if (minWcxx . . $ Video#minW. < SWcxx . . $ `src/io/gfx/video.h:38:9`!) minWcxx . . $ Video#minW. = SWcxx . . $ `src/io/gfx/video.h:38:9`!;
242 if (minHcxx . . $ Video#minH. < SHcxx . . $ `src/io/gfx/video.h:39:9`!) minHcxx . . $ Video#minH. = SHcxx . . $ `src/io/gfx/video.h:39:9`!;
243 if (maxWcxx . . $ Video#maxW. > MAX_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:49:9`!) maxWcxx . . $ Video#maxW. = MAX_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:49:9`!;
244 if (maxHcxx . . $ Video#maxH. > MAX_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:50:9`!) maxHcxx . . $ Video#maxH. = MAX_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:50:9`!;
245
246 LOG_TRACEcxx . . $ `src/io/log.h:74:9`!("Allowing resolutions between %dx%d and %dx%d.", minW, minH, maxW, maxH);
247
248 }
249
250
251 /**
252 * Initialise video output.
253 *
254 * @param cfg Video Options
255 *
256 * @return Success
257 */
258 bool Videocxx . . $ Video#::initcxx . . $ Video#init(63f3bea6ba3175f4). (SetupOptionscxx . . $ SetupOptions# cfg) {
259
260 fullscreencxx . . $ Video#fullscreen. = cfg.fullScreencxx . . $ SetupOptions#fullScreen.;
261
262 // The window stays for whole runtime, as it is needed for
263 // e.g. determining desktop resolution
264 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
265 #if OJ_SDL3
266 window = SDL_CreateWindow("OpenJazz", SW, SH, fullscreen? SDL_WINDOW_FULLSCREEN: SDL_WINDOW_RESIZABLE);
267 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
268 windowcxx . . $ Video#window. = SDL_CreateWindow("OpenJazz", SDL_WINDOWPOS_UNDEFINEDcxx . . $ `<external>/14887343297790812595/SDL_video.h:138:9`!,
269 SDL_WINDOWPOS_UNDEFINEDcxx . . $ `<external>/14887343297790812595/SDL_video.h:138:9`!, SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!,
270 fullscreencxx . . $ Video#fullscreen.? SDL_WINDOW_FULLSCREEN_DESKTOP: SDL_WINDOW_RESIZABLE);
271 #endif
272 if (!windowcxx . . $ Video#window.) {
273 LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Could not create window: %s", SDL_GetError());
274 return false;
275 }
276 #endif
277
278 if (fullscreencxx . . $ Video#fullscreen.) showCursorcxx . . $ showCursor(b45ddcbc8423892c).(false);
279
280 findResolutionscxx . . $ Video#findResolutions(49f6e7a06ebc5aa8).();
281
282 #ifdef SCALEcxx . . $ `<built-in>:466:9`!
283 if ((SWcxx . . $ `src/io/gfx/video.h:38:9`! * cfg.videoScalecxx . . $ SetupOptions#videoScale. <= cfg.videoWidthcxx . . $ SetupOptions#videoWidth.) &&
284 (SHcxx . . $ `src/io/gfx/video.h:39:9`! * cfg.videoScalecxx . . $ SetupOptions#videoScale. <= cfg.videoHeightcxx . . $ SetupOptions#videoHeight.))
285 scaleFactorcxx . . $ Video#scaleFactor. = cfg.videoScalecxx . . $ SetupOptions#videoScale.;
286
287 scaleMethodcxx . . $ Video#scaleMethod. = cfg.scaleMethodcxx . . $ SetupOptions#scaleMethod.;
288 #endif
289
290 if (!resetcxx . . $ Video#reset(cf9ef193275fa6d8).(cfg.videoWidthcxx . . $ SetupOptions#videoWidth., cfg.videoHeightcxx . . $ SetupOptions#videoHeight.)) {
291 LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Could not set video mode: %s", SDL_GetError());
292 return false;
293 }
294
295 setTitlecxx . . $ Video#setTitle(85c52e162fed56f9).(nullptr);
296
297 return true;
298
299 }
300
301
302 /**
303 * Shared Deinitialisation code for reset() and deinit()
304 *
305 */
306 void Videocxx . . $ Video#::commonDeinitcxx . . $ Video#commonDeinit(49f6e7a06ebc5aa8). () {
307 // canvas is used when scaling or built with SDL2
308 if (canvascxx . . $ canvas. && canvascxx . . $ canvas. != screencxx . . $ Video#screen.)
309 destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(canvascxx . . $ canvas.);
310
311 #if OJ_SDL2cxx . . $ `<built-in>:465:9`!
312 if(textureSurfacecxx . . $ Video#textureSurface.)
313 destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(textureSurfacecxx . . $ Video#textureSurface.);
314 #endif
315
316 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
317 if(screencxx . . $ Video#screen.)
318 destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(screencxx . . $ Video#screen.);
319
320 if(texturecxx . . $ Video#texture.) {
321 SDL_DestroyTexture(texturecxx . . $ Video#texture.);
322 texturecxx . . $ Video#texture. = nullptr;
323 }
324
325 if(renderercxx . . $ Video#renderer.) {
326 SDL_DestroyRenderer(renderercxx . . $ Video#renderer.);
327 renderercxx . . $ Video#renderer. = nullptr;
328 }
329 #endif
330 }
331
332 /**
333 * Deinitialise video output.
334 *
335 */
336 void Videocxx . . $ Video#::deinitcxx . . $ Video#deinit(49f6e7a06ebc5aa8). () {
337
338 commonDeinitcxx . . $ Video#commonDeinit(49f6e7a06ebc5aa8).();
339
340 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
341 if(windowcxx . . $ Video#window.) {
342 SDL_DestroyWindow(windowcxx . . $ Video#window.);
343 windowcxx . . $ Video#window. = nullptr;
344 }
345 #endif
346 }
347
348 /**
349 * Sets the size of the video window or the resolution of the screen.
350 *
351 * @param width New width of the window or screen
352 * @param height New height of the window or screen
353 *
354 * @return Success
355 */
356 bool Videocxx . . $ Video#::resetcxx . . $ Video#reset(cf9ef193275fa6d8). (int width, int height) {
357
358 #ifdef NO_RESIZE
359 (void)width;
360 (void)height;
361 screenW = DEFAULT_SCREEN_WIDTH;
362 screenH = DEFAULT_SCREEN_HEIGHT;
363 fullscreen = true;
364 #else
365 screenWcxx . . $ Video#screenW. = width;
366 screenHcxx . . $ Video#screenH. = height;
367 #endif
368
369 commonDeinitcxx . . $ Video#commonDeinit(49f6e7a06ebc5aa8).();
370
371 // If video mode is not valid reset to low default
372 if (screenWcxx . . $ Video#screenW. < minWcxx . . $ Video#minW. || screenWcxx . . $ Video#screenW. > maxWcxx . . $ Video#maxW. || screenHcxx . . $ Video#screenH. < minHcxx . . $ Video#minH. || screenHcxx . . $ Video#screenH. > maxHcxx . . $ Video#maxH.) {
373 LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Video mode invalid, resetting.");
374 screenWcxx . . $ Video#screenW. = minWcxx . . $ Video#minW.;
375 screenHcxx . . $ Video#screenH. = minHcxx . . $ Video#minH.;
376 }
377
378 #if OJ_SDL3
379 renderer = SDL_CreateRenderer(window, nullptr);
380 if (!renderer) {
381 LOG_FATAL("Could not create renderer: %s", SDL_GetError());
382 return false;
383 }
384
385 SDL_SetWindowSize(window, screenW, screenH);
386 SDL_SetWindowFullscreen(window, fullscreen? SDL_WINDOW_FULLSCREEN: 0);
387 screen = createSurface(nullptr, screenW, screenH);
388 if (!screen) {
389 LOG_FATAL("Could not create screen surface: %s", SDL_GetError());
390 return false;
391 }
392 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
393 // Let the renderer scale the texture
394 switch(scaleMethodcxx . . $ Video#scaleMethod.) {
395 case scalerTypecxx . . $ scalerType#::Bilinearcxx . . $ scalerType#Bilinear.:
396 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITYcxx . . $ `<external>/10713713676398969957/SDL_hints.h:1983:9`!, "linear");
397 break;
398 default:
399 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITYcxx . . $ `<external>/10713713676398969957/SDL_hints.h:1983:9`!, "nearest");
400 break;
401 }
402
403 renderercxx . . $ Video#renderer. = SDL_CreateRenderer(windowcxx . . $ Video#window., -1, 0);
404 if (!renderercxx . . $ Video#renderer.) {
405 LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Could not create renderer: %s", SDL_GetError());
406 return false;
407 }
408
409 SDL_SetWindowSize(windowcxx . . $ Video#window., screenWcxx . . $ Video#screenW., screenHcxx . . $ Video#screenH.);
410 SDL_SetWindowFullscreen(windowcxx . . $ Video#window., fullscreencxx . . $ Video#fullscreen.? SDL_WINDOW_FULLSCREEN_DESKTOP: 0);
411 #else
412 screen = SDL_SetVideoMode(screenW, screenH, 8, fullscreen? FULLSCREEN_FLAGS: WINDOWED_FLAGS);
413 if (!screen) return false;
414 #endif
415
416 #ifdef SCALEcxx . . $ `<built-in>:466:9`!
417 // sanitize
418 scaleFactorcxx . . $ Video#scaleFactor. = CLAMPcxx . . $ `src/types.h:58:9`!(scaleFactor, MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!, MAX_SCALEcxx . . $ `src/io/gfx/video.h:43:10`!);
419
420 // Check that the scale will fit in the current resolution
421 while ( ((screenWcxx . . $ Video#screenW./SWcxx . . $ `src/io/gfx/video.h:38:9`! < scaleFactorcxx . . $ Video#scaleFactor.) || (screenHcxx . . $ Video#screenH./SHcxx . . $ `src/io/gfx/video.h:39:9`! < scaleFactorcxx . . $ Video#scaleFactor.))
422 && (scaleFactorcxx . . $ Video#scaleFactor. > MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!) ) {
423 scaleFactorcxx . . $ Video#scaleFactor.--;
424 }
425
426 if (scaleFactorcxx . . $ Video#scaleFactor. > MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!) {
427 // Do scaling
428 canvasWcxx . . $ canvasW. = screenWcxx . . $ Video#screenW. / scaleFactorcxx . . $ Video#scaleFactor.;
429 canvasHcxx . . $ canvasH. = screenHcxx . . $ Video#screenH. / scaleFactorcxx . . $ Video#scaleFactor.;
430 canvascxx . . $ canvas. = createSurfacecxx . . $ Video#createSurface(5ec4649223a2dfef).(nullptr, canvasWcxx . . $ canvasW., canvasHcxx . . $ canvasH.);
431
432 } else
433 #endif
434 {
435 // No scaling
436 canvasWcxx . . $ canvasW. = screenWcxx . . $ Video#screenW.;
437 canvasHcxx . . $ canvasH. = screenHcxx . . $ Video#screenH.;
438
439 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
440 canvascxx . . $ canvas. = createSurfacecxx . . $ Video#createSurface(5ec4649223a2dfef).(nullptr, canvasWcxx . . $ canvasW., canvasHcxx . . $ canvasH.);
441 #else
442 canvas = screen;
443 #endif
444
445 }
446
447 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
448 int renderW = canvasWcxx . . $ canvasW.;
449 int renderH = canvasHcxx . . $ canvasH.;
450
451 #if SCALEcxx . . $ `<built-in>:466:9`!
452 // Do prescaling (scaleX, hqx)
453 if(scaleMethodcxx . . $ Video#scaleMethod. != scalerTypecxx . . $ scalerType#::Nonecxx . . $ scalerType#None. && scaleMethodcxx . . $ Video#scaleMethod. != scalerTypecxx . . $ scalerType#::Bilinearcxx . . $ scalerType#Bilinear.) {
454 renderW = screenWcxx . . $ Video#screenW.;
455 renderH = screenHcxx . . $ Video#screenH.;
456 }
457 #endif
458
459 #if OJ_SDL3
460 SDL_SetRenderLogicalPresentation(renderer, renderW, renderH, SDL_LOGICAL_PRESENTATION_LETTERBOX);
461
462 const char *name = SDL_GetRendererName(renderer);
463 LOG_TRACE("Using '%s' pixel format with '%s' renderer", SDL_GetPixelFormatName(SDL_PIXELFORMAT_INDEX8), name);
464
465 // Create texture for pixel data upload (8 bit)
466 texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_INDEX8, SDL_TEXTUREACCESS_STREAMING, renderW, renderH);
467 if (!texture) {
468 LOG_ERROR("Could not create texture: %s", SDL_GetError());
469 return false;
470 }
471 if(!SDL_SetTexturePalette(texture, texturePalette)) {
472 LOG_ERROR("Could not set texture palette: %s", SDL_GetError());
473 return false;
474 }
475 // Let the renderer scale the texture
476 switch(scaleMethod) {
477 case scalerType::Bilinear:
478 SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
479 break;
480 default:
481 SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
482 break;
483 }
484 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
485 SDL_RenderSetLogicalSize(renderercxx . . $ Video#renderer., renderW, renderH);
486
487 Uint32cxx . . $ Uint32# format = SDL_MasksToPixelFormatEnum(canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->BitsPerPixel,
488 canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->Rmask, canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->Gmask, canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->Bmask, canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->Amask);
489 LOG_TRACEcxx . . $ `src/io/log.h:74:9`!("Screen surface is using '%s' pixel format", SDL_GetPixelFormatName(format));
490 screencxx . . $ Video#screen. = SDL_CreateRGBSurfaceWithFormatFrom(canvascxx . . $ canvas.->pixelscxx . . $ SDL_Surface#pixels., canvasWcxx . . $ canvasW., canvasHcxx . . $ canvasH.,
491 canvascxx . . $ canvas.->formatcxx . . $ SDL_Surface#format.->BitsPerPixel, canvascxx . . $ canvas.->pitchcxx . . $ SDL_Surface#pitch., format);
492
493 // Find a suitable renderer/texture format
494 format = SDL_PIXELFORMAT_RGB888;
495 SDL_RendererInfo info;
496 if (SDL_GetRendererInfo(renderercxx . . $ Video#renderer., &info) >= 0) {
497 for (Uint32cxx . . $ Uint32# i = 0; i < info.num_texture_formats; i++) {
498 if (SDL_ISPIXELFORMAT_PACKEDcxx . . $ `<external>/13773327968391986473/SDL_pixels.h:144:9`!(info.texture_formats[i])) {
499 format = info.texture_formats[i];
500 break;
501 }
502 }
503 }
504 LOG_TRACEcxx . . $ `src/io/log.h:74:9`!("Using '%s' pixel format with '%s' renderer", SDL_GetPixelFormatName(format), info.name);
505
506 // Create texture with compatible surface for pixel data upload (likely 32 bit)
507 texturecxx . . $ Video#texture. = SDL_CreateTexture(renderercxx . . $ Video#renderer., format, SDL_TEXTUREACCESS_STREAMING, renderW, renderH);
508 if (!texturecxx . . $ Video#texture.) {
509 LOG_ERRORcxx . . $ `src/io/log.h:78:9`!("Could not create texture: %s", SDL_GetError());
510 return false;
511 }
512
513 textureSurfacecxx . . $ Video#textureSurface. = SDL_CreateRGBSurfaceWithFormat(0, renderW, renderH, SDL_BITSPERPIXELcxx . . $ `<external>/13773327968391986473/SDL_pixels.h:130:9`!(format), format);
514 if (!textureSurfacecxx . . $ Video#textureSurface.) {
515 LOG_ERRORcxx . . $ `src/io/log.h:78:9`!("Could not create surface: %s", SDL_GetError());
516 return false;
517 }
518 #endif
519 #endif
520
521 #if !defined(WIZ) && !defined(GP2X)
522 exposecxx . . $ Video#expose(49f6e7a06ebc5aa8).();
523 #endif
524
525 return true;
526
527 }
528
529
530 /**
531 * Sets the display palette.
532 *
533 * @param palette The new palette
534 */
535 void Videocxx . . $ Video#::setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2). (SDL_Color *palette) {
536
537 // Make palette changes invisible until the next draw. Hopefully.
538 #if OJ_SDL3
539 const SDL_PixelFormatDetails *details = SDL_GetPixelFormatDetails(canvas->format);
540 clearScreen(SDL_MapRGB(details, nullptr, 0, 0, 0));
541 #else
542 clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(SDL_MapRGB(screencxx . . $ Video#screen.->formatcxx . . $ SDL_Surface#format., 0, 0, 0));
543 #endif
544 flipcxx . . $ Video#flip(b4cc491d773144d4).(0);
545
546 changePalettecxx . . $ Video#changePalette(dc6239902d762776).(palette, 0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
547 currentPalettecxx . . $ Video#currentPalette. = palette;
548
549 }
550
551 /**
552 * Sets some colours of the display palette.
553 *
554 * @param palette The palette containing the new colours
555 * @param first The index of the first colour in both the display palette and the specified palette
556 * @param amount The number of colours
557 */
558 void Videocxx . . $ Video#::changePalettecxx . . $ Video#changePalette(dc6239902d762776). (SDL_Color *palette, unsigned char first, unsigned int amount) {
559 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
560 setSurfacePalettecxx . . $ Video#setSurfacePalette(b59f7f041c83eb39).(screencxx . . $ Video#screen., palette, first, amount);
561 #if OJ_SDL3
562 if(!SDL_SetPaletteColors(texturePalette, palette, first, amount)) {
563 LOG_WARN("Could not set texture palette colors: %s", SDL_GetError());
564 }
565 #endif
566 #else
567 SDL_SetPalette(screen, SDL_PHYSPAL, palette, first, amount);
568 #endif
569 }
570
571
572 /**
573 * Restores a surface's palette.
574 *
575 * @param surface Surface with a modified palette
576 */
577 void Videocxx . . $ Video#::restoreSurfacePalettecxx . . $ Video#restoreSurfacePalette(60a0b30a00b4fc6d). (SDL_Surface* surface) {
578 #if OJ_SDL3
579 setSurfacePalette(surface, logicalPalette->colors, 0, MAX_PALETTE_COLORS);
580 #else
581 setSurfacePalettecxx . . $ Video#setSurfacePalette(b59f7f041c83eb39).(surface, logicalPalettecxx . . $ Video#logicalPalette., 0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
582 #endif
583 }
584
585
586 /**
587 * Sets the window title.
588 *
589 * @param title the title or nullptr, to use default
590 */
591 void Videocxx . . $ Video#::setTitlecxx . . $ Video#setTitle(85c52e162fed56f9). (const char *title) {
592
593 constexpr const char *titleBase = "OpenJazz";
594 int titleLen = strlen(titleBase) + 1;
595
596 if (title != nullptr) {
597 titleLen = strlen(titleBase) + 3 + strlen(title) + 1;
598 }
599
600 char *windowTitle = new char[titleLen];
601 strcpy(windowTitle, titleBase);
602
603 if (title != nullptr) {
604 strcat(windowTitle, " - ");
605 strcat(windowTitle, title);
606 }
607
608 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
609 SDL_SetWindowTitle(windowcxx . . $ Video#window., windowTitle);
610 #else
611 SDL_WM_SetCaption(windowTitle, nullptr);
612 #endif
613
614 delete[] windowTitle;
615
616 }
617
618
619 /**
620 * Sets the scaling factor and method.
621 *
622 * @param newScaleFactor The new scaling factor
623 * @param newScaleMethod The new scaling method
624 */
625 void Videocxx . . $ Video#::setScalingcxx . . $ Video#setScaling(37c85713de463f11). (int newScaleFactor, scalerTypecxx . . $ scalerType# newScaleMethod) {
626 bool reset_needed = false;
627
628 if ((SWcxx . . $ `src/io/gfx/video.h:38:9`! * newScaleFactor <= screenWcxx . . $ Video#screenW.) && (SHcxx . . $ `src/io/gfx/video.h:39:9`! * newScaleFactor <= screenHcxx . . $ Video#screenH.)) {
629 reset_needed = (scaleFactorcxx . . $ Video#scaleFactor. != newScaleFactor);
630 scaleFactorcxx . . $ Video#scaleFactor. = newScaleFactor;
631 }
632
633 if(scaleMethodcxx . . $ Video#scaleMethod. != newScaleMethod) {
634 scaleMethodcxx . . $ Video#scaleMethod. = newScaleMethod;
635 reset_needed = true;
636 }
637
638 if(reset_needed) {
639 if (screencxx . . $ Video#screen.)
640 resetcxx . . $ Video#reset(cf9ef193275fa6d8).(screenWcxx . . $ Video#screenW., screenHcxx . . $ Video#screenH.);
641 }
642 }
643
644
645 /**
646 * Refresh display palette.
647 */
648 void Videocxx . . $ Video#::exposecxx . . $ Video#expose(49f6e7a06ebc5aa8). () {
649 #if OJ_SDL3
650 setSurfacePalette(screen, logicalPalette->colors, 0, MAX_PALETTE_COLORS);
651 #else
652 setSurfacePalettecxx . . $ Video#setSurfacePalette(b59f7f041c83eb39).(screencxx . . $ Video#screen., logicalPalettecxx . . $ Video#logicalPalette., 0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
653 #endif
654 changePalettecxx . . $ Video#changePalette(dc6239902d762776).(currentPalettecxx . . $ Video#currentPalette., 0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
655 }
656
657
658 /**
659 * Update video based on a system event.
660 *
661 * @param event The system event. Events not affecting video will be ignored
662 */
663 void Videocxx . . $ Video#::updatecxx . . $ Video#update(568d8a17e3151145). (SDL_Event *event) {
664 #if !defined(FULLSCREEN_ONLY) || !defined(NO_RESIZE)
665 auto switchFullscreen = [&] () {
666 fullscreencxx . . $ Video#fullscreen. = !fullscreencxx . . $ Video#fullscreen.;
667 if (fullscreencxx . . $ Video#fullscreen.) showCursorcxx . . $ showCursor(b45ddcbc8423892c).(false);
668
669 findResolutionscxx . . $ Video#findResolutions(49f6e7a06ebc5aa8).();
670
671 resetcxx . . $ Video#reset(cf9ef193275fa6d8).(screenWcxx . . $ Video#screenW., screenHcxx . . $ Video#screenH.);
672 if (!fullscreencxx . . $ Video#fullscreen.) showCursorcxx . . $ showCursor(b45ddcbc8423892c).(true);
673 };
674
675 switch (event->type) {
676
677 #ifndef FULLSCREEN_ONLY
678 #if OJ_SDL3
679 case SDL_EVENT_KEY_DOWN:
680 // If Alt + Enter has been pressed, switch between windowed and full-screen mode.
681 if ((event->key.key == SDLK_RETURN) && (event->key.mod & SDL_KMOD_ALT)) {
682 switchFullscreen();
683 }
684 #else
685 case SDL_KEYDOWN:
686 // If Alt + Enter has been pressed, switch between windowed and full-screen mode.
687 if ((event->key.keysym.sym == SDLK_RETURNcxx . . $ SDLK_RETURN.) &&
688 (event->key.keysym.mod & KMOD_ALTcxx . . $ KMOD_ALT.)) {
689 switchFullscreen(cxx . . $ Video#update(568d8a17e3151145).$anonymous_type_0#`operator()`(83f5f38750778ac8).);
690 }
691
692 #endif
693
694 break;
695 #endif
696
697 #if !OJ_SDL3 && !OJ_SDL2cxx . . $ `<built-in>:465:9`!
698 #ifndef NO_RESIZE
699 case SDL_VIDEORESIZE:
700 reset(event->resize.w, event->resize.h);
701
702 break;
703 #endif
704
705 case SDL_VIDEOEXPOSE:
706 expose();
707
708 break;
709 #endif
710 }
711 #else
712 (void)event;
713 #endif
714 }
715
716
717 /**
718 * Draw graphics to screen.
719 *
720 * @param mspf Ticks per frame
721 * @param paletteEffects Palette effects to use
722 * @param effectsStopped Whether the effects should be applied without advancing
723 */
724 void Videocxx . . $ Video#::flipcxx . . $ Video#flip(b4cc491d773144d4). (int mspf, PaletteEffectcxx . . $ PaletteEffect#* paletteEffects, bool effectsStopped) {
725
726 SDL_Color shownPalette[MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!];
727
728 #if defined(SCALEcxx . . $ `<built-in>:466:9`!) && !OJ_SDL2cxx . . $ `<built-in>:465:9`! && !OJ_SDL3
729 // for SDL1.2 scale 8 bit canvas surface
730 if (canvas != nullptr && canvas != screen) {
731
732 // Copy everything that has been drawn so far
733 if (scaleMethod == scalerType::Scale2x)
734 scale(scaleFactor,
735 screen->pixels, screen->pitch,
736 canvas->pixels, canvas->pitch,
737 screen->format->BytesPerPixel, canvas->w, canvas->h);
738 else
739 SDL_SoftStretch(canvas, nullptr, screen, nullptr);
740
741 }
742 #endif
743
744 // Apply palette effects
745 if (paletteEffects) {
746 // The palette is emulated, compile all palette changes and apply at once.
747 memcpy(shownPalette, currentPalettecxx . . $ Video#currentPalette., sizeof(SDL_Color) * MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
748 paletteEffects->applycxx . . $ PaletteEffect#apply(a0d1f6d228fe1f03).(shownPalette, false, mspf, effectsStopped);
749 changePalettecxx . . $ Video#changePalette(dc6239902d762776).(shownPalette, 0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!);
750 }
751
752 #if OJ_SDL3
753 // Show what has been drawn
754 SDL_UpdateTexture(texture, nullptr, canvas->pixels, canvas->pitch);
755 SDL_RenderClear(renderer);
756 if (isPlayingMovie) {
757 SDL_FRect src = {0, 0, static_cast<float>(canvasW), static_cast<float>(canvasH)};
758 SDL_RenderTexture(renderer, texture, &src, nullptr);
759 } else {
760 SDL_RenderTexture(renderer, texture, nullptr, nullptr);
761 }
762 SDL_RenderPresent(renderer);
763 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
764 #if defined(SCALEcxx . . $ `<built-in>:466:9`!)
765 if(scaleFactorcxx . . $ Video#scaleFactor. > MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`! && scaleMethodcxx . . $ Video#scaleMethod. == scalerTypecxx . . $ scalerType#::Scale2xcxx . . $ scalerType#Scale2x.) {
766 // scale 32 bit screen surface
767 scalecxx . . $ scale(7846225ae81d1a86).(scaleFactorcxx . . $ Video#scaleFactor.,
768 textureSurfacecxx . . $ Video#textureSurface.->pixelscxx . . $ SDL_Surface#pixels., textureSurfacecxx . . $ Video#textureSurface.->pitchcxx . . $ SDL_Surface#pitch.,
769 screencxx . . $ Video#screen.->pixelscxx . . $ SDL_Surface#pixels., screencxx . . $ Video#screen.->pitchcxx . . $ SDL_Surface#pitch.,
770 screencxx . . $ Video#screen.->formatcxx . . $ SDL_Surface#format.->BytesPerPixel, screencxx . . $ Video#screen.->wcxx . . $ SDL_Surface#w., screencxx . . $ Video#screen.->hcxx . . $ SDL_Surface#h.);
771 } else if (scaleFactorcxx . . $ Video#scaleFactor. > MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`! && scaleMethodcxx . . $ Video#scaleMethod. == scalerTypecxx . . $ scalerType#::hqxcxx . . $ scalerType#hqx.) {
772 // TODO
773 } else {
774 #endif
775 // copy unscaled
776 SDL_BlitSurfacecxx . . $ `<external>/18043084669712134795/SDL_surface.h:873:9`!(screencxx . . $ Video#screen., nullptr, textureSurfacecxx . . $ Video#textureSurface., nullptr);
777 #if defined(SCALEcxx . . $ `<built-in>:466:9`!)
778 }
779 #endif
780
781 // Show what has been drawn
782 SDL_UpdateTexture(texturecxx . . $ Video#texture., nullptr, textureSurfacecxx . . $ Video#textureSurface.->pixelscxx . . $ SDL_Surface#pixels., textureSurfacecxx . . $ Video#textureSurface.->pitchcxx . . $ SDL_Surface#pitch.);
783 SDL_RenderClear(renderercxx . . $ Video#renderer.);
784
785 if (isPlayingMoviecxx . . $ Video#isPlayingMovie.) {
786 SDL_Rect src = {0, 0, canvasWcxx . . $ canvasW., canvasHcxx . . $ canvasH.};
787 SDL_RenderCopy(renderercxx . . $ Video#renderer., texturecxx . . $ Video#texture., &src, nullptr);
788 } else {
789 SDL_RenderCopy(renderercxx . . $ Video#renderer., texturecxx . . $ Video#texture., nullptr, nullptr);
790 }
791 SDL_RenderPresent(renderercxx . . $ Video#renderer.);
792 #else
793 SDL_Flip(screen);
794 #endif
795
796 }
797
798
799 /**
800 * Fill the screen with a colour.
801 *
802 * @param index Index of the colour to use
803 */
804 void Videocxx . . $ Video#::clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3). (int index) {
805
806 #if defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(GAMESHELL)
807 // always 240 lines cleared to black
808 memset(screen->pixels, index, 320*240);
809 #elif defined (__3DS__)
810 memset(screen->pixels, index, 400*240);
811 #elif OJ_SDL3
812 SDL_FillSurfaceRect(canvas, nullptr, index);
813 #else
814 SDL_FillRect(canvascxx . . $ canvas., nullptr, index);
815 #endif
816
817 }
818
819
820 /**
821 * Sets up scaling for movie mode.
822 *
823 * @param status Whether or not movie mode will be enabled
824 */
825 void Videocxx . . $ Video#::moviePlaybackcxx . . $ Video#moviePlayback(b45ddcbc8423892c). (bool status) {
826 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
827 static int movieW = SWcxx . . $ `src/io/gfx/video.h:38:9`!;
828 static int movieH = SHcxx . . $ `src/io/gfx/video.h:39:9`!;
829
830 if(isPlayingMoviecxx . . $ Video#isPlayingMovie. == status)
831 return;
832
833 isPlayingMoviecxx . . $ Video#isPlayingMovie. = status;
834
835 if (isPlayingMoviecxx . . $ Video#isPlayingMovie.) {
836 // save size
837 movieW = canvasWcxx . . $ canvasW.;
838 movieH = canvasHcxx . . $ canvasH.;
839
840 canvasWcxx . . $ canvasW. = SWcxx . . $ `src/io/gfx/video.h:38:9`!;
841 canvasHcxx . . $ canvasH. = SHcxx . . $ `src/io/gfx/video.h:39:9`!;
842 } else {
843 // reset
844 canvasWcxx . . $ canvasW. = movieW;
845 canvasHcxx . . $ canvasH. = movieH;
846 }
847 #if OJ_SDL3
848 SDL_SetRenderLogicalPresentation(renderer, canvasW, canvasH, SDL_LOGICAL_PRESENTATION_LETTERBOX);
849 #else
850 SDL_RenderSetLogicalSize(renderercxx . . $ Video#renderer., canvasWcxx . . $ canvasW., canvasHcxx . . $ canvasH.);
851 #endif
852 #else
853 (void)status;
854 #endif
855 }
856
857
858 /**
859 * Fill a specified rectangle of the screen with a colour.
860 *
861 * @param x X-coordinate of the left side of the rectangle
862 * @param y Y-coordinate of the top of the rectangle
863 * @param width Width of the rectangle
864 * @param height Height of the rectangle
865 * @param index Index of the colour to use
866 * @param fill Whether to fill or only color the borders
867 */
868 void Videocxx . . $ Video#::drawRectcxx . . $ Video#drawRect(a4376a5627a47301). (int x, int y, int width, int height, int index, bool fill) {
869 SDL_Rect dst[4];
870
871 for(int i = 0; i < 4; i++) {
872 dst[i].x = x;
873 dst[i].y = y;
874 dst[i].w = width;
875 dst[i].h = height;
876 }
877
878 if (fill) {
879 #if OJ_SDL3
880 SDL_FillSurfaceRect(canvas, &dst[0], index);
881 #else
882 SDL_FillRect(canvascxx . . $ canvas., &dst[0], index);
883 #endif
884 } else {
885 // left
886 dst[0].w = 1;
887 // right
888 dst[1].x = x + width - 1;
889 dst[1].w = 1;
890 // top
891 dst[2].h = 1;
892 // bottom
893 dst[3].y = y + height - 1;
894 dst[3].h = 1;
895 // draw each border
896 #if OJ_SDL3
897 SDL_FillSurfaceRects(canvas, dst, 4, index);
898 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
899 SDL_FillRects(canvascxx . . $ canvas., dst, 4, index);
900 #else
901 SDL_FillRect(canvas, &dst[0], index);
902 SDL_FillRect(canvas, &dst[1], index);
903 SDL_FillRect(canvas, &dst[2], index);
904 SDL_FillRect(canvas, &dst[3], index);
905 #endif
906 }
907 }
908
909 /**
910 * Sets the Color key of provided surface.
911 *
912 * @param surface Surface to change
913 * @param index Color index
914 */
915 void Videocxx . . $ Video#::enableColorKeycxx . . $ Video#enableColorKey(905504f46e4e09c1). (SDL_Surface* surface, unsigned int index) {
916
917 #if OJ_SDL3
918 SDL_SetSurfaceColorKey(surface, true, index);
919 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
920 SDL_SetColorKey(surface, SDL_TRUEcxx . . $ SDL_TRUE., index);
921 #else
922 SDL_SetColorKey(surface, SDL_SRCCOLORKEY, index);
923 #endif
924
925 }
926
927 /**
928 * Returns the Color key of provided surface.
929 *
930 * @param surface Surface to query
931 *
932 * @return color index
933 */
934 unsigned int Videocxx . . $ Video#::getColorKeycxx . . $ Video#getColorKey(77e0245589bafc78). (SDL_Surface* surface) {
935
936 #if OJ_SDL3 || OJ_SDL2cxx . . $ `<built-in>:465:9`!
937 Uint32cxx . . $ Uint32# key;
938 bool queryOk = false;
939
940 #if OJ_SDL3
941 queryOk = SDL_GetSurfaceColorKey(surface, &key);
942 #else
943 queryOk = SDL_GetColorKey(surface, &key) == 0;
944 #endif
945
946 if (!queryOk) {
947 LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Could not get Color Key: %s\n", SDL_GetError());
948 return -1;
949 }
950
951 return key;
952
953 #else
954 return surface->format->colorkey;
955 #endif
956
957 }
958
959 /**
960 * Sets the palette colors of provided surface.
961 *
962 * @param surface Surface to change
963 * @param palette Palette to copy colors from
964 * @param start index of first color copy
965 * @param length number of colors to copy
966 */
967 void Videocxx . . $ Video#::setSurfacePalettecxx . . $ Video#setSurfacePalette(b59f7f041c83eb39). (SDL_Surface* surface, SDL_Color *palette, int start, int length) {
968 #if OJ_SDL3
969 SDL_Palette *surfacePalette = SDL_GetSurfacePalette(surface);
970 if(!surfacePalette) {
971 LOG_WARN("Could not set palette on surface without palette.");
972 return;
973 }
974
975 if(!SDL_SetPaletteColors(surfacePalette, palette, start, length)) {
976 LOG_WARN("Could not set palette colors: %s", SDL_GetError());
977 return;
978 }
979 #elif OJ_SDL2cxx . . $ `<built-in>:465:9`!
980 if (surface->formatcxx . . $ SDL_Surface#format.->palette) {
981 SDL_SetPaletteColors(surface->formatcxx . . $ SDL_Surface#format.->palette, palette, start, length);
982 } else
983 LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Could not change palette on surface without palette.");
984 #else
985 SDL_SetPalette(surface, SDL_LOGPAL, palette, start, length);
986 #endif
987
988 }