forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.cpp
More file actions
201 lines (157 loc) · 4.61 KB
/
Copy pathimage.cpp
File metadata and controls
201 lines (157 loc) · 4.61 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode 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 LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include "graphics.h"
#include "graphics-internal.h"
////////////////////////////////////////////////////////////////////////////////
static void MCGImageDestroy(MCGImageRef self)
{
if (self != NULL)
{
if (self -> bitmap != NULL)
delete self -> bitmap;
MCMemoryDelete(self);
}
}
bool MCGImageCreateWithSkBitmap(const SkBitmap &p_bitmap, MCGImageRef &r_image)
{
bool t_success;
t_success = true;
__MCGImage *t_image;
t_image = nil;
if (t_success)
t_success = MCMemoryNew(t_image);
SkBitmap *t_bitmap;
t_bitmap = nil;
if (t_success)
{
t_bitmap = new SkBitmap(p_bitmap);
t_success = nil != t_bitmap;
}
if (t_success)
{
t_image -> bitmap = t_bitmap;
t_image -> is_valid = true;
t_image -> references = 1;
r_image = t_image;
}
else
{
if (t_bitmap != nil)
delete t_bitmap;
MCMemoryDelete(t_image);
}
return t_success;
}
bool MCGImageCreateWithRaster(const MCGRaster &p_raster, MCGPixelOwnershipType p_ownership, MCGImageRef &r_image)
{
bool t_success;
t_success = true;
__MCGImage *t_image;
t_image = nil;
SkBitmap t_bitmap;
if (t_success)
t_success = MCGRasterToSkBitmap(p_raster, p_ownership, t_bitmap);
if (t_success)
t_success = MCGImageCreateWithSkBitmap(t_bitmap, t_image);
if (t_success)
r_image = t_image;
else
MCMemoryDelete(t_image);
return t_success;
}
bool MCGImageCreateWithRasterAndRelease(const MCGRaster &p_raster, MCGImageRef &r_image)
{
return MCGImageCreateWithRaster(p_raster, kMCGPixelOwnershipTypeTake, r_image);
}
bool MCGImageCreateWithRasterNoCopy(const MCGRaster& p_raster, MCGImageRef& r_image)
{
return MCGImageCreateWithRaster(p_raster, kMCGPixelOwnershipTypeBorrow, r_image);
}
bool MCGImageCreateWithRaster(const MCGRaster& p_raster, MCGImageRef& r_image)
{
return MCGImageCreateWithRaster(p_raster, kMCGPixelOwnershipTypeCopy, r_image);
}
bool MCGImageGetRaster(MCGImageRef p_image, MCGRaster &r_raster)
{
if (p_image == nil)
return false;
__MCGImage *t_image = (__MCGImage*)p_image;
if (!t_image->is_valid || t_image->bitmap == nil)
return false;
// IM-2013-06-18: lock pixels here to force skia to update the pixel ptr
// from the bitmap's pixel ref
t_image->bitmap->lockPixels();
r_raster.format = MCGRasterFormatFromSkBitmapConfig(t_image->bitmap->config());
r_raster.width = t_image->bitmap->width();
r_raster.height = t_image->bitmap->height();
r_raster.pixels = t_image->bitmap->getPixels();
r_raster.stride =t_image->bitmap->rowBytes();
t_image->bitmap->unlockPixels();
return true;
}
bool MCGImageCreateWithData(const void *p_bytes, uindex_t p_byte_count, MCGImageRef& r_image)
{
// TODO: Implement
return false;
}
bool MCGImageCreateWithFilename(const char *p_filename, MCGImageRef& r_image)
{
// TODO: Implement
return false;
}
////////////////////////////////////////////////////////////////////////////////
MCGImageRef MCGImageRetain(MCGImageRef self)
{
if (self != NULL)
self -> references++;
return self;
}
void MCGImageRelease(MCGImageRef self)
{
if (self != NULL)
{
self -> references--;
if (self -> references <= 0)
MCGImageDestroy(self);
}
}
////////////////////////////////////////////////////////////////////////////////
bool MCGImageIsValid(MCGImageRef self)
{
return self != NULL && self -> is_valid;
}
////////////////////////////////////////////////////////////////////////////////
int32_t MCGImageGetWidth(MCGImageRef self)
{
return self -> bitmap -> width();
}
int32_t MCGImageGetHeight(MCGImageRef self)
{
return self -> bitmap -> height();
}
MCGSize MCGImageGetSize(MCGImageRef self)
{
MCGSize t_size;
t_size . width = 0;
t_size . height = 0;
if (!MCGImageIsValid(self))
return t_size;
t_size . width = (MCGFloat) self -> bitmap -> width();
t_size . height = (MCGFloat) self -> bitmap -> height();
return t_size;
}
////////////////////////////////////////////////////////////////////////////////
bool MCGImageIsOpaque(MCGImageRef self)
{
return self != nil && self -> bitmap -> isOpaque();
}
////////////////////////////////////////////////////////////////////////////////