MCPcopy Create free account
hub / github.com/TASEmulators/fceux / gui_gdscreenshot

Function gui_gdscreenshot

src/lua-engine.cpp:4144–4184  ·  view source on GitHub ↗

gui.gdscreenshot(getemuscreen) Returns a screen shot as a string in gd's v1 file format. This allows us to make screen shots available without gd installed locally. Users can also just grab pixels via substring selection. I think... Does lua support grabbing byte values from a string? // yes, string.byte(str,offset) Well, either way, just install gd and do what you like with it. It really is ea

Source from the content-addressed store, hash-verified

4142// It really is easier that way.
4143// example: gd.createFromGdStr(gui.gdscreenshot()):png("outputimage.png")
4144static int gui_gdscreenshot(lua_State *L) {
4145 bool getemuscreen = (lua_toboolean(L,1) == 1);
4146
4147 int width = LUA_SCREEN_WIDTH;
4148 int height = LUA_SCREEN_HEIGHT;
4149
4150 int size = 11 + width * height * 4;
4151 char* str = new char[size+1];
4152 str[size] = 0;
4153 unsigned char* ptr = (unsigned char*)str;
4154
4155 // GD format header for truecolor image (11 bytes)
4156 *ptr++ = (65534 >> 8) & 0xFF;
4157 *ptr++ = (65534 ) & 0xFF;
4158 *ptr++ = (width >> 8) & 0xFF;
4159 *ptr++ = (width ) & 0xFF;
4160 *ptr++ = (height>> 8) & 0xFF;
4161 *ptr++ = (height ) & 0xFF;
4162 *ptr++ = 1;
4163 *ptr++ = 255;
4164 *ptr++ = 255;
4165 *ptr++ = 255;
4166 *ptr++ = 255;
4167
4168 uint8* scrBuf = getemuscreen ? XBackBuf : XBuf;
4169
4170 for (int y=0; y < height; y++) {
4171 for (int x=0; x < width; x++) {
4172 uint8 index = scrBuf[(y)*256 + x];
4173
4174 // Write A,R,G,B (alpha=0 for us):
4175 *ptr = 0;
4176 FCEUD_GetPalette(index, ptr + 1, ptr + 2, ptr + 3);
4177 ptr += 4;
4178 }
4179 }
4180
4181 lua_pushlstring(L, str, size);
4182 delete[] str;
4183 return 1;
4184}
4185
4186// gui.opacity(number alphaValue)
4187// sets the transparency of subsequent draw calls

Callers

nothing calls this directly

Calls 3

lua_tobooleanFunction · 0.85
lua_pushlstringFunction · 0.85
FCEUD_GetPaletteFunction · 0.50

Tested by

no test coverage detected