2008-06-03 23:07:09 +04:00
|
|
|
/*
|
2008-06-07 05:13:07 +04:00
|
|
|
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
|
2008-06-03 23:07:09 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Page thumbnail creation (implementation).
|
|
|
|
*
|
|
|
|
* Thumbnails are created by setting the current drawing contexts to a BView
|
|
|
|
* attached to the BBitmap we are passed, and plotting the page at a small
|
|
|
|
* scale.
|
|
|
|
*/
|
|
|
|
|
2008-08-13 23:35:41 +04:00
|
|
|
#define __STDBOOL_H__ 1
|
2008-06-03 23:07:09 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <Bitmap.h>
|
|
|
|
#include <View.h>
|
|
|
|
extern "C" {
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "render/font.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
}
|
|
|
|
#include "beos/beos_scaffolding.h"
|
|
|
|
#include "beos/beos_plotters.h"
|
|
|
|
#include "beos/beos_bitmap.h"
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
// Zeta PRIVATE: in libzeta for now.
|
|
|
|
extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap);
|
|
|
|
|
2008-10-02 18:10:52 +04:00
|
|
|
#warning XXX do we need to set bitmap:shadow ?
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
/**
|
|
|
|
* Create a thumbnail of a page.
|
|
|
|
*
|
|
|
|
* \param content content structure to thumbnail
|
|
|
|
* \param bitmap the bitmap to draw to
|
|
|
|
* \param url the URL the thumnail belongs to, or NULL
|
|
|
|
*/
|
|
|
|
bool thumbnail_create(struct content *content, struct bitmap *bitmap,
|
|
|
|
const char *url)
|
|
|
|
{
|
2008-10-02 00:44:39 +04:00
|
|
|
BBitmap *thumbnail;
|
|
|
|
BBitmap *small;
|
|
|
|
BBitmap *big;
|
|
|
|
BView *oldView;
|
|
|
|
BView *view;
|
|
|
|
BView *thumbView;
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
int depth;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
assert(content);
|
|
|
|
assert(bitmap);
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
thumbnail = nsbeos_bitmap_get_primary(bitmap);
|
|
|
|
width = thumbnail->Bounds().Width();
|
|
|
|
height = thumbnail->Bounds().Height();
|
|
|
|
depth = 32;
|
|
|
|
//depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
LOG(("Trying to create a thumbnail bitmap %dx%d for a content of %dx%d@%d",
|
|
|
|
width, height,
|
2008-06-03 23:07:09 +04:00
|
|
|
content->width, content->width, depth));
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
BRect contentRect(0, 0, content->width - 1, content->width - 1);
|
|
|
|
big = new BBitmap(contentRect,
|
|
|
|
B_BITMAP_ACCEPTS_VIEWS, B_RGB32);
|
|
|
|
|
|
|
|
if (big->InitCheck() < B_OK) {
|
|
|
|
delete big;
|
2008-06-03 23:07:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
small = new BBitmap(thumbnail->Bounds(),
|
|
|
|
B_BITMAP_ACCEPTS_VIEWS, B_RGB32);
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
if (small->InitCheck() < B_OK) {
|
|
|
|
delete small;
|
|
|
|
delete big;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX: _lock ?
|
|
|
|
// backup the current gc
|
|
|
|
oldView = nsbeos_current_gc();
|
|
|
|
|
|
|
|
view = new BView(contentRect, "thumbnailer",
|
|
|
|
B_FOLLOW_NONE, B_WILL_DRAW);
|
|
|
|
big->AddChild(view);
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
thumbView = new BView(small->Bounds(), "thumbnail",
|
|
|
|
B_FOLLOW_NONE, B_WILL_DRAW);
|
|
|
|
small->AddChild(thumbView);
|
|
|
|
|
|
|
|
view->LockLooper();
|
|
|
|
|
|
|
|
/* impose our view on the content... */
|
|
|
|
nsbeos_current_gc_set(view);
|
|
|
|
|
|
|
|
plot = nsbeos_plotters;
|
2008-06-03 23:07:09 +04:00
|
|
|
nsbeos_plot_set_scale(1.0);
|
|
|
|
|
|
|
|
plot.fill(0, 0, content->width, content->width, 0xffffffff);
|
|
|
|
|
|
|
|
/* render the content */
|
|
|
|
content_redraw(content, 0, 0, content->width, content->width,
|
|
|
|
0, 0, content->width, content->width, 1.0, 0xFFFFFF);
|
2008-10-02 00:44:39 +04:00
|
|
|
|
|
|
|
view->Sync();
|
|
|
|
view->UnlockLooper();
|
|
|
|
|
|
|
|
// restore the current gc
|
|
|
|
nsbeos_current_gc_set(oldView);
|
|
|
|
|
|
|
|
|
|
|
|
// now scale it down
|
|
|
|
//XXX: use Zeta's bilinear scaler ?
|
|
|
|
//#ifdef B_ZETA_VERSION
|
|
|
|
// err = ScaleBitmap(*shot, *scaledBmp);
|
|
|
|
//#else
|
|
|
|
thumbView->LockLooper();
|
|
|
|
thumbView->DrawBitmap(big, big->Bounds(), small->Bounds());
|
|
|
|
thumbView->Sync();
|
|
|
|
thumbView->UnlockLooper();
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
small->LockBits();
|
|
|
|
thumbnail->LockBits();
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
// copy it to the bitmap
|
|
|
|
memcpy(thumbnail->Bits(), small->Bits(), thumbnail->BitsLength());
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
thumbnail->UnlockBits();
|
|
|
|
small->UnlockBits();
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
/* register the thumbnail with the URL */
|
|
|
|
if (url)
|
|
|
|
urldb_set_thumbnail(url, bitmap);
|
|
|
|
|
|
|
|
bitmap_modified(bitmap);
|
|
|
|
|
2008-10-02 00:44:39 +04:00
|
|
|
// cleanup
|
|
|
|
small->RemoveChild(thumbView);
|
|
|
|
delete thumbView;
|
|
|
|
delete small;
|
|
|
|
big->RemoveChild(view);
|
|
|
|
delete view;
|
|
|
|
delete big;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|