Method: Magick::Image._load
- Defined in:
- ext/RMagick/rmimage.cpp
._load(str) ⇒ Magic::Image
Implement marshalling.
8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 |
# File 'ext/RMagick/rmimage.cpp', line 8877
VALUE
Image__load(VALUE klass ATTRIBUTE_UNUSED, VALUE str)
{
Image *image;
ImageInfo *info;
DumpedImage mi;
ExceptionInfo *exception;
char *blob;
size_t length;
blob = rm_str2cstr(str, &length);
// Must be as least as big as the 1st 4 fields in DumpedImage
if (length <= (long)(sizeof(DumpedImage)-MaxTextExtent))
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (too short)");
}
// Retrieve & validate the image format from the header portion
mi.id = ((DumpedImage *)blob)->id;
if (mi.id != DUMPED_IMAGE_ID)
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (invalid header)");
}
mi.mj = ((DumpedImage *)blob)->mj;
mi.mi = ((DumpedImage *)blob)->mi;
if ( mi.mj != DUMPED_IMAGE_MAJOR_VERS
|| mi.mi > DUMPED_IMAGE_MINOR_VERS)
{
rb_raise(rb_eTypeError, "incompatible image format (can't be read)\n"
"\tformat version %d.%d required; %d.%d given",
DUMPED_IMAGE_MAJOR_VERS, DUMPED_IMAGE_MINOR_VERS,
mi.mj, mi.mi);
}
mi.len = ((DumpedImage *)blob)->len;
// Must be bigger than the header
if (length <= (mi.len + sizeof(DumpedImage) - MaxTextExtent))
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (too short)");
}
info = CloneImageInfo(NULL);
memcpy(info->magick, ((DumpedImage *)blob)->magick, mi.len);
info->magick[mi.len] = '\0';
exception = AcquireExceptionInfo();
blob += offsetof(DumpedImage, magick) + mi.len;
length -= offsetof(DumpedImage, magick) + mi.len;
GVL_STRUCT_TYPE(BlobToImage) args = { info, blob, (size_t)length, exception };
image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args);
DestroyImageInfo(info);
rm_check_exception(exception, image, DestroyOnError);
DestroyExceptionInfo(exception);
return rm_image_new(image);
}
|