From a06b4b4302acdb1406fa9a5f88f5439675598cd4 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 20 Feb 2011 12:39:23 +0000 Subject: Port cocoa front end to use thumbnail_redraw(). Note: untested. svn path=/trunk/netsurf/; revision=11720 --- cocoa/thumbnail.m | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'cocoa/thumbnail.m') diff --git a/cocoa/thumbnail.m b/cocoa/thumbnail.m index 26f1a7a65..0ec66b52a 100644 --- a/cocoa/thumbnail.m +++ b/cocoa/thumbnail.m @@ -28,41 +28,36 @@ bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, const char *url) { + int bwidth = bitmap_get_width( bitmap ); + int bheight = bitmap_get_height( bitmap ); CGColorSpaceRef cspace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ); CGContextRef bitmapContext = CGBitmapContextCreate( bitmap_get_buffer( bitmap ), - bitmap_get_width( bitmap ), bitmap_get_height( bitmap ), + bwidth, bheight, bitmap_get_bpp( bitmap ) * 8 / 4, bitmap_get_rowstride( bitmap ), cspace, kCGImageAlphaNoneSkipLast ); CGColorSpaceRelease( cspace ); - size_t width = MIN( content_get_width( content ), 1024 ); - size_t height = MIN( content_get_height( content ), 768 ); - - struct rect clip; - clip.x0 = 0; - clip.y0 = 0; - clip.x1 = content_get_width( content ); - clip.y1 = content_get_height( content ); - - CGContextTranslateCTM( bitmapContext, 0, bitmap_get_height( bitmap ) ); - CGContextScaleCTM( bitmapContext, (CGFloat)bitmap_get_width( bitmap ) / width, -(CGFloat)bitmap_get_height( bitmap ) / height ); + size_t height = ((width * bheight) + bwidth / 2)) / bwidth; + CGContextTranslateCTM( bitmapContext, 0, bheight ); + CGContextScaleCTM( bitmapContext, (CGFloat)bwidth / width, -(CGFloat)bheight / height ); + [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: bitmapContext flipped: YES]]; - - content_redraw( content, 0, 0, content_get_width( content ), content_get_height( content ), - &clip, - 1.0, 0xFFFFFFFF ); - + + /* todo: ??? set plot scale according to the scale the thumbnail will be + * rendered at, by calling thumbnail_get_redraw_scale(). ??? */ + + thumbnail_redraw( content, width, height ); + [NSGraphicsContext setCurrentContext: nil]; CGContextRelease( bitmapContext ); - + bitmap_modified( bitmap ); - + if (NULL != url) urldb_set_thumbnail( url, bitmap ); - - return true; + return true; } -- cgit v1.2.3