[vlc-commits] [Git][videolan/vlc][master] 14 commits: macosx: Add starter VLCCompositeImageView class

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Sep 14 14:18:45 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
4b1053d4 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Add starter VLCCompositeImageView class

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
fb99327f by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Add private property in VLCCompositeImageView defining frames for subimages

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
df336be9 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Generate composited image from image array in VLCCompositeImageView

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d4fca9b1 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Provide composited image for audio groups in VLCLibraryImageCache

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
2ff7f494 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Do not use composite cover image for albums

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
50398cfb by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Move composite image generation code to NSImage extension

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d37d4dfc by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Move composited image frame grid generation to NSImage extension

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
24c8d4b4 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Generate frames for composite image grid dynamically

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
05bdc291 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Do not display duplicated album artworks in composite image

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
53765b20 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Add compositedGriditemCount property to VLCCompositeImageView

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
679342d7 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Allow for custom grid item counts in NSImage extension framesForCompositeImageGridWithImages

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
5a6fc0c5 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Generate composite image directly from VLCLibraryImageCache

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
411d32ea by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Remove now uneeded VLCCompositeImageView

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d4f742d8 by Claudio Cambra at 2023-09-14T13:58:37+00:00
macosx: Replace use of deprecated lockFocus/unlockFocus with imageWithSize and drawingHandler

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


3 changed files:

- modules/gui/macosx/extensions/NSImage+VLCAdditions.h
- modules/gui/macosx/extensions/NSImage+VLCAdditions.m
- modules/gui/macosx/library/VLCLibraryImageCache.m


Changes:

=====================================
modules/gui/macosx/extensions/NSImage+VLCAdditions.h
=====================================
@@ -28,6 +28,12 @@ NS_ASSUME_NONNULL_BEGIN
 
 + (instancetype)quickLookPreviewForLocalPath:(NSString*)path withSize:(NSSize)size;
 + (instancetype)quickLookPreviewForLocalURL:(NSURL*)url withSize:(NSSize)size;
++ (instancetype)compositeImageWithImages:(NSArray<NSImage *> * const)images
+                                  frames:(NSArray<NSValue *> * const)frames
+                                    size:(const NSSize)size;
++ (NSArray<NSValue *> *)framesForCompositeImageSquareGridWithImages:(NSArray<NSImage *> * const)images
+                                                               size:(const NSSize)size
+                                                      gridItemCount:(const NSUInteger)gridItemCount;
 
 - (instancetype)imageTintedWithColor:(NSColor *)color;
 


=====================================
modules/gui/macosx/extensions/NSImage+VLCAdditions.m
=====================================
@@ -72,6 +72,34 @@
     return image;
 }
 
++ (instancetype)compositeImageWithImages:(NSArray<NSImage *> * const)images
+                                  frames:(NSArray<NSValue *> * const)frames
+                                    size:(const NSSize)size
+{
+    return [NSImage imageWithSize:size
+                          flipped:NO
+                   drawingHandler:^BOOL(const NSRect dstRect) {
+
+        NSUInteger counter = 0;
+        for (NSValue * const rectValue in frames) {
+            if (counter >= images.count) {
+                break;
+            }
+
+            NSImage * const image = [images objectAtIndex:counter];
+            const NSRect imageRect = rectValue.rectValue;
+            [image drawInRect:imageRect
+                     fromRect:NSZeroRect
+                    operation:NSCompositingOperationOverlay
+                     fraction:1.];
+
+            counter += 1;
+        }
+
+        return YES;
+    }];
+}
+
 - (instancetype)imageTintedWithColor:(NSColor *)color
 {
     NSImage * const image = [self copy];
@@ -87,4 +115,33 @@
     return image;
 }
 
++ (NSArray<NSValue *> *)framesForCompositeImageSquareGridWithImages:(NSArray<NSImage *> * const)images
+                                                               size:(const NSSize)size
+                                                      gridItemCount:(const NSUInteger)gridItemCount
+{
+    const float sqrtAxisItemCount = sqrt(gridItemCount);
+    const float roundAxisItemCount = roundf(sqrtAxisItemCount);
+    NSAssert(sqrtAxisItemCount == roundAxisItemCount, @"Provided grid item count should be an integer square root");
+
+    // Default to just one item if there are not enough images
+    const NSUInteger actualGridItemCount = images.count >= gridItemCount ? gridItemCount : 1;
+
+    // Default to just one item if there are not enough images
+    const NSUInteger gridDivisor = actualGridItemCount > 1 ? roundAxisItemCount : 1;
+    const CGFloat itemWidth = size.width / gridDivisor;
+    const CGFloat itemHeight = size.height / gridDivisor;
+
+    NSMutableArray<NSValue *> * const rects = NSMutableArray.array;
+
+    for (NSUInteger i = 0; i < actualGridItemCount; ++i) {
+        const CGFloat xPos = (i % gridDivisor) * itemWidth;
+        const CGFloat yPos = floor(i / gridDivisor) * itemHeight;
+        const NSRect rect = NSMakeRect(xPos, yPos, itemWidth, itemHeight);
+        NSValue * const rectVal = [NSValue valueWithRect:rect];
+        [rects addObject:rectVal];
+    }
+
+    return rects.copy;
+}
+
 @end


=====================================
modules/gui/macosx/library/VLCLibraryImageCache.m
=====================================
@@ -22,6 +22,8 @@
 
 #import "VLCLibraryImageCache.h"
 
+#import "extensions/NSImage+VLCAdditions.h"
+
 #import "library/VLCInputItem.h"
 #import "library/VLCLibraryDataTypes.h"
 
@@ -33,6 +35,8 @@ NSUInteger kVLCMaximumLibraryImageCacheSize = 50;
 uint32_t kVLCDesiredThumbnailWidth = 512;
 uint32_t kVLCDesiredThumbnailHeight = 512;
 float kVLCDefaultThumbnailPosition = .15;
+const NSUInteger kVLCCompositeImageDefaultCompositedGridItemCount = 4;
+
 
 @interface VLCLibraryImageCache()
 {
@@ -160,12 +164,40 @@ float kVLCDefaultThumbnailPosition = .15;
 + (void)thumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
                withCompletion:(void(^)(const NSImage *))completionHandler
 {
-    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        NSImage * const image = [VLCLibraryImageCache thumbnailForLibraryItem:libraryItem];
-        dispatch_async(dispatch_get_main_queue(), ^{
-            completionHandler(image);
+    if ([libraryItem isKindOfClass:VLCAbstractMediaLibraryAudioGroup.class] && ![libraryItem isKindOfClass:VLCMediaLibraryAlbum.class]) {
+
+        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+            VLCAbstractMediaLibraryAudioGroup * const audioGroupItem = (VLCAbstractMediaLibraryAudioGroup *)libraryItem;
+            NSMutableArray<NSImage *> * const itemImages = NSMutableArray.array;
+            NSMutableSet<NSNumber *> * const itemAlbums = NSMutableSet.set;
+
+            [audioGroupItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem * const item) {
+                NSNumber * const albumId = @(item.albumID);
+                if ([itemAlbums containsObject:albumId]) {
+                    return;
+                }
+
+                [itemAlbums addObject:albumId];
+                NSImage * const itemImage = [VLCLibraryImageCache thumbnailForLibraryItem:item];
+                [itemImages addObject:itemImage];
+            }];
+
+            const NSSize size = NSMakeSize(kVLCDesiredThumbnailWidth, kVLCDesiredThumbnailHeight);
+            NSArray<NSValue *> * const frames = [NSImage framesForCompositeImageSquareGridWithImages:itemImages size:size gridItemCount:kVLCCompositeImageDefaultCompositedGridItemCount];
+            NSImage * const compositeImage = [NSImage compositeImageWithImages:itemImages frames:frames size:size];
+
+            dispatch_async(dispatch_get_main_queue(), ^{
+                completionHandler(compositeImage);
+            });
         });
-    });
+    } else {
+        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+            NSImage * const image = [VLCLibraryImageCache thumbnailForLibraryItem:libraryItem];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                completionHandler(image);
+            });
+        });
+    }
 }
 
 + (void)thumbnailForInputItem:(VLCInputItem *)inputItem



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/db063d7f513dde5b95ba8560bb8a0323cded738c...d4f742d8f6231fbcad004a4e4a71a0ea65d69128

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/db063d7f513dde5b95ba8560bb8a0323cded738c...d4f742d8f6231fbcad004a4e4a71a0ea65d69128
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list