mirror of
https://github.com/gligli/nulldc-360.git
synced 2025-04-02 11:11:56 -04:00
58 lines
No EOL
1.9 KiB
C
58 lines
No EOL
1.9 KiB
C
#include <png.h>
|
|
#include <sys/time.h>
|
|
#include <time/time.h>
|
|
#include <byteswap.h>
|
|
|
|
struct ati_info {
|
|
uint32_t unknown1[4];
|
|
uint32_t base;
|
|
uint32_t unknown2[8];
|
|
uint32_t width;
|
|
uint32_t height;
|
|
} __attribute__((__packed__));
|
|
|
|
void doScreenCapture(){
|
|
printf("Start Capure\n");
|
|
|
|
struct ati_info *ai = (struct ati_info*) 0xec806100ULL;
|
|
|
|
int width = ai->width;
|
|
int height = ai->height;
|
|
|
|
volatile unsigned int *screen = (unsigned int*) (long) (ai->base | 0x80000000);
|
|
|
|
unsigned int screen2[width * height];
|
|
png_bytep row_pointers[height];
|
|
|
|
int y, x;
|
|
for (y = 0; y < height; ++y) {
|
|
for (x = 0; x < width; ++x) {
|
|
unsigned int base = ((((y & ~31) * width) + (x & ~31)*32) +
|
|
(((x & 3) + ((y & 1) << 2) + ((x & 28) << 1) + ((y & 30) << 5)) ^ ((y & 8) << 2)));
|
|
screen2[y * width + x] = 0xFF | __builtin_bswap32(screen[base] >> 8);
|
|
}
|
|
row_pointers[y] = (png_bytep) (screen2 + y * width);
|
|
}
|
|
|
|
struct timeval tp;
|
|
gettimeofday(&tp, NULL);
|
|
char filename[256];
|
|
sprintf(filename, "uda:/sshot_%d.png", tp.tv_sec);
|
|
|
|
FILE *outfp = fopen(filename, "wb");
|
|
|
|
png_structp png_ptr_w = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
|
|
png_infop info_ptr_w = png_create_info_struct(png_ptr_w);
|
|
|
|
png_init_io(png_ptr_w, outfp);
|
|
png_set_IHDR(png_ptr_w, info_ptr_w, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
png_set_rows(png_ptr_w, info_ptr_w, row_pointers);
|
|
png_write_png(png_ptr_w, info_ptr_w, PNG_TRANSFORM_IDENTITY, 0);
|
|
png_write_end(png_ptr_w, info_ptr_w);
|
|
png_destroy_write_struct(&png_ptr_w, &info_ptr_w);
|
|
|
|
fclose(outfp);
|
|
|
|
printf("ScreenCapture : File saved to : %s\r\n", filename);
|
|
} |