summaryrefslogtreecommitdiff
path: root/cocoa/thumbnail.m
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-01-12 20:21:17 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-01-12 20:21:17 +0000
commitb58dcc351f3f7ec32ecb0553436ff9ee76e52551 (patch)
treefed57c711a544fb8272423e2645c5bbf2def25d7 /cocoa/thumbnail.m
parent8c09af55681ff4d4e40eba62fca0c219443a2fc7 (diff)
downloadnetsurf-b58dcc351f3f7ec32ecb0553436ff9ee76e52551.tar.gz
netsurf-b58dcc351f3f7ec32ecb0553436ff9ee76e52551.tar.bz2
Cocoa front end (credit: Sven Weidauer)
svn path=/trunk/netsurf/; revision=11292
Diffstat (limited to 'cocoa/thumbnail.m')
-rw-r--r--cocoa/thumbnail.m61
1 files changed, 61 insertions, 0 deletions
diff --git a/cocoa/thumbnail.m b/cocoa/thumbnail.m
new file mode 100644
index 000000000..b6df608eb
--- /dev/null
+++ b/cocoa/thumbnail.m
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "desktop/browser.h"
+#import "desktop/plotters.h"
+#import "content/urldb.h"
+#import "image/bitmap.h"
+
+#import <Cocoa/Cocoa.h>
+
+/* In platform specific thumbnail.c. */
+bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap,
+ const char *url)
+{
+ CGColorSpaceRef cspace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB );
+ CGContextRef bitmapContext = CGBitmapContextCreate( bitmap_get_buffer( bitmap ),
+ bitmap_get_width( bitmap ), bitmap_get_height( bitmap ),
+ bitmap_get_bpp( bitmap ) / 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 );
+
+ CGContextTranslateCTM( bitmapContext, 0, bitmap_get_height( bitmap ) );
+ CGContextScaleCTM( bitmapContext, (CGFloat)bitmap_get_width( bitmap ) / width, -(CGFloat)bitmap_get_height( bitmap ) / height );
+
+ [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: bitmapContext flipped: YES]];
+
+ content_redraw( content, 0, 0, content_get_width( content ), content_get_height( content ),
+ 0, 0, content_get_width( content ), content_get_height( content ),
+ 1.0, 0xFFFFFFFF );
+
+ [NSGraphicsContext setCurrentContext: nil];
+ CGContextRelease( bitmapContext );
+
+ bitmap_modified( bitmap );
+
+ if (NULL != url) urldb_set_thumbnail( url, bitmap );
+
+ return true;
+
+}
+