git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

SDL/save_png/appkit.m

      1 #import <AppKit/AppKit.h>
      2 #import <SDL.h>
      3 #import "save_png.h"
      4 
      5 bool save_png(const char *filename, uint32_t width, uint32_t height, const void *pixels, SDL_PixelFormat *pixel_format)
      6 {
      7     if (pixel_format->format != SDL_PIXELFORMAT_ABGR8888 &&
      8         pixel_format->format != SDL_PIXELFORMAT_XBGR8888) {
      9         return false;
     10     }
     11     size_t stride = width * 4;
     12     
     13     @autoreleasepool {
     14         NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
     15                                                                         pixelsWide:width
     16                                                                         pixelsHigh:height
     17                                                                      bitsPerSample:8
     18                                                                    samplesPerPixel:3
     19                                                                           hasAlpha:false
     20                                                                           isPlanar:false
     21                                                                     colorSpaceName:NSDeviceRGBColorSpace
     22                                                                       bitmapFormat:0
     23                                                                        bytesPerRow:4 * width
     24                                                                       bitsPerPixel:32];
     25         memcpy(rep.bitmapData, pixels, stride * height);
     26         NSData *data = [rep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
     27         return [data writeToFile:@(filename) atomically:true];
     28     }
     29 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.