Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit e1b6687

Browse files
committed
[[ ImageRepUpdate ]] Replace MCImageBitmap with MCGImageRef in frames locked from MCImageReps
[[ ImageRepUpdate ]] Split unpremultiplied bitmap locking to separate methods [[ ImageRepUpdate ]] Replace MCImageBitmap in MCImageDescriptor struct with MCGImageRef
1 parent 035eae3 commit e1b6687

26 files changed

+767
-356
lines changed

engine/src/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ struct MCImageDescriptor
7979
// IM-2013-07-19: [[ ResIndependence ]] add scale factor field for scaled images
8080
MCGFloat scale_factor;
8181

82-
// The image bitmap
83-
MCImageBitmap *bitmap;
82+
// IM-2014-06-12: [[ ImageRepUpdate ]] Update image to be an MCGImage
83+
MCGImageRef image;
8484

8585
// The image source data
8686
MCImageDataType data_type;

engine/src/customprinter.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ bool MCCustomMetaContext::candomark(MCMark *p_mark)
264264
// Devices have to support unmasked images (otherwise we couldn't
265265
// rasterize!).
266266
bool t_mask, t_alpha;
267-
t_mask = MCImageBitmapHasTransparency(p_mark -> image . descriptor . bitmap, t_alpha);
267+
t_mask = !MCGImageIsOpaque(p_mark->image.descriptor.image);
268+
t_alpha = t_mask && MCGImageHasPartialTransparency(p_mark->image.descriptor.image);
268269

269270
if (!t_mask)
270271
return true;
@@ -494,23 +495,29 @@ void MCCustomMetaContext::doimagemark(MCMark *p_mark)
494495
}
495496

496497
uint2 t_img_width, t_img_height;
497-
MCImageBitmap *t_img_bitmap = nil;
498-
t_img_bitmap = p_mark -> image . descriptor . bitmap;
499-
t_img_width = t_img_bitmap -> width;
500-
t_img_height = t_img_bitmap -> height;
498+
MCGRaster t_raster;
501499

502500
if (!m_execute_error)
503501
{
502+
if (!MCGImageGetRaster(p_mark->image.descriptor.image, t_raster))
503+
m_execute_error = true;
504+
}
505+
506+
if (!m_execute_error)
507+
{
508+
t_img_width = t_raster.width;
509+
t_img_height = t_raster.height;
510+
504511
// Fill in the printer image info
505512
MCCustomPrinterImage t_image;
506513
if (t_image_type == kMCCustomPrinterImageNone)
507514
{
508515
bool t_mask, t_alpha;
509-
t_mask = MCImageBitmapHasTransparency(t_img_bitmap, t_alpha);
510-
t_image . type = t_alpha ? kMCCustomPrinterImageRawARGB : (t_mask ? kMCCustomPrinterImageRawMRGB : kMCCustomPrinterImageRawXRGB);
511-
t_image . id = (uint32_t)(intptr_t)t_img_bitmap;
512-
t_image . data = t_img_bitmap -> data;
513-
t_image . data_size = t_img_bitmap -> stride * t_img_height;
516+
t_mask = !MCGImageIsOpaque(p_mark->image.descriptor.image);
517+
t_alpha = t_mask && MCGImageHasPartialTransparency(p_mark->image.descriptor.image);
518+
t_image . id = (uint32_t)(intptr_t)p_mark->image.descriptor.image;
519+
t_image . data = t_raster.pixels;
520+
t_image . data_size = t_raster.stride * t_img_height;
514521
}
515522
else
516523
{

engine/src/graphicscontext.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,6 @@ void MCGraphicsContext::draweps(real8 sx, real8 sy, int2 angle, real8 xscale, re
11571157

11581158
void MCGraphicsContext::drawimage(const MCImageDescriptor& p_image, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, int2 dy)
11591159
{
1160-
MCGRaster t_raster;
1161-
t_raster = MCImageBitmapGetMCGRaster(p_image.bitmap, true);
1162-
11631160
MCGRectangle t_clip;
11641161
t_clip . origin . x = dx;
11651162
t_clip . origin . y = dy;
@@ -1169,8 +1166,8 @@ void MCGraphicsContext::drawimage(const MCImageDescriptor& p_image, int2 sx, int
11691166
MCGRectangle t_dest;
11701167
t_dest.origin.x = dx - sx;
11711168
t_dest.origin.y = dy - sy;
1172-
t_dest.size.width = t_raster.width;
1173-
t_dest.size.height = t_raster.height;
1169+
t_dest.size.width = MCGImageGetWidth(p_image.image);
1170+
t_dest.size.height = MCGImageGetHeight(p_image.image);
11741171

11751172
MCGContextSave(m_gcontext);
11761173
MCGContextClipToRect(m_gcontext, t_clip);
@@ -1193,7 +1190,7 @@ void MCGraphicsContext::drawimage(const MCImageDescriptor& p_image, int2 sx, int
11931190
MCGContextTranslateCTM(m_gcontext, -t_dest.origin.x, -t_dest.origin.y);
11941191
}
11951192

1196-
MCGContextDrawPixels(m_gcontext, t_raster, t_dest, p_image.filter);
1193+
MCGContextDrawImage(m_gcontext, p_image.image, t_dest, p_image.filter);
11971194
MCGContextRestore(m_gcontext);
11981195
}
11991196

engine/src/idraw.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
8888
// source images from flushing everything else out of the cache.
8989
bool t_success = true;
9090

91-
MCImageFrame *t_frame = nil;
91+
MCGImageFrame *t_frame = nil;
9292

9393
bool t_printer = dc->gettype() == CONTEXT_TYPE_PRINTER;
9494
bool t_update = !((state & CS_SIZE) && (state & CS_EDITED));
@@ -138,7 +138,7 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
138138

139139
// IM-2014-01-31: [[ HiDPI ]] Get the appropriate image for the combined
140140
// context device & image transforms
141-
t_success = t_rep->LockImageFrame(currentframe, true, t_device_scale, t_frame);
141+
t_success = t_rep->LockImageFrame(currentframe, t_device_scale, t_frame);
142142
if (t_success)
143143
{
144144
MCImageDescriptor t_image;
@@ -169,7 +169,7 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
169169
break;
170170
}
171171

172-
t_image . bitmap = t_frame->image;
172+
t_image . image = t_frame->image;
173173

174174
if (t_printer && m_rep->GetType() == kMCImageRepResident)
175175
{
@@ -202,8 +202,8 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
202202

203203
if (state & CS_DO_START)
204204
{
205-
MCImageFrame *t_frame = nil;
206-
if (m_rep->LockImageFrame(currentframe, true, getdevicescale(), t_frame))
205+
MCGImageFrame *t_frame = nil;
206+
if (m_rep->LockImageFrame(currentframe, getdevicescale(), t_frame))
207207
{
208208
MCscreen->addtimer(this, MCM_internal, t_frame->duration);
209209
m_rep->UnlockImageFrame(currentframe, t_frame);
@@ -401,15 +401,22 @@ void MCImage::magredrawrect(MCContext *dest_context, const MCRectangle &drect)
401401
// OVERHAUL - REVISIT: may be able to use scaling transform with nearest filter
402402
// instead of manually scaling image
403403

404+
MCGImageRef t_line_img;
405+
t_line_img = nil;
406+
407+
/* UNCHECKED */ MCGImageCreateWithRasterNoCopy(MCImageBitmapGetMCGRaster(t_line, true), t_line_img);
408+
404409
// Render the scanline into the destination context.
405410
MCImageDescriptor t_image;
406411
memset(&t_image, 0, sizeof(MCImageDescriptor));
407-
t_image . bitmap = t_line;
412+
t_image . image = t_line_img;
408413

409414
dest_context -> drawimage(t_image, 0, 0, linewidth, MCmagnification, 0, dy);
410415

411416
dy += MCmagnification;
412417
yoffset += t_magimage->stride;
418+
419+
MCGImageRelease(t_line_img);
413420
}
414421

415422
MCImageFreeBitmap(t_line);

engine/src/ifile.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ void MCImage::recompress()
103103
flags &= ~F_NEED_FIXING;
104104
}
105105

106-
bool MCImageDecompress(MCImageCompressedBitmap *p_compressed, MCImageFrame *&r_frames, uindex_t &r_frame_count)
106+
bool MCImageDecompress(MCImageCompressedBitmap *p_compressed, MCBitmapFrame *&r_frames, uindex_t &r_frame_count)
107107
{
108108
bool t_success = true;
109109

110110
IO_handle t_stream = nil;
111-
MCImageFrame *t_frames = nil;
111+
MCBitmapFrame *t_frames = nil;
112112
uindex_t t_frame_count = 1;
113113

114114
// create single frame for non-animated formats
@@ -171,24 +171,15 @@ bool MCImage::decompressbrush(MCGImageRef &r_brush)
171171

172172
bool t_success = true;
173173

174-
MCImageFrame *t_frame = nil;
174+
MCGImageFrame *t_frame = nil;
175175

176176
// IM-2013-10-30: [[ FullscreenMode ]] REVISIT: We try here to acquire the brush
177177
// bitmap at 1.0 scale, but currently ignore the set density value of the returned frame.
178178
// We may have to add support for hi-res brushes OR scale the resulting bitmap appropriately.
179-
t_success = m_rep->LockImageFrame(0, true, 1.0, t_frame);
179+
t_success = m_rep->LockImageFrame(0, 1.0, t_frame);
180180

181181
if (t_success)
182-
{
183-
MCGRaster t_raster;
184-
t_raster.width = t_frame->image->width;
185-
t_raster.height = t_frame->image->height;
186-
t_raster.stride = t_frame->image->stride;
187-
t_raster.format = MCImageBitmapHasTransparency(t_frame->image) ? kMCGRasterFormat_ARGB : kMCGRasterFormat_xRGB;
188-
t_raster.pixels = t_frame->image->data;
189-
190-
t_success = MCGImageCreateWithRaster(t_raster, r_brush);
191-
}
182+
r_brush = MCGImageRetain(t_frame->image);
192183

193184
m_rep->UnlockImageFrame(0, t_frame);
194185

@@ -202,8 +193,8 @@ void MCImagePrepareRepForDisplayAtDensity(MCImageRep *p_rep, MCGFloat p_density)
202193
/* OVERHAUL - REVISIT: for the moment, prepared images are premultiplied
203194
* as we expect them to be rendered, but if not then this is actually
204195
* causing more work to be done than needed */
205-
MCImageFrame *t_frame = nil;
206-
p_rep->LockImageFrame(0, true, p_density, t_frame);
196+
MCGImageFrame *t_frame = nil;
197+
p_rep->LockImageFrame(0, p_density, t_frame);
207198
p_rep->UnlockImageFrame(0, t_frame);
208199
}
209200
}

engine/src/igif.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int gif_readFunc(GifFileType *p_gif, GifByteType *p_buffer, int p_byte_count)
209209
return t_byte_count;
210210
}
211211

212-
bool MCImageDecodeGIF(IO_handle p_stream, MCImageFrame *&r_frames, uindex_t &r_frame_count)
212+
bool MCImageDecodeGIF(IO_handle p_stream, MCBitmapFrame *&r_frames, uindex_t &r_frame_count)
213213
{
214214
bool t_success = true;
215215

@@ -224,7 +224,7 @@ bool MCImageDecodeGIF(IO_handle p_stream, MCImageFrame *&r_frames, uindex_t &r_f
224224
MCRectangle t_disposal_region;
225225

226226
// The list of frames.
227-
MCImageFrame *t_frames = nil;
227+
MCBitmapFrame *t_frames = nil;
228228

229229
if (nil == (t_gif = DGifOpen(p_stream, gif_readFunc, &t_err)))
230230
return false;

engine/src/iimport.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,10 @@ bool MCImageBitmapApplyMask(MCImageBitmap *p_bitmap, MCImageBitmap *p_mask)
150150
}
151151

152152
// decode image data to a series of frames, ignoring all the other bits & pieces
153-
bool MCImageDecode(IO_handle p_stream, MCImageFrame *&r_frames, uindex_t &r_frame_count)
153+
bool MCImageDecode(IO_handle p_stream, MCBitmapFrame *&r_frames, uindex_t &r_frame_count)
154154
{
155155
bool t_success = true;
156156

157-
MCImageFrame *t_frames = nil;
158-
uindex_t t_frame_count = 0;
159-
160157
MCImageBitmap *t_bitmap = nil;
161158
MCImageCompressedBitmap *t_compressed = nil;
162159

@@ -189,7 +186,7 @@ bool MCImageDecode(IO_handle p_stream, MCImageFrame *&r_frames, uindex_t &r_fram
189186
return t_success;
190187
}
191188

192-
bool MCImageDecode(const uint8_t *p_data, uindex_t p_size, MCImageFrame *&r_frames, uindex_t &r_frame_count)
189+
bool MCImageDecode(const uint8_t *p_data, uindex_t p_size, MCBitmapFrame *&r_frames, uindex_t &r_frame_count)
193190
{
194191
bool t_success = true;
195192

0 commit comments

Comments
 (0)