2011-01-12 23:21:17 +03:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-31 22:12:00 +03:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
#import "desktop/browser.h"
|
|
|
|
#import "desktop/plotters.h"
|
2011-02-20 01:17:54 +03:00
|
|
|
#import "desktop/thumbnail.h"
|
2011-01-12 23:21:17 +03:00
|
|
|
#import "content/urldb.h"
|
2011-08-31 15:55:02 +04:00
|
|
|
#import "cocoa/plotter.h"
|
2011-01-12 23:21:17 +03:00
|
|
|
#import "image/bitmap.h"
|
|
|
|
|
|
|
|
/* In platform specific thumbnail.c. */
|
2015-03-15 03:00:45 +03:00
|
|
|
bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-02-20 15:39:23 +03:00
|
|
|
int bwidth = bitmap_get_width( bitmap );
|
|
|
|
int bheight = bitmap_get_height( bitmap );
|
2011-06-30 19:48:07 +04:00
|
|
|
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = false,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = true,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &cocoa_plotters
|
|
|
|
};
|
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
CGColorSpaceRef cspace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB );
|
|
|
|
CGContextRef bitmapContext = CGBitmapContextCreate( bitmap_get_buffer( bitmap ),
|
2011-02-20 15:39:23 +03:00
|
|
|
bwidth, bheight,
|
2011-01-25 21:48:26 +03:00
|
|
|
bitmap_get_bpp( bitmap ) * 8 / 4,
|
2011-01-12 23:21:17 +03:00
|
|
|
bitmap_get_rowstride( bitmap ),
|
|
|
|
cspace, kCGImageAlphaNoneSkipLast );
|
|
|
|
CGColorSpaceRelease( cspace );
|
|
|
|
|
|
|
|
size_t width = MIN( content_get_width( content ), 1024 );
|
2011-02-21 21:28:28 +03:00
|
|
|
size_t height = ((width * bheight) + bwidth / 2) / bwidth;
|
2011-01-12 23:21:17 +03:00
|
|
|
|
2011-02-20 15:39:23 +03:00
|
|
|
CGContextTranslateCTM( bitmapContext, 0, bheight );
|
|
|
|
CGContextScaleCTM( bitmapContext, (CGFloat)bwidth / width, -(CGFloat)bheight / height );
|
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
[NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: bitmapContext flipped: YES]];
|
2011-02-20 15:39:23 +03:00
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
thumbnail_redraw( content, width, height, &ctx );
|
2011-02-20 15:39:23 +03:00
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
[NSGraphicsContext setCurrentContext: nil];
|
|
|
|
CGContextRelease( bitmapContext );
|
2011-02-20 15:39:23 +03:00
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
bitmap_modified( bitmap );
|
2011-02-20 15:39:23 +03:00
|
|
|
|
|
|
|
return true;
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|