-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathImageFilter.cpp
74 lines (59 loc) · 1.22 KB
/
ImageFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 2018-2023, Stefano Ceccherini <[email protected]>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "ImageFilter.h"
#include <Bitmap.h>
#include <View.h>
ImageFilter::ImageFilter(BRect frame, color_space colorSpace)
:
fBitmap(NULL),
fView(NULL)
{
// Bitmap and view used to convert the source bitmap
// to the correct size and depth
fBitmap = new BBitmap(frame, colorSpace, true);
fView = new BView(frame, "drawing view", B_FOLLOW_NONE, 0);
if (fBitmap->Lock()) {
fBitmap->AddChild(fView);
fBitmap->Unlock();
}
}
ImageFilter::~ImageFilter()
{
delete fBitmap;
}
BBitmap*
ImageFilter::Bitmap()
{
return fBitmap;
}
BView*
ImageFilter::View()
{
return fView;
}
// ImageFilterScale
ImageFilterScale::ImageFilterScale(BRect frame, color_space colorSpace)
:
ImageFilter(frame, colorSpace)
{
}
ImageFilterScale::~ImageFilterScale()
{
}
/* virtual */
BBitmap*
ImageFilterScale::ApplyFilter(BBitmap* bitmap)
{
// Draw scaled
if (bitmap != NULL) {
Bitmap()->Lock();
View()->DrawBitmap(bitmap, bitmap->Bounds().OffsetToCopy(B_ORIGIN),
View()->Bounds());
View()->Sync();
Bitmap()->Unlock();
delete bitmap;
}
return new BBitmap(*Bitmap());
}