git.y1.nz

SameBoy

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

commit c06e320b9579a5b8c1177ca1218ed8c87d57798c
parent b032b89457bc1e00a636c26eb5e0968ac77ed1ef
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sun, 29 Jan 2023 23:19:26 +0200

Fix the camera using the wrong aspect ratio on some Macs. Fix a bug that caused artifacts on the right and bottom edges of the camera image.

Diffstat:
MCocoa/Document.m14++++++++------
MCore/camera.c11+++++++++--
2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -1861,18 +1861,20 @@ static bool is_path_writeable(const char *path) NSError *error; AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo]; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice: device error: &error]; - CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions([[[device formats] firstObject] formatDescription]); + CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions([[[device formats] lastObject] formatDescription]); if (!input) { GB_camera_updated(&gb); return; } + + double ratio = MAX(130.0 / dimensions.width, 114.0 / dimensions.height); cameraOutput = [[AVCaptureStillImageOutput alloc] init]; /* Greyscale is not widely supported, so we use YUV, whose first element is the brightness. */ [cameraOutput setOutputSettings: @{(id)kCVPixelBufferPixelFormatTypeKey: @(kYUVSPixelFormat), - (id)kCVPixelBufferWidthKey: @(MAX(128, 112 * dimensions.width / dimensions.height)), - (id)kCVPixelBufferHeightKey: @(MAX(112, 128 * dimensions.height / dimensions.width)),}]; + (id)kCVPixelBufferWidthKey: @(round(dimensions.width * ratio)), + (id)kCVPixelBufferHeightKey: @(round(dimensions.height * ratio)),}]; cameraSession = [AVCaptureSession new]; @@ -1908,7 +1910,7 @@ static bool is_path_writeable(const char *path) }); } -- (uint8_t)cameraGetPixelAtX:(uint8_t)x andY:(uint8_t) y +- (uint8_t)cameraGetPixelAtX:(unsigned)x andY:(unsigned)y { if (!cameraImage) { return 0; @@ -1916,8 +1918,8 @@ static bool is_path_writeable(const char *path) uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(cameraImage); size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cameraImage); - uint8_t offsetX = (CVPixelBufferGetWidth(cameraImage) - 128) / 2; - uint8_t offsetY = (CVPixelBufferGetHeight(cameraImage) - 112) / 2; + unsigned offsetX = (CVPixelBufferGetWidth(cameraImage) - 128) / 2; + unsigned offsetY = (CVPixelBufferGetHeight(cameraImage) - 112) / 2; uint8_t ret = baseAddress[(x + offsetX) * 2 + (y + offsetY) * bytesPerRow]; return ret; diff --git a/Core/camera.c b/Core/camera.c @@ -25,10 +25,17 @@ static uint8_t generate_noise(uint8_t x, uint8_t y) static long get_processed_color(GB_gameboy_t *gb, uint8_t x, uint8_t y) { - if (x >= 128) { + if (x == 128) { + x = 127; + } + else if (x > 128) { x = 0; } - if (y >= 112) { + + if (y == 112) { + y = 111; + } + else if (y >= 112) { y = 0; }

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