Merge pull request #2921 from caiiiycuk/incoming
SDL_CreateRGBSurfaceFrom for surfaces with depth 32
This commit is contained in:
Коммит
81d1b20ce3
|
@ -1694,10 +1694,31 @@ var LibrarySDL = {
|
|||
},
|
||||
|
||||
SDL_CreateRGBSurfaceFrom: function(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask) {
|
||||
// TODO: Actually fill pixel data to created surface.
|
||||
// TODO: Take into account depth and pitch parameters.
|
||||
console.log('TODO: Partially unimplemented SDL_CreateRGBSurfaceFrom called!');
|
||||
return SDL.makeSurface(width, height, 0, false, 'CreateRGBSurfaceFrom', rmask, gmask, bmask, amask);
|
||||
var surf = SDL.makeSurface(width, height, 0, false, 'CreateRGBSurfaceFrom', rmask, gmask, bmask, amask);
|
||||
|
||||
if (depth !== 32) {
|
||||
// TODO: Actually fill pixel data to created surface.
|
||||
// TODO: Take into account depth and pitch parameters.
|
||||
console.log('TODO: Partially unimplemented SDL_CreateRGBSurfaceFrom called!');
|
||||
return surf;
|
||||
}
|
||||
|
||||
var data = SDL.surfaces[surf];
|
||||
var image = data.ctx.createImageData(width, height);
|
||||
var pitchOfDst = width * 4;
|
||||
|
||||
for (var row = 0; row < height; ++row) {
|
||||
var baseOfSrc = row * pitch;
|
||||
var baseOfDst = row * pitchOfDst;
|
||||
|
||||
for (var col = 0; col < width * 4; ++col) {
|
||||
image.data[baseOfDst + col] = {{{ makeGetValue('pixels', 'baseOfDst + col', 'i8', null, true) }}};
|
||||
}
|
||||
}
|
||||
|
||||
data.ctx.putImageData(image, 0, 0);
|
||||
|
||||
return surf;
|
||||
},
|
||||
|
||||
SDL_ConvertSurface: function(surf, format, flags) {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <SDL/SDL.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define width 600
|
||||
#define height 450
|
||||
|
||||
int main() {
|
||||
|
||||
uint8_t pixels[width * height * 4];
|
||||
uint8_t *end = pixels + width * height * 4;
|
||||
uint8_t *pixel = pixels;
|
||||
SDL_Rect rect = {0, 0, width, height};
|
||||
|
||||
while (pixel != end) {
|
||||
*pixel = (pixel - pixels) * 256 / (width * height * 4);
|
||||
pixel++;
|
||||
}
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Surface *screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE);
|
||||
SDL_Surface *image = SDL_CreateRGBSurfaceFrom(pixels, width, height, 32, width * 4,
|
||||
0x000000ff,
|
||||
0x0000ff00,
|
||||
0x00ff0000,
|
||||
0xff000000);
|
||||
|
||||
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 255, 0, 0));
|
||||
SDL_BlitSurface(image, &rect, screen, &rect);
|
||||
SDL_UpdateRect(screen, 0, 0, width, height);
|
||||
|
||||
printf("There should be a red to white gradient\n");
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 3.1 KiB |
|
@ -1623,6 +1623,9 @@ void *getBindBuffer() {
|
|||
def test_sdl_maprgba(self):
|
||||
self.btest('sdl_maprgba.c', reference='sdl_maprgba.png', reference_slack=3)
|
||||
|
||||
def test_sdl_create_rgb_surface_from(self):
|
||||
self.btest('sdl_create_rgb_surface_from.c', reference='sdl_create_rgb_surface_from.png')
|
||||
|
||||
def test_sdl_rotozoom(self):
|
||||
shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png'))
|
||||
self.btest('sdl_rotozoom.c', reference='sdl_rotozoom.png', args=['--preload-file', 'screenshot.png'], reference_slack=3)
|
||||
|
|
Загрузка…
Ссылка в новой задаче