Skip to content

Commit

Permalink
fix: avoid hardcoding the grabbed image format
Browse files Browse the repository at this point in the history
  • Loading branch information
tillt committed Nov 24, 2023
1 parent 7db0075 commit e4aba53
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions KompleteSynthesia/VideoController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ - (id)initWithLogViewController:(LogViewController*)lc error:(NSError**)error
screenBuffer[1] = NULL;
atomic_fetch_and(&stopMirroring, 0);
atomic_fetch_and(&mirrorActive, 0);


imageConversionTempBuffer = NULL;
imageConversionTempBufferDimensions = CGSizeMake(0,0);
imageConversionScaleBuffer = NULL;

log = lc;

usb = [[USBController alloc] initWithError:error];
Expand All @@ -60,10 +64,6 @@ - (id)initWithLogViewController:(LogViewController*)lc error:(NSError**)error
// FIXME: We don't know the resolution the MK3 screen.
_screenSize = usb.mk == 2 ? CGSizeMake(480.0f, 272.0f) : CGSizeMake(480.0f, 272.0f);

imageConversionTempBuffer = NULL;
imageConversionTempBufferDimensions = CGSizeMake(0,0);
imageConversionScaleBuffer = malloc(_screenSize.width * 4 * _screenSize.height);

// width * height * 2 (261120) + commands (36)
stream = [[NSMutableData alloc] initWithCapacity:(_screenSize.width * 2 * _screenSize.height) + 36];

Expand Down Expand Up @@ -203,8 +203,12 @@ - (void)NIImageFromCGImage:(CGImageRef)source destination:(NIImage*)destination
if (imageConversionTempBuffer != NULL) {
free(imageConversionTempBuffer);
}
if (imageConversionScaleBuffer != NULL) {
free(imageConversionScaleBuffer);
}
imageConversionTempBufferDimensions = CGSizeMake(width, height);
imageConversionTempBuffer = malloc(CGImageGetBytesPerRow(source) * height);
imageConversionScaleBuffer = malloc(CGImageGetBytesPerRow(source) * _screenSize.height);
}

CFDataRef raw = CGDataProviderCopyData(CGImageGetDataProvider(source));
Expand Down Expand Up @@ -235,7 +239,7 @@ - (void)NIImageFromCGImage:(CGImageRef)source destination:(NIImage*)destination
imageConversionScaleBuffer,
_screenSize.height,
_screenSize.width,
_screenSize.width * 4
_screenSize.width * (((unsigned int)CGImageGetBitsPerPixel(source)) >> 3)
};

vImageScale_ARGB8888(&sourceBuffer,
Expand Down

0 comments on commit e4aba53

Please sign in to comment.