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

Commit 1559c2a

Browse files
committed
[[ Canvas ]] Fixed some syntax errors in grammar specification. Implemented path instruction parsing. Added typecheck functions for paint subtypes.
[[ Graphics ]] Added path iteration & copy subpath functions to libgraphics [[ ImageRep ]] Added pixel-data based image rep
1 parent 0a1e712 commit 1559c2a

7 files changed

Lines changed: 603 additions & 82 deletions

File tree

engine/src/image_rep.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,104 @@ void MCCachedImageRep::MoveRepToHead(MCCachedImageRep *p_rep)
498498

499499
////////////////////////////////////////////////////////////////////////////////
500500

501+
MCPixelDataImageRep::MCPixelDataImageRep(MCDataRef p_data, uint32_t p_width, uint32_t p_height, MCGPixelFormat p_format, bool p_premultiplied)
502+
{
503+
m_pixel_data = MCValueRetain(p_data);
504+
m_pixel_width = p_width;
505+
m_pixel_height = p_height;
506+
m_pixel_format = p_format;
507+
m_pixels_premultiplied = p_premultiplied;
508+
}
509+
510+
MCPixelDataImageRep::~MCPixelDataImageRep()
511+
{
512+
MCValueRelease(m_pixel_data);
513+
m_pixel_data = nil;
514+
}
515+
516+
uint32_t MCPixelDataImageRep::GetDataCompression()
517+
{
518+
return F_RLE;
519+
}
520+
521+
uindex_t MCPixelDataImageRep::GetFrameCount()
522+
{
523+
return 1;
524+
}
525+
526+
bool MCPixelDataImageRep::LoadImageFrames(MCBitmapFrame *&r_frames, uindex_t &r_frame_count, bool &r_premultiplied)
527+
{
528+
bool t_success;
529+
t_success = true;
530+
531+
MCBitmapFrame *t_frames;
532+
t_frames = nil;
533+
534+
if (t_success)
535+
t_success = MCMemoryNew(t_frames);
536+
537+
if (t_success)
538+
t_success = MCImageBitmapCreate(m_pixel_width, m_pixel_height, t_frames->image);
539+
540+
if (t_success)
541+
{
542+
uint32_t t_pixel_count;
543+
t_pixel_count = MCMin(MCDataGetLength(m_pixel_data) / sizeof(uint32_t), m_pixel_width * m_pixel_height);
544+
545+
// uint32_t t_pixel_width;
546+
// t_pixel_width = (t_pixel_count + m_pixel_height - 1) / m_pixel_height; // rounding up to nearest pixel
547+
548+
uint32_t i = 0;
549+
550+
uint32_t *t_src_ptr;
551+
t_src_ptr = (uint32_t*)MCDataGetBytePtr(m_pixel_data);
552+
553+
uint8_t *t_dst_ptr;
554+
t_dst_ptr = (uint8_t*)t_frames->image->data;
555+
for (uint32_t y = 0; y < m_pixel_height; y++)
556+
{
557+
uint32_t *t_dst_pixel;
558+
t_dst_pixel = (uint32_t*)t_dst_ptr;
559+
560+
for (uint32_t x = 0; x < m_pixel_width; x++)
561+
{
562+
// if (x < t_pixel_width && i < t_pixel_count)
563+
if (i < t_pixel_count)
564+
*t_dst_pixel++ = MCGPixelToNative(m_pixel_format, t_src_ptr[i++]);
565+
else
566+
*t_dst_pixel++ = MCGPixelPackNative(0, 0, 0, 1);
567+
}
568+
569+
t_dst_ptr += t_frames->image->stride;
570+
}
571+
}
572+
573+
if (t_success)
574+
{
575+
t_frames->duration = 0;
576+
t_frames->x_scale = 1.0;
577+
t_frames->y_scale = 1.0;
578+
579+
r_frames = t_frames;
580+
r_frame_count = 1;
581+
r_premultiplied = m_pixels_premultiplied;
582+
}
583+
else
584+
MCImageFreeFrames(t_frames, 1);
585+
586+
return t_success;
587+
}
588+
589+
bool MCPixelDataImageRep::CalculateGeometry(uint32_t &r_width, uint32_t &r_height)
590+
{
591+
r_width = m_pixel_width;
592+
r_height = m_pixel_height;
593+
594+
return true;
595+
}
596+
597+
////////////////////////////////////////////////////////////////////////////////
598+
501599
bool MCImageRepCreateReferencedWithSearchKey(MCStringRef p_filename, MCStringRef p_searchkey, MCImageRep *&r_rep)
502600
{
503601
bool t_success;
@@ -604,4 +702,22 @@ bool MCImageRepGetResampled(uint32_t p_width, uint32_t p_height, bool p_flip_hor
604702

605703
}
606704

705+
bool MCImageRepGetPixelRep(MCDataRef p_pixel_data, uint32_t p_width, uint32_t p_height, MCGPixelFormat p_format, bool p_premultiplied, MCImageRep *&r_rep)
706+
{
707+
bool t_success;
708+
t_success = true;
709+
710+
MCPixelDataImageRep *t_rep;
711+
t_rep = new MCPixelDataImageRep(p_pixel_data, p_width, p_height, p_format, p_premultiplied);
712+
713+
t_success = t_rep != nil;
714+
if (t_success)
715+
{
716+
MCCachedImageRep::AddRep(t_rep);
717+
r_rep = t_rep->Retain();
718+
}
719+
720+
return t_success;
721+
}
722+
607723
////////////////////////////////////////////////////////////////////////////////

engine/src/image_rep.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef enum
2828
kMCImageRepResident,
2929
kMCImageRepVector,
3030
kMCImageRepCompressed,
31+
kMCImageRepPixelData,
3132

3233
kMCImageRepResampled,
3334
} MCImageRepType;
@@ -400,6 +401,29 @@ class MCDensityMappedImageRep : public MCCachedImageRep
400401
MCStringRef m_filename;
401402
};
402403

404+
class MCPixelDataImageRep : public MCLoadableImageRep
405+
{
406+
public:
407+
MCPixelDataImageRep(MCDataRef p_data, uint32_t p_width, uint32_t p_height, MCGPixelFormat p_format, bool p_premultiplied);
408+
~MCPixelDataImageRep();
409+
410+
MCImageRepType GetType() { return kMCImageRepPixelData; }
411+
uint32_t GetDataCompression();
412+
uindex_t GetFrameCount();
413+
414+
protected:
415+
bool LoadImageFrames(MCBitmapFrame* &r_frames, uindex_t &r_frame_count, bool &r_premultiplied);
416+
bool CalculateGeometry(uint32_t &r_width, uint32_t &r_height);
417+
418+
//////////
419+
420+
MCDataRef m_pixel_data;
421+
uint32_t m_pixel_width;
422+
uint32_t m_pixel_height;
423+
MCGPixelFormat m_pixel_format;
424+
bool m_pixels_premultiplied;
425+
};
426+
403427
////////////////////////////////////////////////////////////////////////////////
404428

405429
bool MCImageRepCreateReferencedWithSearchKey(MCStringRef p_filename, MCStringRef p_searchkey, MCImageRep *&r_rep);

libgraphics/include/graphics.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,16 @@ MCGRectangle MCGMaskGetBounds(MCGMaskRef mask);
715715

716716
////////////////////////////////////////////////////////////////////////////////
717717

718-
typedef uint8_t MCGPathCommand;
719-
enum
718+
enum MCGPathCommand
720719
{
721720
kMCGPathCommandEnd,
722721
kMCGPathCommandMoveTo,
723722
kMCGPathCommandLineTo,
724-
kMCGPathCommandCurveTo,
723+
kMCGPathCommandCubicCurveTo,
725724
kMCGPathCommandQuadCurveTo,
726725
kMCGPathCommandCloseSubpath,
726+
727+
kMCGPathCommandCount
727728
};
728729

729730
bool MCGPathCreate(const MCGPathCommand *commands, const MCGFloat *parameters, MCGPathRef& r_path);
@@ -733,6 +734,7 @@ MCGPathRef MCGPathRetain(MCGPathRef path);
733734
void MCGPathRelease(MCGPathRef path);
734735

735736
bool MCGPathIsValid(MCGPathRef path);
737+
bool MCGPathIsEmpty(MCGPathRef path);
736738

737739
void MCGPathCopy(MCGPathRef path, MCGPathRef& r_new_path);
738740
void MCGPathCopyAndRelease(MCGPathRef path, MCGPathRef& r_new_path);
@@ -767,6 +769,9 @@ bool MCGPathTransform(MCGPathRef path, const MCGAffineTransform &p_transform);
767769

768770
bool MCGPathGetBoundingBox(MCGPathRef path, MCGRectangle &r_bounds);
769771

772+
typedef bool (*MCGPathIterateCallback)(void *p_context, MCGPathCommand p_command, MCGPoint *p_points, uint32_t p_point_count);
773+
bool MCGPathIterate(MCGPathRef p_path, MCGPathIterateCallback p_callback, void *p_context);
774+
770775
////////////////////////////////////////////////////////////////////////////////
771776

772777
bool MCGContextCreate(uint32_t width, uint32_t height, bool alpha, MCGContextRef& r_context);

0 commit comments

Comments
 (0)