Browse Source

phone library: use optimized code path for label thumbnails

Felix Paul Kühne 11 years ago
parent
commit
845caab572
1 changed files with 3 additions and 35 deletions
  1. 3 35
      Sources/VLCPlaylistTableViewCell.m

+ 3 - 35
Sources/VLCPlaylistTableViewCell.m

@@ -99,42 +99,10 @@
         [self _configureForFolder:mediaObject];
 
         if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
-            NSUInteger fileNumber = [mediaObject.files count] > 4 ? 4 : [mediaObject.files count];
-            if (fileNumber == 0) {
+            if (mediaObject.files.count == 0)
                 self.thumbnailView.image = [UIImage imageNamed:@"folderIcon"];
-            } else {
-                NSArray *files = [mediaObject.files allObjects];
-                CGSize frameSize = self.thumbnailView.frame.size;
-                UIImage *displayedImage;
-                UIGraphicsBeginImageContext(frameSize);
-                for (NSUInteger i = 0; i < fileNumber; i++) {
-                    MLFile *file =  [files objectAtIndex:i];
-                    displayedImage = [VLCThumbnailsCache thumbnailForMediaFile:file];
-
-                    CGContextRef context = UIGraphicsGetCurrentContext();
-                    CGFloat imagePartWidth = (frameSize.width / fileNumber);
-                    //calculate imagesize to fit to the framewidth
-                    CGFloat ratio = frameSize.width / displayedImage.size.width;
-                    CGSize calculatedImageSize = CGSizeMake(displayedImage.size.width * ratio, displayedImage.size.height * ratio);
-                    //the rect in which the image should be drawn
-                    CGRect clippingRect = CGRectMake(imagePartWidth * i, 0, imagePartWidth, frameSize.height);
-                    CGContextSaveGState(context);
-                    CGContextClipToRect(context, clippingRect);
-                    //take the center of the clippingRect and calculate the offset from the original center
-                    CGFloat centerOffsetX = (imagePartWidth * i + imagePartWidth / 2) - frameSize.width / 2;
-                    //offset to center vertical
-                    CGFloat centerOffsetY = (frameSize.height - calculatedImageSize.height) / 2;
-                    //shift the rect to draw the middle of the image in the clippingrect
-                    CGRect drawingRect = CGRectMake(centerOffsetX, centerOffsetY, calculatedImageSize.width, calculatedImageSize.height);
-
-                    [displayedImage drawInRect:drawingRect];
-                    //get rid of the old clippingRect
-                    CGContextRestoreGState(context);
-                }
-                displayedImage = UIGraphicsGetImageFromCurrentImageContext();
-                UIGraphicsEndImageContext();
-                self.thumbnailView.image = displayedImage;
-            }
+            else
+                self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject ofSize:self.thumbnailView.frame.size];
         }
     } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
         MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;