diff options
author | Damiano Galassi <[email protected]> | 2021-04-13 09:17:52 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2021-04-13 09:17:52 +0200 |
commit | 6fec869301eefc2eb3d938e59f5641e9ac06662b (patch) | |
tree | 9f963e9c8a4848fef0a39682b9ec6b06a4f41f52 | |
parent | dc4afd877e52fd66b1ebdb527c7f7c33c74c8cfe (diff) |
MacGui: use new api hb_get_preview3 for previews.
-rw-r--r-- | macosx/HBCore.h | 9 | ||||
-rw-r--r-- | macosx/HBCore.m | 41 | ||||
-rw-r--r-- | macosx/HBPicture.m | 14 | ||||
-rw-r--r-- | macosx/HBPreviewController.m | 7 | ||||
-rw-r--r-- | macosx/HBPreviewGenerator.m | 15 | ||||
-rw-r--r-- | macosx/HBPreviewViewController.m | 9 |
6 files changed, 42 insertions, 53 deletions
diff --git a/macosx/HBCore.h b/macosx/HBCore.h index 5d27a20a1..0fb0ec386 100644 --- a/macosx/HBCore.h +++ b/macosx/HBCore.h @@ -177,16 +177,11 @@ typedef void (^HBCoreCompletionHandler)(HBCoreResult result); * into an CGImage. * * @param index the index of the desired image. - * @param title Handle to hb_title_t of desired title - * @param frame a HBPicture instance that describe the image's frame. - * @param deinterlace whether the preview image must be deinterlaced or not. + * @param job a HBJob instance. * * @return a CGImageRef of the wanted image, NULL if the index is out of bounds. */ -- (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index - forTitle:(HBTitle *)title - pictureFrame:(HBPicture *)frame - deinterlace:(BOOL)deinterlace CF_RETURNS_RETAINED; +- (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index job:(HBJob *)job CF_RETURNS_RETAINED; /** * Returns the counts of the available previews images. diff --git a/macosx/HBCore.m b/macosx/HBCore.m index 5f41289ef..714af12aa 100644 --- a/macosx/HBCore.m +++ b/macosx/HBCore.m @@ -331,29 +331,19 @@ typedef void (^HBCoreCleanupHandler)(void); #pragma mark - Preview images -- (CGImageRef)copyImageAtIndex:(NSUInteger)index - forTitle:(HBTitle *)title - pictureFrame:(HBPicture *)frame - deinterlace:(BOOL)deinterlace CF_RETURNS_RETAINED +- (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index job:(HBJob *)job CF_RETURNS_RETAINED { CGImageRef img = NULL; - hb_geometry_settings_t geo; - memset(&geo, 0, sizeof(geo)); - geo.geometry.width = frame.displayWidth; - geo.geometry.height = frame.height; - // ignore the par. - geo.geometry.par.num = 1; - geo.geometry.par.den = 1; - int crop[4] = {frame.cropTop, frame.cropBottom, frame.cropLeft, frame.cropRight}; - memcpy(geo.crop, crop, sizeof(int[4])); - - hb_image_t *image = hb_get_preview2(_hb_handle, title.index, (int)index, &geo, deinterlace); + hb_job_t *hb_job = [job hb_job]; + hb_dict_t *job_dict = hb_job_to_dict(hb_job); + hb_job_close(&hb_job); + hb_image_t *image = hb_get_preview3(_hb_handle, (int)index, job_dict); if (image) { // Create an CGImageRef and copy the libhb image into it. - // The image data returned by hb_get_preview2 is 4 bytes per pixel, BGRA format. + // The image data returned by hb_get_preview3 is 4 bytes per pixel, BGRA format. // Alpha is ignored. CFMutableDataRef imgData = CFDataCreateMutable(kCFAllocatorDefault, 0); CFDataSetLength(imgData, 3 * image->width * image->height); @@ -376,9 +366,9 @@ typedef void (^HBCoreCleanupHandler)(void); CGDataProviderRef provider = CGDataProviderCreateWithCFData(imgData); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNone; - CGColorSpaceRef colorSpace = copyColorSpace(title.hb_title->color_prim, - title.hb_title->color_transfer, - title.hb_title->color_matrix); + CGColorSpaceRef colorSpace = copyColorSpace(image->color_prim, + image->color_transfer, + image->color_matrix); img = CGImageCreate(image->width, image->height, @@ -399,16 +389,9 @@ typedef void (^HBCoreCleanupHandler)(void); hb_image_close(&image); } - if (img && (frame.rotate || frame.flip)) - { - CGImageRef rotatedImg = CGImageRotated(img, frame.rotate, frame.flip); - CGImageRelease(img); - return rotatedImg; - } - else - { - return img; - } + hb_value_free(&job_dict); + + return img; } - (NSUInteger)imagesCountForTitle:(HBTitle *)title diff --git a/macosx/HBPicture.m b/macosx/HBPicture.m index a1507e21c..f7149b74d 100644 --- a/macosx/HBPicture.m +++ b/macosx/HBPicture.m @@ -652,6 +652,20 @@ NSString * const HBPictureChangedNotification = @"HBPictureChangedNotification"; } } +- (void)setPaddingColorCustom:(NSString *)paddingColorCustom +{ + if (paddingColorCustom != _paddingColorCustom) + { + [[self.undo prepareWithInvocationTarget:self] setPaddingColorCustom:_paddingColorCustom]; + } + _paddingColorCustom = paddingColorCustom; + + if (!self.isValidating) + { + [self validateSettings]; + } +} + #pragma mark - Anamorphic - (void)setAnamorphicMode:(HBPictureAnarmophicMode)anamorphicMode diff --git a/macosx/HBPreviewController.m b/macosx/HBPreviewController.m index b908b52cd..81f75400d 100644 --- a/macosx/HBPreviewController.m +++ b/macosx/HBPreviewController.m @@ -481,8 +481,11 @@ if (self.generator && self.window.isVisible) { CGImageRef image = [self.generator copyImageAtIndex:idx shouldCache:YES]; - self.previewView.image = image; - CFRelease(image); + if (image) + { + self.previewView.image = image; + CFRelease(image); + } } } diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index 0e5b2b0e9..91b69177f 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -79,7 +79,7 @@ * * @param index picture index in title. */ -- (CGImageRef) copyImageAtIndex: (NSUInteger) index shouldCache: (BOOL) cache +- (nullable CGImageRef) copyImageAtIndex: (NSUInteger) index shouldCache: (BOOL) cache { if (index >= self.imagesCount) { @@ -92,13 +92,7 @@ if (!theImage) { - HBFilters *filters = self.job.filters; - BOOL deinterlace = (![filters.deinterlace isEqualToString:@"off"]); - - theImage = (CGImageRef)[self.scanCore copyImageAtIndex:index - forTitle:self.job.title - pictureFrame:self.job.picture - deinterlace:deinterlace]; + theImage = [self.scanCore copyImageAtIndex:index job:self.job]; if (cache && theImage) { // The cost is the number of pixels of the image @@ -188,10 +182,7 @@ if (image == NULL) { - image = (CGImageRef)[self.scanCore copyImageAtIndex:index - forTitle:self.job.title - pictureFrame:self.job.picture - deinterlace:NO]; + image = [self.scanCore copyImageAtIndex:index job:self.job]; CFAutorelease(image); } diff --git a/macosx/HBPreviewViewController.m b/macosx/HBPreviewViewController.m index e6bcf4cb9..c810107a8 100644 --- a/macosx/HBPreviewViewController.m +++ b/macosx/HBPreviewViewController.m @@ -182,9 +182,12 @@ It may be used under the terms of the GNU General Public License. */ if (self.generator && self.visible) { CGImageRef fPreviewImage = [self.generator copyImageAtIndex:self.selectedIndex shouldCache:YES]; - self.previewView.image = fPreviewImage; - CFRelease(fPreviewImage); - self.previewView.layer.opacity = 1; + if (fPreviewImage) + { + self.previewView.image = fPreviewImage; + CFRelease(fPreviewImage); + self.previewView.layer.opacity = 1; + } } else { |