Created
September 14, 2015 10:51
-
-
Save k3kaimu/03e89b21e59fca71a24a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import derelict.sdl2.sdl; | |
import derelict.sdl2.image; | |
import std.string; | |
import std.conv; | |
import std.exception; | |
static this() | |
{ | |
DerelictSDL2.load(); | |
DerelictSDL2Image.load(); | |
} | |
void main() | |
{ | |
enforce(SDL_Init(SDL_INIT_VIDEO) >= 0); | |
enforce(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG); | |
auto input = readln().chomp(); | |
auto img = IMG_Load(input.toStringz()); | |
if(img is null) | |
writeln(IMG_GetError().to!string); | |
auto bs = cast(ubyte*)(img.pixels); | |
size_t bytes = bs[0] << 24 | bs[1] << 16 | bs[2] << 8 | bs[3]; | |
File file = File("output.dat", "w"); | |
file.rawWrite(img.pixels[4 .. bytes + 4]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment