当前位置: 首页>>代码示例>>C++>>正文


C++ cairo_image_surface_get_format函数代码示例

本文整理汇总了C++中cairo_image_surface_get_format函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_image_surface_get_format函数的具体用法?C++ cairo_image_surface_get_format怎么用?C++ cairo_image_surface_get_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cairo_image_surface_get_format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ink_cairo_surface_blit

void
ink_cairo_surface_blit(cairo_surface_t *src, cairo_surface_t *dest)
{
    if (cairo_surface_get_type(src) == CAIRO_SURFACE_TYPE_IMAGE &&
        cairo_surface_get_type(dest) == CAIRO_SURFACE_TYPE_IMAGE &&
        cairo_image_surface_get_format(src) == cairo_image_surface_get_format(dest) &&
        cairo_image_surface_get_height(src) == cairo_image_surface_get_height(dest) &&
        cairo_image_surface_get_width(src) == cairo_image_surface_get_width(dest) &&
        cairo_image_surface_get_stride(src) == cairo_image_surface_get_stride(dest))
    {
        // use memory copy instead of using a Cairo context
        cairo_surface_flush(src);
        int stride = cairo_image_surface_get_stride(src);
        int h = cairo_image_surface_get_height(src);
        memcpy(cairo_image_surface_get_data(dest), cairo_image_surface_get_data(src), stride * h);
        cairo_surface_mark_dirty(dest);
    } else {
        // generic implementation
        cairo_t *ct = cairo_create(dest);
        cairo_set_source_surface(ct, src, 0, 0);
        cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE);
        cairo_paint(ct);
        cairo_destroy(ct);
    }
}
开发者ID:Spin0za,项目名称:inkscape,代码行数:25,代码来源:cairo-utils.cpp

示例2: cairo_boilerplate_get_image_surface_from_png

cairo_surface_t *
cairo_boilerplate_get_image_surface_from_png (const char   *filename,
					      int	    width,
					      int	    height,
					      cairo_bool_t  flatten)
{
    cairo_surface_t *surface;

    surface = cairo_image_surface_create_from_png (filename);
    if (cairo_surface_status (surface))
	return surface;

    if (flatten) {
	cairo_t *cr;
	cairo_surface_t *flattened;

	flattened = cairo_image_surface_create (cairo_image_surface_get_format (surface),
						width,
						height);
	cr = cairo_create (flattened);
	cairo_surface_destroy (flattened);

	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_paint (cr);

	cairo_set_source_surface (cr, surface,
				  width - cairo_image_surface_get_width (surface),
				  height - cairo_image_surface_get_height (surface));
	cairo_paint (cr);

	cairo_surface_destroy (surface);
	surface = cairo_surface_reference (cairo_get_target (cr));
	cairo_destroy (cr);
    } else if (cairo_image_surface_get_width (surface) != width ||
	       cairo_image_surface_get_height (surface) != height)
    {
	cairo_t *cr;
	cairo_surface_t *sub;

	sub = cairo_image_surface_create (cairo_image_surface_get_format (surface),
					  width,
					  height);
	cr = cairo_create (sub);
	cairo_surface_destroy (sub);

	cairo_set_source_surface (cr, surface,
				  width - cairo_image_surface_get_width (surface),
				  height - cairo_image_surface_get_height (surface));
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);

	cairo_surface_destroy (surface);
	surface = cairo_surface_reference (cairo_get_target (cr));
	cairo_destroy (cr);
    }

    return surface;
}
开发者ID:mrobinson,项目名称:cairo,代码行数:58,代码来源:cairo-boilerplate.c

示例3: createTextureFromSurface

std::shared_ptr<Texture> createTextureFromSurface(cairo_surface_t* surface) {
	// Convert cairo format to GL format.
	GLint gl_internal_format;
	GLint gl_format;
	const cairo_format_t format = cairo_image_surface_get_format(surface);
	if(format == CAIRO_FORMAT_ARGB32) {
		gl_internal_format = GL_RGBA;
		gl_format = GL_BGRA;
	} else if(format == CAIRO_FORMAT_RGB24) {
		gl_internal_format = GL_RGB;
		gl_format = GL_BGR;
	} else {
		throw "Unsupported surface type";
	}

	// Create texture
	const int width = cairo_image_surface_get_width(surface);
	const int height = cairo_image_surface_get_height(surface);

	auto texture = Texture::create(width, height);
	texture->useIn();
	glTexImage2D(GL_TEXTURE_2D, 0, gl_internal_format, width, height, 0, gl_format, GL_UNSIGNED_BYTE, cairo_image_surface_get_data(surface));

	return texture;
}
开发者ID:xanxys,项目名称:construct,代码行数:25,代码来源:ui_common.cpp

示例4: cairo_image_surface_create_from_png

Picture *Picture::from_png(const char *filename) {
    cairo_surface_t *pngs = cairo_image_surface_create_from_png(filename);

    if (cairo_surface_status(pngs) != CAIRO_STATUS_SUCCESS) {
        cairo_surface_destroy(pngs);
        throw std::runtime_error("Failed to load PNG to Cairo surface");
    }

    cairo_format_t nf = cairo_image_surface_get_format(pngs);

    if (nf != CAIRO_FORMAT_ARGB32 && nf != CAIRO_FORMAT_RGB24) {
        cairo_surface_destroy(pngs);
        throw std::runtime_error("PNG uses unsupported pixel format");
    } 

    Picture *ret = Picture::alloc(
        cairo_image_surface_get_width(pngs),
        cairo_image_surface_get_height(pngs),
        4*cairo_image_surface_get_width(pngs),
        BGRA8
    );
        
    int xcopy = 4*ret->w;
    int stride = cairo_image_surface_get_stride(pngs);
    uint8_t *data = (uint8_t *)cairo_image_surface_get_data(pngs);

    /* copy data */
    for (int ycopy = 0; ycopy < ret->h; ++ycopy) {
        memcpy(ret->scanline(ycopy), data + stride * ycopy, xcopy);
    }
    
    cairo_surface_destroy(pngs);
    return ret;
}
开发者ID:asquared,项目名称:seven_seg,代码行数:34,代码来源:picture.cpp

示例5: _gtk_cairo_blur_surface

/*
 * _gtk_cairo_blur_surface:
 * @surface: a cairo image surface.
 * @radius: the blur radius.
 *
 * Blurs the cairo image surface at the given radius.
 */
void
_gtk_cairo_blur_surface (cairo_surface_t* surface,
                         double           radius_d)
{
  cairo_format_t format;
  int radius = radius_d;

  g_return_if_fail (surface != NULL);
  g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE);

  format = cairo_image_surface_get_format (surface);
  g_return_if_fail (format == CAIRO_FORMAT_A8);

  if (radius == 0)
    return;

  /* Before we mess with the surface, execute any pending drawing. */
  cairo_surface_flush (surface);

  _boxblur (cairo_image_surface_get_data (surface),
            cairo_image_surface_get_stride (surface),
            cairo_image_surface_get_height (surface),
            radius);

  /* Inform cairo we altered the surface contents. */
  cairo_surface_mark_dirty (surface);
}
开发者ID:vaurelios,项目名称:gtk,代码行数:34,代码来源:gtkcairoblur.c

示例6: _cairo_image_surface_create_compatible

cairo_surface_t *
_cairo_image_surface_create_compatible (cairo_surface_t *surface)
{
	return cairo_image_surface_create (cairo_image_surface_get_format (surface),
					   cairo_image_surface_get_width (surface),
					   cairo_image_surface_get_height (surface));
}
开发者ID:cormac-w,项目名称:gthumb,代码行数:7,代码来源:cairo-utils.c

示例7: cairo_surface_to_pixbuf

static GdkPixbuf *
cairo_surface_to_pixbuf (cairo_surface_t *surface)
{
	gint stride, width, height, x, y;
	guchar *data, *output, *output_pixel;

	/* This doesn't deal with alpha --- it simply converts the 4-byte Cairo ARGB
	 * format to the 3-byte GdkPixbuf packed RGB format. */
	g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_RGB24);

	stride = cairo_image_surface_get_stride (surface);
	width = cairo_image_surface_get_width (surface);
	height = cairo_image_surface_get_height (surface);
	data = cairo_image_surface_get_data (surface);

	output = g_malloc (stride * height);
	output_pixel = output;

	for (y = 0; y < height; y++) {
		guint32 *row = (guint32*) (data + y * stride);

		for (x = 0; x < width; x++) {
			output_pixel[0] = (row[x] & 0x00ff0000) >> 16;
			output_pixel[1] = (row[x] & 0x0000ff00) >> 8;
			output_pixel[2] = (row[x] & 0x000000ff);

			output_pixel += 3;
		}
	}

	return gdk_pixbuf_new_from_data (output, GDK_COLORSPACE_RGB, FALSE, 8,
					 width, height, width * 3,
					 (GdkPixbufDestroyNotify) g_free, NULL);
}
开发者ID:JosephMcc,项目名称:xplayer,代码行数:34,代码来源:xplayer-video-thumbnailer.c

示例8: gsk_cairo_blur_surface

/*
 * _gsk_cairo_blur_surface:
 * @surface: a cairo image surface.
 * @radius: the blur radius.
 *
 * Blurs the cairo image surface at the given radius.
 */
void
gsk_cairo_blur_surface (cairo_surface_t* surface,
                        double           radius_d,
                        GskBlurFlags     flags)
{
  int radius = radius_d;

  g_return_if_fail (surface != NULL);
  g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE);
  g_return_if_fail (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_A8);

  /* The code doesn't actually do any blurring for radius 1, as it
   * ends up with box filter size 1 */
  if (radius <= 1)
    return;

  if ((flags & (GSK_BLUR_X|GSK_BLUR_Y)) == 0)
    return;

  /* Before we mess with the surface, execute any pending drawing. */
  cairo_surface_flush (surface);

  _boxblur (cairo_image_surface_get_data (surface),
            cairo_image_surface_get_stride (surface),
            cairo_image_surface_get_height (surface),
            radius, flags);

  /* Inform cairo we altered the surface contents. */
  cairo_surface_mark_dirty (surface);
}
开发者ID:GNOME,项目名称:gtk,代码行数:37,代码来源:gskcairoblur.c

示例9: GCN_EXCEPTION

    void CairoImage::putPixel(int x, int y, const Color& color)
    {
        if (!mCairoSurface)
        {
            throw GCN_EXCEPTION("Trying to write a pixel on a non loaded image.");
        }

        int stride=cairo_image_surface_get_stride(mCairoSurface);
        unsigned char *imagePixels=cairo_image_surface_get_data(mCairoSurface);
        if (!imagePixels)
        {
            throw GCN_EXCEPTION("Surface data are not available (surface is not of type Image or has been finished)");
        }
        // deal differently with each surface format
        switch(cairo_image_surface_get_format(mCairoSurface))
        {
            case CAIRO_FORMAT_ARGB32:
                *((unsigned long*)(&imagePixels[x*4 + y*stride]))=PrecomputeAlpha(color);
                break;
            case CAIRO_FORMAT_RGB24:
                *((unsigned long*)(&imagePixels[x*4 + y*stride]))=GetRGB(color);
                break;
            case CAIRO_FORMAT_A8:
                imagePixels[x + y*stride]=(unsigned char)color.a;
                break;
            default :
                //do nothing
                break;
        }
    }
开发者ID:andryblack,项目名称:guichan,代码行数:30,代码来源:cairoimage.cpp

示例10: surface_get_format

static int
surface_get_format (lua_State *L) {
    cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE);
    if (cairo_surface_get_type(*obj) != CAIRO_SURFACE_TYPE_IMAGE)
        return luaL_error(L, "method 'get_format' only works on image surfaces");
    return format_to_lua(L, cairo_image_surface_get_format(*obj));
}
开发者ID:steelman,项目名称:oocairo,代码行数:7,代码来源:obj_surface.c

示例11: negative_exec

static gpointer
negative_exec (GthAsyncTask *task,
	       gpointer      user_data)
{
	NegativeData    *negative_data = user_data;
	cairo_format_t   format;
	int              width;
	int              height;
	int              source_stride;
	int              destination_stride;
	unsigned char   *p_source_line;
	unsigned char   *p_destination_line;
	unsigned char   *p_source;
	unsigned char   *p_destination;
	gboolean         cancelled;
	double           progress;
	gboolean         terminated;
	int              x, y;
	unsigned char    red, green, blue, alpha;

	format = cairo_image_surface_get_format (negative_data->source);
	width = cairo_image_surface_get_width (negative_data->source);
	height = cairo_image_surface_get_height (negative_data->source);
	source_stride = cairo_image_surface_get_stride (negative_data->source);

	negative_data->destination = cairo_image_surface_create (format, width, height);
	destination_stride = cairo_image_surface_get_stride (negative_data->destination);
	p_source_line = _cairo_image_surface_flush_and_get_data (negative_data->source);
	p_destination_line = _cairo_image_surface_flush_and_get_data (negative_data->destination);
	for (y = 0; y < height; y++) {
		gth_async_task_get_data (task, NULL, &cancelled, NULL);
		if (cancelled)
			return NULL;

		progress = (double) y / height;
		gth_async_task_set_data (task, NULL, NULL, &progress);

		p_source = p_source_line;
		p_destination = p_destination_line;
		for (x = 0; x < width; x++) {
			CAIRO_GET_RGBA (p_source, red, green, blue, alpha);
			CAIRO_SET_RGBA (p_destination,
					255 - red,
					255 - green,
					255 - blue,
					alpha);

			p_source += 4;
			p_destination += 4;
		}
		p_source_line += source_stride;
		p_destination_line += destination_stride;
	}

	cairo_surface_mark_dirty (negative_data->destination);
	terminated = TRUE;
	gth_async_task_set_data (task, &terminated, NULL, NULL);

	return NULL;
}
开发者ID:KapTmaN,项目名称:gthumb,代码行数:60,代码来源:gth-file-tool-negative.c

示例12: evasObjectFromCairoImageSurface

PassRefPtr<Evas_Object> evasObjectFromCairoImageSurface(Evas* canvas, cairo_surface_t* surface)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);

    cairo_status_t status = cairo_surface_status(surface);
    if (status != CAIRO_STATUS_SUCCESS) {
        EINA_LOG_ERR("cairo surface is invalid: %s", cairo_status_to_string(status));
        return 0;
    }

    cairo_surface_type_t type = cairo_surface_get_type(surface);
    if (type != CAIRO_SURFACE_TYPE_IMAGE) {
        EINA_LOG_ERR("unknown surface type %d, required %d (CAIRO_SURFACE_TYPE_IMAGE).",
            type, CAIRO_SURFACE_TYPE_IMAGE);
        return 0;
    }

    cairo_format_t format = cairo_image_surface_get_format(surface);
    if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) {
        EINA_LOG_ERR("unknown surface format %d, expected %d or %d.",
            format, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24);
        return 0;
    }

    int width = cairo_image_surface_get_width(surface);
    int height = cairo_image_surface_get_height(surface);
    int stride = cairo_image_surface_get_stride(surface);
    if (width <= 0 || height <= 0 || stride <= 0) {
        EINA_LOG_ERR("invalid image size %dx%d, stride=%d", width, height, stride);
        return 0;
    }

    void* data = cairo_image_surface_get_data(surface);
    if (!data) {
        EINA_LOG_ERR("could not get source data.");
        return 0;
    }

    RefPtr<Evas_Object> image = adoptRef(evas_object_image_filled_add(canvas));
    if (!image) {
        EINA_LOG_ERR("could not add image to canvas.");
        return 0;
    }

    evas_object_image_colorspace_set(image.get(), EVAS_COLORSPACE_ARGB8888);
    evas_object_image_size_set(image.get(), width, height);
    evas_object_image_alpha_set(image.get(), format == CAIRO_FORMAT_ARGB32);

    if (evas_object_image_stride_get(image.get()) != stride) {
        EINA_LOG_ERR("evas' stride %d diverges from cairo's %d.",
            evas_object_image_stride_get(image.get()), stride);
        return 0;
    }

    evas_object_image_data_copy_set(image.get(), data);

    return image.release();
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:59,代码来源:CairoUtilitiesEfl.cpp

示例13: image_surface_equals

static cairo_bool_t
image_surface_equals (cairo_surface_t *A, cairo_surface_t *B)
{
    if (cairo_image_surface_get_format (A) !=
	cairo_image_surface_get_format (B))
	return 0;

    if (cairo_image_surface_get_width (A) !=
	cairo_image_surface_get_width (B))
	return 0;

    if (cairo_image_surface_get_height (A) !=
	cairo_image_surface_get_height (B))
	return 0;

    return 1;
}
开发者ID:Blueprintts,项目名称:npm-pdf2svg,代码行数:17,代码来源:png.c

示例14: bg

static void bg(GtkStyleContext* sc, wxColour& color, int state = GTK_STATE_FLAG_NORMAL)
{
    GdkRGBA* rgba;
    cairo_pattern_t* pattern = NULL;
    gtk_style_context_set_state(sc, GtkStateFlags(state));
    gtk_style_context_get(sc, GtkStateFlags(state),
        "background-color", &rgba, "background-image", &pattern, NULL);
    color = wxColour(*rgba);
    gdk_rgba_free(rgba);

    // "background-image" takes precedence over "background-color".
    // If there is an image, try to get a color out of it.
    if (pattern)
    {
        if (cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE)
        {
            cairo_surface_t* surf;
            cairo_pattern_get_surface(pattern, &surf);
            if (cairo_surface_get_type(surf) == CAIRO_SURFACE_TYPE_IMAGE)
            {
                const guchar* data = cairo_image_surface_get_data(surf);
                const int stride = cairo_image_surface_get_stride(surf);
                // choose a pixel in the middle vertically,
                // images often have a vertical gradient
                const int i = stride * (cairo_image_surface_get_height(surf) / 2);
                const unsigned* p = reinterpret_cast<const unsigned*>(data + i);
                const unsigned pixel = *p;
                guchar r, g, b, a = 0xff;
                switch (cairo_image_surface_get_format(surf))
                {
                case CAIRO_FORMAT_ARGB32:
                    a = guchar(pixel >> 24);
                    // fallthrough
                case CAIRO_FORMAT_RGB24:
                    r = guchar(pixel >> 16);
                    g = guchar(pixel >> 8);
                    b = guchar(pixel);
                    break;
                default:
                    a = 0;
                    break;
                }
                if (a != 0)
                {
                    if (a != 0xff)
                    {
                        // un-premultiply
                        r = guchar((r * 0xff) / a);
                        g = guchar((g * 0xff) / a);
                        b = guchar((b * 0xff) / a);
                    }
                    color.Set(r, g, b, a);
                }
            }
        }
        cairo_pattern_destroy(pattern);
    }
开发者ID:MaartenBent,项目名称:wxWidgets,代码行数:57,代码来源:settings.cpp

示例15: _cairo_image_surface_transform

cairo_surface_t *
_cairo_image_surface_transform (cairo_surface_t *source,
				GthTransform     transform)
{
	cairo_surface_t *destination = NULL;
	cairo_format_t   format;
	int              width;
	int              height;
	int              source_stride;
	int              destination_width;
	int              destination_height;
	int              line_start;
	int              line_step;
	int              pixel_step;
	unsigned char   *p_source_line;
	unsigned char   *p_destination_line;
	unsigned char   *p_source;
	unsigned char   *p_destination;
	int              x;

	if (source == NULL)
		return NULL;

	format = cairo_image_surface_get_format (source);
	width = cairo_image_surface_get_width (source);
	height = cairo_image_surface_get_height (source);
	source_stride = cairo_image_surface_get_stride (source);

	_cairo_image_surface_transform_get_steps (format,
						  width,
						  height,
						  transform,
						  &destination_width,
						  &destination_height,
						  &line_start,
						  &line_step,
						  &pixel_step);

	destination = cairo_image_surface_create (format, destination_width, destination_height);
	p_source_line = _cairo_image_surface_flush_and_get_data (source);
	p_destination_line = _cairo_image_surface_flush_and_get_data (destination) + line_start;
	while (height-- > 0) {
		p_source = p_source_line;
		p_destination = p_destination_line;
		for (x = 0; x < width; x++) {
			memcpy (p_destination, p_source, 4);
			p_source += 4;
			p_destination += pixel_step;
		}
		p_source_line += source_stride;
		p_destination_line += line_step;
	}

	cairo_surface_mark_dirty (destination);

	return destination;
}
开发者ID:cormac-w,项目名称:gthumb,代码行数:57,代码来源:cairo-utils.c


注:本文中的cairo_image_surface_get_format函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。