// decode image data to a series of frames, ignoring all the other bits & pieces bool MCImageDecode(IO_handle p_stream, MCImageFrame *&r_frames, uindex_t &r_frame_count) { bool t_success = true; MCImageFrame *t_frames = nil; uindex_t t_frame_count = 0; MCImageBitmap *t_bitmap = nil; MCImageCompressedBitmap *t_compressed = nil; MCPoint t_hotspot; char *t_name = nil; if (t_success) t_success = MCImageImport(p_stream, nil, t_hotspot, t_name, t_compressed, t_bitmap); if (t_success) { if (t_compressed != nil) t_success = MCImageDecompress(t_compressed, r_frames, r_frame_count); else { t_success = MCMemoryNewArray(1, r_frames); if (t_success) { r_frames[0].image = t_bitmap; t_bitmap = nil; r_frame_count = 1; } } } MCImageFreeCompressedBitmap(t_compressed); MCImageFreeBitmap(t_bitmap); MCCStringFree(t_name); return t_success; }
bool MCEncodedImageRep::LoadImageFrames(MCImageFrame *&r_frames, uindex_t &r_frame_count, bool &r_frames_premultiplied) { bool t_success = true; // IM-2013-02-18 - switching this back to using MCImageImport as we need to // determine the compression type for m_compression IO_handle t_stream = nil; IO_handle t_mask_stream = nil; MCImageCompressedBitmap *t_compressed = nil; MCImageBitmap *t_bitmap = nil; MCPoint t_hotspot = {1, 1}; char *t_name = nil; t_success = GetDataStream(t_stream) && MCImageImport(t_stream, t_mask_stream, t_hotspot, t_name, t_compressed, t_bitmap); if (t_stream != nil) MCS_close(t_stream); MCImageFrame *t_frames; t_frames = nil; uindex_t t_frame_count; t_frame_count = 0; if (t_success) { if (t_compressed != nil) t_success = MCImageDecompress(t_compressed, t_frames, t_frame_count); else { t_success = MCMemoryNewArray(1, t_frames); if (t_success) { t_frames[0].image = t_bitmap; t_frames[0].density = 1.0; t_bitmap = nil; t_frame_count = 1; } } } if (t_success) { m_width = t_frames[0].image->width; m_height = t_frames[0].image->height; if (t_compressed != nil) m_compression = t_compressed->compression; m_have_geometry = true; r_frames = t_frames; r_frame_count = t_frame_count; r_frames_premultiplied = false; } MCCStringFree(t_name); MCImageFreeBitmap(t_bitmap); MCImageFreeCompressedBitmap(t_compressed); return t_success; }
MCCompressedImageRep::~MCCompressedImageRep() { MCImageFreeCompressedBitmap(m_compressed); }
IO_stat MCImage::import(MCStringRef newname, IO_handle stream, IO_handle mstream) { bool t_success = true; MCImageCompressedBitmap *t_compressed = nil; MCImageBitmap *t_bitmap = nil; MCStringRef t_name = nil; MCPoint t_hotspot = {1, 1}; t_success = MCImageImport(stream, mstream, t_hotspot, t_name, t_compressed, t_bitmap); if (t_success) { if (t_compressed == nil) t_success = setbitmap(t_bitmap, 1.0); else t_success = setcompressedbitmap(t_compressed); } MCImageFreeCompressedBitmap(t_compressed); MCImageFreeBitmap(t_bitmap); uindex_t t_width, t_height; if (t_success) t_success = getsourcegeometry(t_width, t_height); if (t_success) { xhot = t_hotspot.x; yhot = t_hotspot.y; bool t_resize = true; t_resize = !(flags & F_LOCK_LOCATION); if (t_resize) { rect.width = t_width; rect.height = t_height; } if (m_rep->GetFrameCount() > 1) { if ((flags & F_REPEAT_COUNT) == 0) repeatcount = -1; irepeatcount = repeatcount; state |= CS_DO_START; } if (isunnamed() && t_name != nil) { MCNewAutoNameRef t_name_nameref; /* UNCHECKED */ MCNameCreate(t_name, &t_name_nameref); setname(*t_name_nameref); } if (isunnamed() && newname != nil) { MCNewAutoNameRef t_name_nameref; uindex_t t_offset; if (MCStringLastIndexOfChar(newname, PATH_SEPARATOR, UINDEX_MAX, kMCCompareExact, t_offset)) { /* UNCHECKED */ MCStringCopySubstring(newname, MCRangeMakeMinMax(t_offset + 1, MCStringGetLength(newname)), t_name); /* UNCHECKED */ MCNameCreate(t_name, &t_name_nameref); } else /* UNCHECKED */ MCNameCreate(newname, &t_name_nameref); setname(*t_name_nameref); } } MCValueRelease(t_name); return t_success ? IO_NORMAL : IO_ERROR; }
IO_stat MCImage::import(const char *newname, IO_handle stream, IO_handle mstream) { bool t_success = true; MCImageCompressedBitmap *t_compressed = nil; MCImageBitmap *t_bitmap = nil; char *t_name = nil; MCPoint t_hotspot = {1, 1}; t_success = MCImageImport(stream, mstream, t_hotspot, t_name, t_compressed, t_bitmap); if (t_success) { if (t_compressed == nil) t_success = setbitmap(t_bitmap); else t_success = setcompressedbitmap(t_compressed); } MCImageFreeCompressedBitmap(t_compressed); MCImageFreeBitmap(t_bitmap); uindex_t t_width, t_height; if (t_success) t_success = m_rep->GetGeometry(t_width, t_height); if (t_success) { xhot = t_hotspot.x; yhot = t_hotspot.y; bool t_resize = true; t_resize = !(flags & F_LOCK_LOCATION); if (t_resize) { rect.width = t_width; rect.height = t_height; } if (m_rep->GetFrameCount() > 1) { if ((flags & F_REPEAT_COUNT) == 0) repeatcount = -1; irepeatcount = repeatcount; state |= CS_DO_START; } if (isunnamed() && t_name != nil) setname_cstring(t_name); if (isunnamed() && newname != nil) { const char *tname = strrchr(newname, PATH_SEPARATOR); if (tname != NULL) tname += 1; else tname = newname; setname_cstring(tname); } } MCCStringFree(t_name); return t_success ? IO_NORMAL : IO_ERROR; }