Method: Magick::Image#_dump
- Defined in:
- ext/RMagick/rmimage.cpp
#_dump(depth) ⇒ String
Implement marshalling.
6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 |
# File 'ext/RMagick/rmimage.cpp', line 6066
VALUE
Image__dump(VALUE self, VALUE depth ATTRIBUTE_UNUSED)
{
Image *image;
ImageInfo *info;
void *blob;
size_t length;
DumpedImage mi;
VALUE str;
ExceptionInfo *exception;
image = rm_check_destroyed(self);
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
strlcpy(info->magick, image->magick, sizeof(info->magick));
exception = AcquireExceptionInfo();
GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception };
blob = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args);
// Free ImageInfo first - error handling may raise an exception
DestroyImageInfo(info);
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
if (!blob)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
// Create a header for the blob: ID and version
// numbers, followed by the length of the magick
// string stored as a byte, followed by the
// magick string itself.
mi.id = DUMPED_IMAGE_ID;
mi.mj = DUMPED_IMAGE_MAJOR_VERS;
mi.mi = DUMPED_IMAGE_MINOR_VERS;
strlcpy(mi.magick, image->magick, sizeof(mi.magick));
mi.len = (unsigned char) min((size_t)UCHAR_MAX, rm_strnlen_s(mi.magick, sizeof(mi.magick)));
// Concatenate the blob onto the header & return the result
str = rb_str_new((char *)&mi, (long)(mi.len+offsetof(DumpedImage, magick)));
str = rb_str_buf_cat(str, (char *)blob, (long)length);
magick_free((void*)blob);
RB_GC_GUARD(str);
return str;
}
|