static cairo_test_status_t test_cairo_surface_get_mime_data (cairo_surface_t *surface) { const char *mimetype = "text/x-uri"; const unsigned char *data; unsigned long length; cairo_surface_get_mime_data (surface, mimetype, &data, &length); return data == NULL && length == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR; }
static int get_mime_data(lua_State *L) { cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE); const char *mime_type = luaL_checkstring(L, 2); const unsigned char *data = NULL; unsigned long length = 0; cairo_surface_get_mime_data(*obj, mime_type, &data, &length); if (data == NULL) return 0; lua_pushlstring(L, (const char *) data, length); return 1; }
/** Retrieves the original compressed data for the surface, if any. * The returned data belongs to the object and should not be freed. */ guchar const *Pixbuf::getMimeData(gsize &len, std::string &mimetype) const { static gchar const *mimetypes[] = { CAIRO_MIME_TYPE_JPEG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_PNG, NULL }; static guint mimetypes_len = g_strv_length(const_cast<gchar**>(mimetypes)); guchar const *data = NULL; for (guint i = 0; i < mimetypes_len; ++i) { unsigned long len_long = 0; cairo_surface_get_mime_data(const_cast<cairo_surface_t*>(_surface), mimetypes[i], &data, &len_long); if (data != NULL) { len = len_long; mimetype = mimetypes[i]; break; } } return data; }