• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cairo_image_surface_get_data函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: gimp_display_shell_render

void
gimp_display_shell_render (GimpDisplayShell *shell,
                           cairo_t          *cr,
                           gint              x,
                           gint              y,
                           gint              w,
                           gint              h)
{
  GimpImage       *image;
  GeglBuffer      *buffer;
#ifdef USE_NODE_BLIT
  GeglNode        *node;
#endif
  gdouble          scale_x       = 1.0;
  gdouble          scale_y       = 1.0;
  gdouble          buffer_scale  = 1.0;
  gint             viewport_offset_x;
  gint             viewport_offset_y;
  gint             viewport_width;
  gint             viewport_height;
  gint             scaled_x;
  gint             scaled_y;
  gint             scaled_width;
  gint             scaled_height;
  cairo_surface_t *xfer;
  gint             xfer_src_x;
  gint             xfer_src_y;
  gint             mask_src_x = 0;
  gint             mask_src_y = 0;
  gint             cairo_stride;
  guchar          *cairo_data;
  GeglBuffer      *cairo_buffer;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
  g_return_if_fail (cr != NULL);
  g_return_if_fail (w > 0 && h > 0);

  image  = gimp_display_get_image (shell->display);
  buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (image));
#ifdef USE_NODE_BLIT
  node   = gimp_projectable_get_graph (GIMP_PROJECTABLE (image));
#endif

#ifdef GIMP_DISPLAY_RENDER_ENABLE_SCALING
  /* if we had this future API, things would look pretty on hires (retina) */
  scale_x = gdk_window_get_scale_factor (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (shell))));
#endif

  scale_x = MIN (scale_x, GIMP_DISPLAY_RENDER_MAX_SCALE);
  scale_y = scale_x;

  if (shell->scale_x > shell->scale_y)
    {
      scale_y *= (shell->scale_x / shell->scale_y);

      buffer_scale = shell->scale_y * scale_y;
    }
  else if (shell->scale_y > shell->scale_x)
    {
      scale_x *= (shell->scale_y / shell->scale_x);

      buffer_scale = shell->scale_x * scale_x;
    }
  else
    {
      buffer_scale = shell->scale_x * scale_x;
    }

  gimp_display_shell_scroll_get_scaled_viewport (shell,
                                                 &viewport_offset_x,
                                                 &viewport_offset_y,
                                                 &viewport_width,
                                                 &viewport_height);

  scaled_x      = floor ((x + viewport_offset_x) * scale_x);
  scaled_y      = floor ((y + viewport_offset_y) * scale_y);
  scaled_width  = ceil (w * scale_x);
  scaled_height = ceil (h * scale_y);

  if (shell->rotate_transform)
    {
      xfer = cairo_surface_create_similar_image (cairo_get_target (cr),
                                                 CAIRO_FORMAT_ARGB32,
                                                 scaled_width,
                                                 scaled_height);
      cairo_surface_mark_dirty (xfer);
      xfer_src_x = 0;
      xfer_src_y = 0;
    }
  else
    {
      xfer = gimp_display_xfer_get_surface (shell->xfer,
                                            scaled_width,
                                            scaled_height,
                                            &xfer_src_x,
                                            &xfer_src_y);
    }

  cairo_stride = cairo_image_surface_get_stride (xfer);
  cairo_data   = cairo_image_surface_get_data (xfer) +
//.........这里部分代码省略.........
开发者ID:Anstep,项目名称:gimp,代码行数:101,代码来源:gimpdisplayshell-render.c


示例2: cairo_image_surface_get_data

unsigned char* LcCairoPainter::data() {
    return cairo_image_surface_get_data(_surface);
}
开发者ID:bomastudio,项目名称:LibreCAD_3,代码行数:3,代码来源:lccairopainter.cpp


示例3: cdcreatecanvas

static void cdcreatecanvas(cdCanvas* canvas, void* data)
{
  cdCtxCanvas* ctxcanvas;
  cairo_surface_t *surface;
  int w = 0, h = 0, use_alpha = 0;
  double res = 3.78;
  unsigned char *rgb = NULL;
  char* str_data = (char*)data;
  char* res_ptr = NULL;
  cairo_format_t format = CAIRO_FORMAT_RGB24;

  /* Starting parameters */
  if (str_data == NULL) 
    return;

  if (strstr(str_data, "-a"))
    use_alpha = 1;

  res_ptr = strstr(str_data, "-r");
  if (res_ptr)
    sscanf(res_ptr+2, "%lg", &res);

  /* size and rgb */
#ifdef SunOS_OLD
  sscanf(str_data, "%dx%d %d", &w, &h, &rgb);
#else
  sscanf(str_data, "%dx%d %p", &w, &h, &rgb);
#endif

  if (w == 0) w = 1;
  if (h == 0) h = 1;

  canvas->w = w;
  canvas->h = h;
  canvas->yres = res;
  canvas->xres = res;
  canvas->w_mm = ((double)w) / res;
  canvas->h_mm = ((double)h) / res;
  if (use_alpha)
  {
    canvas->bpp = 32;
    format = CAIRO_FORMAT_ARGB32;
  }
  else
    canvas->bpp = 24;  /* fake value, image bpp is always 32 */

  if (rgb)
    surface = cairo_image_surface_create_for_data(rgb, format, w, h, w*32);
  else
  	surface = cairo_image_surface_create(format, canvas->w, canvas->h);

  /* Starting Cairo driver */
  ctxcanvas = cdcairoCreateCanvas(canvas, cairo_create(surface));
  cairo_surface_destroy(surface);

  if (rgb)
  {
    ctxcanvas->user_image = 1;
    ctxcanvas->rgb = rgb;
  }
  else
  {
    ctxcanvas->user_image = 0;
    ctxcanvas->rgb = cairo_image_surface_get_data(cairo_get_target(ctxcanvas->cr));

    /* fill with white */
    /* transparent, this is the normal alpha coding */
    cairo_set_source_rgba(ctxcanvas->cr, 1.0, 1.0, 1.0, 0.0);
    cairo_rectangle(ctxcanvas->cr, 0, 0, canvas->w, canvas->h);
    cairo_fill(ctxcanvas->cr);
  }
                                      
  cdRegisterAttribute(canvas, &stride_attrib);
  cdRegisterAttribute(canvas, &write2png_attrib);
  cdRegisterAttribute(canvas, &data_attrib);
}
开发者ID:Vulcanior,项目名称:IUP,代码行数:76,代码来源:cdcairoirgb.c


示例4: lime_cairo_image_surface_get_data

	double lime_cairo_image_surface_get_data (double handle) {
		
		return (intptr_t)cairo_image_surface_get_data ((cairo_surface_t*)(intptr_t)handle);
		
	}
开发者ID:rushmobius,项目名称:lime,代码行数:5,代码来源:CairoBindings.cpp


示例5: draw_page_cairo

gboolean
draw_page_cairo (GtkPrintContext *context,
                 PrintData       *data)
{
  GimpDrawable    *drawable = gimp_drawable_get (data->drawable_id);
  GimpPixelRgn     region;
  cairo_t         *cr;
  cairo_surface_t *surface;
  guchar          *pixels;
  gdouble          cr_width;
  gdouble          cr_height;
  gdouble          cr_dpi_x;
  gdouble          cr_dpi_y;
  gint             width;
  gint             height;
  gint             stride;
  gint             y;
  gdouble          scale_x;
  gdouble          scale_y;

  width  = drawable->width;
  height = drawable->height;

  gimp_tile_cache_ntiles (width / gimp_tile_width () + 1);

  cr = gtk_print_context_get_cairo_context (context);

  cr_width  = gtk_print_context_get_width  (context);
  cr_height = gtk_print_context_get_height (context);
  cr_dpi_x  = gtk_print_context_get_dpi_x  (context);
  cr_dpi_y  = gtk_print_context_get_dpi_y  (context);

  scale_x = cr_dpi_x / data->xres;
  scale_y = cr_dpi_y / data->yres;

#if 0
  /* print header if it is requested */
  if (data->show_info_header)
    {
      draw_info_header (context, cr, data);

/* In points */
#define HEADER_HEIGHT (20 * 72.0 / 25.4)
      cairo_translate (cr, 0, HEADER_HEIGHT);
      cr_height -= HEADER_HEIGHT;
    }
#endif

  cairo_translate (cr,
                   data->offset_x / cr_dpi_x * 72.0,
                   data->offset_y / cr_dpi_y * 72.0);
  cairo_scale (cr, scale_x, scale_y);

  gimp_pixel_rgn_init (&region, drawable, 0, 0, width, height, FALSE, FALSE);

  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);

  pixels = cairo_image_surface_get_data (surface);
  stride = cairo_image_surface_get_stride (surface);

  for (y = 0; y < height; y++, pixels += stride)
    {
      gimp_pixel_rgn_get_row (&region, pixels, 0, y, width);

      switch (drawable->bpp)
        {
        case 3:
          convert_from_rgb (pixels, width);
          break;
        case 4:
          convert_from_rgba (pixels, width);
          break;
        }

      if (y % 16 == 0)
        gimp_progress_update ((gdouble) y / (gdouble) height);
    }

  cairo_set_source_surface (cr, surface, 0, 0);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);
  cairo_surface_destroy (surface);

  gimp_progress_update (1.0);

  gimp_drawable_detach (drawable);

  return TRUE;
}
开发者ID:Minoos,项目名称:gimp,代码行数:89,代码来源:print-draw-page.c


示例6: get_cairo_region_create_from_surface

static inline
cairo_region_t *
get_cairo_region_create_from_surface(struct qp_graph *gr,
    cairo_surface_t *surface, int width, int height)
{
  /* TODO: this is a resource pig.  Make it better. */

  cairo_rectangle_int_t rect;
  cairo_surface_t *image;
  cairo_region_t *region;
  cairo_t *cr;
  uint32_t *data, bg;
  int x, y, stride;

  if(!gr->x11)
    /* Creates region that covers the area where the
     * given surface is more than 50% opaque.
     * The below code copies this method.  This GDK
     * code is a pig too. */
    return gdk_cairo_region_create_from_surface(surface);

  if(!gr->x11->background_set)
  {
    /* We need to see what the background color is when it is
     * applied to an image.  A small image. */
    image = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1, 1);
    cr = cairo_create(image);
    cairo_set_source_rgba(cr, gr->background_color.r,
        gr->background_color.g, gr->background_color.b,
        gr->background_color.a);
    cairo_paint (cr);
    cairo_destroy (cr);
    data = (void *) cairo_image_surface_get_data(image);
    gr->x11->background = (data[0] & 0x00FFFFFF);
    cairo_surface_destroy(image);
    gr->x11->background_set = 1;
  }

  bg = gr->x11->background;

  image = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
  cr = cairo_create(image);
  cairo_set_source_surface(cr, surface, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);

  data = (void *) cairo_image_surface_get_data(image);
  stride = cairo_image_surface_get_stride(image);

  region = cairo_region_create();

  for(y=0; y < height; y++)
    {
      for(x=0; x < width; x++)
        {
          /* Search for a continuous range of "background pixels"*/
          gint x0=x;
          while(x < width)
            {
              if((data[x] & 0x00FFFFFF) == bg)
                /* This pixel is the background color */
                break;
              x++;
            }

          if(x > x0)
            {
              /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
               * in the region
               */
              rect.x = x0;
              rect.width = x - x0;
              rect.y = y;
              rect.height = 1;

              cairo_region_union_rectangle(region, &rect);
            }
        }
      data += stride/4;
    }

  cairo_surface_destroy(image);

  return region;
}
开发者ID:lanceman2,项目名称:quickplot,代码行数:85,代码来源:graph_draw.c


示例7: msRenderRasterizedSVGSymbol

int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
{

#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
  struct svg_symbol_cache *svg_cache;
  symbolStyleObj pixstyle;
  symbolObj pixsymbol;
  int status;

  if(MS_SUCCESS != msPreloadSVGSymbol(symbol))
    return MS_FAILURE;
  svg_cache = (struct svg_symbol_cache*) symbol->renderer_cache;

  //already rendered at the right size and scale? return
  if(svg_cache->scale != style->scale || svg_cache->rotation != style->rotation) {
    cairo_t *cr;
    cairo_surface_t *surface;
    unsigned char *pb;
    int width, height, surface_w, surface_h;
    /* need to recompute the pixmap */
    if(svg_cache->pixmap_buffer) {
      msFreeRasterBuffer(svg_cache->pixmap_buffer);
    } else {
      svg_cache->pixmap_buffer = msSmallCalloc(1,sizeof(rasterBufferObj));
    }

    //increase pixmap size to accomodate scaling/rotation
    if (style->scale != 1.0) {
      width = surface_w = (symbol->sizex * style->scale + 0.5);
      height = surface_h = (symbol->sizey * style->scale + 0.5);
    } else {
      width = surface_w = symbol->sizex;
      height = surface_h = symbol->sizey;
    }
    if (style->rotation != 0) {
      surface_w = surface_h = MS_NINT(MS_MAX(height, width) * 1.415);
    }

    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, surface_w, surface_h);
    cr = cairo_create(surface);

    if (style->rotation != 0) {
      cairo_translate(cr, surface_w / 2, surface_h / 2);
      cairo_rotate(cr, -style->rotation);
      cairo_translate(cr, -width / 2, -height / 2);
    }
    if (style->scale != 1.0) {
      cairo_scale(cr, style->scale, style->scale);
    }
#ifdef USE_SVG_CAIRO
    if(svg_cairo_render(svg_cache->svgc, cr) != SVG_CAIRO_STATUS_SUCCESS) {
      return MS_FAILURE;
    }
#else
  rsvg_handle_render_cairo(svg_cache->svgc, cr);
#endif
    pb = cairo_image_surface_get_data(surface);

    //set up raster
    initializeRasterBufferCairo(svg_cache->pixmap_buffer, surface_w, surface_h, 0);
    memcpy(svg_cache->pixmap_buffer->data.rgba.pixels, pb, surface_w * surface_h * 4 * sizeof (unsigned char));
    svg_cache->scale = style->scale;
    svg_cache->rotation = style->rotation;
    cairo_destroy(cr);
    cairo_surface_destroy(surface);
  }
  assert(svg_cache->pixmap_buffer->height && svg_cache->pixmap_buffer->width);

  pixstyle = *style;
  pixstyle.rotation = 0.0;
  pixstyle.scale = 1.0;

  pixsymbol.pixmap_buffer = svg_cache->pixmap_buffer;
  pixsymbol.type = MS_SYMBOL_PIXMAP;

  status = MS_IMAGE_RENDERER(img)->renderPixmapSymbol(img,x,y,&pixsymbol,&pixstyle);
  MS_IMAGE_RENDERER(img)->freeSymbol(&pixsymbol);
  return status;
#else
  msSetError(MS_MISCERR, "SVG Symbols requested but MapServer is not built with libsvgcairo",
             "renderSVGSymbolCairo()");
  return MS_FAILURE;
#endif
}
开发者ID:geographika,项目名称:mapserver,代码行数:84,代码来源:mapcairo.c


示例8: draw_page_cairo

static void draw_page_cairo(GtkPrintContext *context, PrintData *data)
{
  cairo_t         *cr;
  GdkPixbuf       *pixbuf_to_draw; 
  cairo_surface_t *surface;
  guchar          *surface_pixels;
  guchar          *pixbuf_pixels;
  gint             stride;
  gint             pixbuf_stride;
  gint             pixbuf_n_channels;
  gdouble          cr_dpi_x;
  gdouble          cr_dpi_y;
  gdouble          scale_x;
  gdouble          scale_y;
  gint             y;

  cr = gtk_print_context_get_cairo_context(context);
  pixbuf_to_draw = gdk_pixbuf_get_from_drawable(NULL,
                               GDK_DRAWABLE(vik_viewport_get_pixmap(data->vvp)),
                               NULL, 0, 0, 0, 0, data->width, data->height);
  surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
                                       data->width, data->height);
  
  cr_dpi_x  = gtk_print_context_get_dpi_x  (context);
  cr_dpi_y  = gtk_print_context_get_dpi_y  (context);

  scale_x = cr_dpi_x / data->xres;
  scale_y = cr_dpi_y / data->yres;

  cairo_translate (cr,
                   data->offset_x / cr_dpi_x * 72.0,
                   data->offset_y / cr_dpi_y * 72.0);
  cairo_scale (cr, scale_x, scale_y);

  surface_pixels = cairo_image_surface_get_data (surface);
  stride = cairo_image_surface_get_stride (surface);
  pixbuf_pixels = gdk_pixbuf_get_pixels (pixbuf_to_draw);
  pixbuf_stride = gdk_pixbuf_get_rowstride(pixbuf_to_draw);
  pixbuf_n_channels = gdk_pixbuf_get_n_channels(pixbuf_to_draw);

  // fprintf(stderr, "DEBUG: %s() surface_pixels=%p pixbuf_pixels=%p size=%d surface_width=%d surface_height=%d stride=%d data_height=%d pixmap_stride=%d pixmap_nchannels=%d pixmap_bit_per_Sample=%d\n", __PRETTY_FUNCTION__, surface_pixels, pixbuf_pixels, stride * data->height, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), stride, data->height, gdk_pixbuf_get_rowstride(pixbuf_to_draw), gdk_pixbuf_get_n_channels(pixbuf_to_draw), gdk_pixbuf_get_bits_per_sample(pixbuf_to_draw));

  /* Assume the pixbuf has 8 bits per channel */
  for (y = 0; y < data->height; y++, surface_pixels += stride, pixbuf_pixels += pixbuf_stride) {
    switch (pixbuf_n_channels) {
      case 3:
        copy_row_from_rgb (surface_pixels, pixbuf_pixels, data->width);
        break;
      case 4:
        copy_row_from_rgba (surface_pixels, pixbuf_pixels, data->width);
        break;
    }
  }

  g_object_unref(G_OBJECT(pixbuf_to_draw));

  cairo_set_source_surface(cr, surface, 0, 0);
  cairo_rectangle(cr, 0, 0, data->width, data->height);
  cairo_fill(cr);
  cairo_surface_destroy(surface);
}
开发者ID:gdt,项目名称:viking,代码行数:61,代码来源:print.c


示例9: GUIFont_GetGreaterSize

TGUIFont *Alloc_GUIFont(const char *AFontName, float AHeight)
{
  TGUIFont *BFont = (TGUIFont *)malloc(sizeof(TGUIFont));
  BFont->FGridWidth = 0;
  BFont->FGridHeight = 0;
  BFont->FHeight = AHeight;
  BFont->FExtents = (TGUIFontExtent *)malloc(sizeof(TGUIFontExtent) * 256);
  TGUIFontExtent *BCharExtent = BFont->FExtents;
  cairo_text_extents_t *BExtents = (cairo_text_extents_t *)malloc(sizeof(cairo_text_extents_t));
  int BRow = 0;
  int BColumn = 0;
  GUIFont_GetGreaterSize(AFontName, AHeight, &BFont->FGridWidth, &BFont->FGridHeight);
  printf("[MESSAGE] Font grid of size (%i, %i).\n", BFont->FGridWidth, BFont->FGridHeight);
  BFont->FTextureWidth = Get_NextP2(BFont->FGridWidth * 16);
  BFont->FTextureHeight = Get_NextP2(BFont->FGridHeight * 16);
  printf("[MESSAGE] Font texture of size (%i, %i).\n", BFont->FTextureWidth, BFont->FTextureHeight);
  
  unsigned char *BData = NULL;
  unsigned char *BText = (unsigned char *)malloc(sizeof(unsigned char) * 2);
  BText[0] = 0;
  BText[1] = '\0';

  // Create texture data .
  cairo_surface_t *BSurface = cairo_image_surface_create(CAIRO_FORMAT_A8,
                                                         BFont->FTextureWidth,
                                                         BFont->FTextureHeight);
  cairo_t *BContext = cairo_create(BSurface);
  
  cairo_set_antialias(BContext, CAIRO_ANTIALIAS_NONE);
  cairo_set_operator(BContext, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(BContext, 0.0, 0.0, 0.0, 0.0);
  
  cairo_font_options_t *cfo = cairo_font_options_create();
  cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_SUBPIXEL);
  cairo_set_font_options(BContext, cfo);
  cairo_set_source_rgba(BContext, 0.0, 0.0, 0.0, 1.0);
  cairo_select_font_face(BContext, AFontName, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  cairo_set_font_size(BContext, AHeight);
  
  for (BText[0] = 0; BText[0] < 255; BText[0]++)
  {
    cairo_text_extents(BContext, BText, BExtents);
    if (BExtents)
    {
      BCharExtent->FAdvanceX = BExtents->x_advance;
      if (BText[0] == 32)
      {
        //BCharExtent->FAdvanceX = BFont->FGridWidth;
      };
      BCharExtent->FAdvanceY = BExtents->y_advance;
      BCharExtent->FBearingX = BExtents->x_bearing;
      BCharExtent->FBearingY = BExtents->y_bearing;
      BCharExtent->FWidth = BExtents->width;
      BCharExtent->FHeight = BExtents->height;
      BRow = BText[0] / 16;
      BColumn = BText[0] % 16;
      cairo_move_to(BContext, -BExtents->x_bearing + (BColumn * BFont->FGridWidth), -BExtents->y_bearing + (BRow * BFont->FGridHeight));
      cairo_show_text(BContext, BText);
    } else
    {
      printf("[MESSAGE] Fail to create font. Extents of char %i returned as null.\n", BText[0]);
      return NULL;
    };
    BCharExtent++;
  };
  cairo_surface_flush(BSurface);
  //cairo_surface_write_to_png(BSurface, "/home/felipefs/Desktop/texture.png");
  BData = cairo_image_surface_get_data(BSurface);
  glGenTextures(1, &BFont->FTexture);
  glBindTexture(GL_TEXTURE_2D, BFont->FTexture);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, BFont->FTextureWidth, BFont->FTextureHeight,
               0, GL_ALPHA, GL_UNSIGNED_BYTE, BData);
  
  cairo_destroy(BContext);
  cairo_surface_destroy(BSurface);
  //free(BData);
  if (glIsTexture(BFont->FTexture) == GL_FALSE)
  {
    printf("[ERROR] Fail to create character texture of size %ix%i.\n", BFont->FTextureWidth, BFont->FTextureHeight);
  };
  printf("[MESSAGE] Font created.\n");
  return BFont;
};
开发者ID:sphaero,项目名称:TableGUI,代码行数:88,代码来源:GUI_font.c


示例10: cairo_image_surface_create


//.........这里部分代码省略.........
    cairo_translate(cairoContext, 0.0, height);
    cairo_scale(cairoContext, 1.0, -1.0);

    if (cairo_status(cairoContext) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Could not create Cairo context\n");
        _error = true;
        return false;
    }

    // Fill the box with the background color
    cairo_save(cairoContext);
    cairo_set_operator(cairoContext, CAIRO_OPERATOR_SOURCE);

    const mf::Color& bgColor(_style->getBackgroundColor());
    cairo_set_source_rgba(cairoContext, bgColor.red, bgColor.green, bgColor.blue, bgColor.alpha);

    if (_shape == 0) {
        if (_cornerWidth > 0 && _cornerHeight > 0) {
            // TODO: Support independent corner width and height
            drawRoundedRect(cairoContext, 0, 0, imageSize.width, imageSize.height, _cornerWidth);
        } else {
            cairo_paint(cairoContext);
            if (_strokeThickness > 0.0f) {
                drawStrokedRect(cairoContext, 0, 0, imageSize.width, imageSize.height, _strokeThickness);
            }
        }
    } else if (_shape == 1) {
        strokeFillBezier(cairoContext, 0, 0, imageSize.width, imageSize.height, _strokeThickness);
    }

    cairo_restore(cairoContext);

    const Rect textRect = textRectForTextSize(textSize, imageSize, tight);

    if (_dropShadow) {
        const Rect shadowRect(textRect.x + shadowXOffset,
                              textRect.y + shadowYOffset,
                              textRect.size.width,
                              textRect.size.height);
        cairo_set_source_rgba(cairoContext,
                              _dropShadowColor.red,
                              _dropShadowColor.green,
                              _dropShadowColor.blue,
                              _dropShadowColor.alpha);

        drawText(cairoContext, _textContent, shadowRect, fontDescription, false);
    }

    cairo_set_source_rgba(cairoContext, _textColor.red, _textColor.green, _textColor.blue, _textColor.alpha);

    if (_textColor.alpha > 0.0) {
        drawText(cairoContext, _textContent, textRect, fontDescription, true);
    }

    // DEBUG: Dump rendered text to an image
    // cairo_surface_write_to_png(cairoSurface, "text.png");

    // Transfer Cairo surface to OpenGL texture
    GLubyte* imageData = static_cast<GLubyte *>(cairo_image_surface_get_data(cairoSurface));

    glGenTextures(1, &_texture.textureID);
    glBindTexture(GL_TEXTURE_2D, _texture.textureID);

    _texture.width = width;
    _texture.height = height;
    _texture.s = 1.0;
    _texture.t = 1.0;
    _texture.aspect = static_cast<GLfloat>(_texture.width) / _texture.height;
    _texture.flipImage = true;

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

#ifdef GL_BGRA
    // Allocate and transfer data into texture (allow OpenGL swizzling)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, imageData);
#else
    // Cairo uses a BGRA layout, OpenGL ES 2.0 does not support GL_BGRA as a
    // source format so manually perform swizzling.
    for (size_t i = 0; i < width * height * BYTES_PER_PIXEL; i += BYTES_PER_PIXEL) {
        std::swap(imageData[i], imageData[i + 2]);
    }

    // Allocate and transfer data into texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
#endif

    // Clean up
    pango_font_description_free(fontDescription);
    cairo_destroy(cairoContext);
    cairo_surface_destroy(cairoSurface);
    g_object_unref(pangoFont);

    _loading = false;
    _loaded = !_loading && !_error;

    return true;
}
开发者ID:CaringLabs,项目名称:MediaFramework,代码行数:101,代码来源:TextAsset.cpp


示例11: RenderText

/* Print text scale */
void RenderText() {
	int i = 0;
	cairo_surface_t *surface;
        cairo_t *cr;
	const unsigned char* surfaceData;

	if (viewType == TWO_D){
		xX = -0.1, yY = 0.05, zZ = 0;
		}
	else {
		xX = -0.02, yY = 0, zZ = 0;
		}
	
	glColor3f(1, 1, 1);
	
	for (i = 0 + (zoom * hzStep); i <= ((hzStep * bandsNumber *zoomFactor) + (zoom * hzStep)); i+= ((hzStep * bandsNumber * zoomFactor)/10)) {
			
		sprintf(textToRender, "%d", i);
		
		surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 32, 32);
		cr = cairo_create (surface);
		//cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL,  CAIRO_FONT_WEIGHT_BOLD);
		cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
		if (viewType == TWO_D){
			cairo_set_font_size (cr, 8.0);
			cairo_move_to (cr, 0, 12);
			}
		else {
			cairo_set_font_size (cr, 10.0);
			cairo_move_to (cr, 0, 18);
			}		
		cairo_show_text (cr, textToRender);
		cairo_surface_flush(surface);
		surfaceData = cairo_image_surface_get_data (surface);
	
		unsigned Texture = 0;

		glGenTextures(1, &Texture);
		glBindTexture(GL_TEXTURE_2D, Texture);

		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), 0, GL_BGRA, GL_UNSIGNED_BYTE, surfaceData);
		
		glBegin(GL_QUADS);
		glColor4f(1, 1, 1, 1);
		glTexCoord2d(0, 0); glVertex3d(xX, yY, 0.01);
		glTexCoord2d(1, 0); glVertex3d(xX+0.1, yY, 0.01);
		glTexCoord2d(1, 1); glVertex3d(xX+0.1, yY-0.2, 0.01);
		glTexCoord2d(0, 1); glVertex3d(xX, yY-0.2, 0.01);
		glEnd();
		
		glDeleteTextures(1, &Texture);
		cairo_destroy (cr);
                cairo_surface_destroy (surface);
		
		if (viewType == TWO_D){
			yY += y_2d/10;
			}
		else {
			xX += x/10;
			}
	}
}
开发者ID:sgrady2,项目名称:C-VtkVis,代码行数:65,代码来源:scale.c


示例12: ImageSource

bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
{
    // This implementation is taken from GraphicsContext3DCairo.

    if (!m_image)
        return false;

    // We need this to stay in scope because the native image is just a shallow copy of the data.
    m_decoder = new ImageSource(premultiplyAlpha ? ImageSource::AlphaPremultiplied : ImageSource::AlphaNotPremultiplied, ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied);

    if (!m_decoder)
        return false;

    ImageSource& decoder = *m_decoder;
    m_alphaOp = AlphaDoNothing;

    if (m_image->data()) {
        decoder.setData(m_image->data(), true);

        if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0))
            return false;

        m_imageSurface = decoder.createFrameAtIndex(0);
    } else {
        m_imageSurface = m_image->nativeImageForCurrentFrame();
        // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAlpha had been applied and the alpha value is 0xFF for each pixel,
        // which is true at present and may be changed in the future and needs adjustment accordingly.
        // 2. For texImage2D with HTMLCanvasElement input in which Alpha is already Premultiplied in this port,
        // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to false.
        if (!premultiplyAlpha && m_imageHtmlDomSource != HtmlDomVideo)
            m_alphaOp = AlphaDoUnmultiply;
    }

    if (!m_imageSurface)
        return false;

    m_imageWidth = cairo_image_surface_get_width(m_imageSurface.get());
    m_imageHeight = cairo_image_surface_get_height(m_imageSurface.get());

    if (!m_imageWidth || !m_imageHeight)
        return false;

    if (cairo_image_surface_get_format(m_imageSurface.get()) != CAIRO_FORMAT_ARGB32)
        return false;

    uint srcUnpackAlignment = 1;
    size_t bytesPerRow = cairo_image_surface_get_stride(m_imageSurface.get());
    size_t bitsPerPixel = 32;
    unsigned padding = bytesPerRow - bitsPerPixel / 8 * m_imageWidth;

    if (padding) {
        srcUnpackAlignment = padding + 1;
        while (bytesPerRow % srcUnpackAlignment)
            ++srcUnpackAlignment;
    }

    m_imagePixelData = cairo_image_surface_get_data(m_imageSurface.get());
    m_imageSourceFormat = DataFormatBGRA8;
    m_imageSourceUnpackAlignment = srcUnpackAlignment;

    return true;
}
开发者ID:valbok,项目名称:WebKitForWayland,代码行数:62,代码来源:GraphicsContext3DEfl.cpp


示例13: gimp_color_bar_expose

static gboolean
gimp_color_bar_expose (GtkWidget      *widget,
                       GdkEventExpose *event)
{
  GimpColorBar    *bar = GIMP_COLOR_BAR (widget);
  cairo_t         *cr;
  GtkAllocation    allocation;
  cairo_surface_t *surface;
  cairo_pattern_t *pattern;
  guchar          *src;
  guchar          *dest;
  gint             x, y;
  gint             width, height;
  gint             i;

  cr = gdk_cairo_create (event->window);

  gdk_cairo_region (cr, event->region);
  cairo_clip (cr);

  gtk_widget_get_allocation (widget, &allocation);

  x = y = gtk_container_get_border_width (GTK_CONTAINER (bar));

  width  = allocation.width  - 2 * x;
  height = allocation.height - 2 * y;

  if (width < 1 || height < 1)
    return TRUE;

  cairo_translate (cr, allocation.x + x, allocation.y + y);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_clip (cr);

  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1);

  for (i = 0, src = bar->buf, dest = cairo_image_surface_get_data (surface);
       i < 256;
       i++, src += 3, dest += 4)
    {
      GIMP_CAIRO_RGB24_SET_PIXEL(dest, src[0], src[1], src[2]);
    }

  cairo_surface_mark_dirty (surface);

  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
  cairo_surface_destroy (surface);

  if (bar->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      cairo_scale (cr, (gdouble) width / 256.0, 1.0);
    }
  else
    {
      cairo_translate (cr, 0, height);
      cairo_scale (cr, 1.0, (gdouble) height / 256.0);
      cairo_rotate (cr, - G_PI / 2);
    }

  cairo_set_source (cr, pattern);
  cairo_pattern_destroy (pattern);

  cairo_paint (cr);

  cairo_destroy (cr);

  return TRUE;
}
开发者ID:AjayRamanathan,项目名称:gimp,代码行数:69,代码来源:gimpcolorbar.c


示例14: write_ppm

static const char *
write_ppm (cairo_surface_t *surface, int fd)
{
    char buf[4096];
    cairo_format_t format;
    const char *format_str;
    const unsigned char *data;
    int len;
    int width, height, stride;
    int i, j;

    data = cairo_image_surface_get_data (surface);
    height = cairo_image_surface_get_height (surface);
    width = cairo_image_surface_get_width (surface);
    stride = cairo_image_surface_get_stride (surface);
    format = cairo_image_surface_get_format (surface);
    if (format == CAIRO_FORMAT_ARGB32) {
	/* see if we can convert to a standard ppm type and trim a few bytes */
	const unsigned char *alpha = data;
	for (j = height; j--; alpha += stride) {
	    for (i = 0; i < width; i++) {
		if ((*(unsigned int *) (alpha+4*i) & 0xff000000) != 0xff000000)
		    goto done;
	    }
	}
	format = CAIRO_FORMAT_RGB24;
 done: ;
    }

    switch (format) {
    case CAIRO_FORMAT_ARGB32:
	/* XXX need true alpha for svg */
	format_str = "P7";
	break;
    case CAIRO_FORMAT_RGB24:
	format_str = "P6";
	break;
    case CAIRO_FORMAT_A8:
	format_str = "P5";
	break;
    case CAIRO_FORMAT_A1:
    case CAIRO_FORMAT_RGB16_565:
    case CAIRO_FORMAT_RGB30:
    case CAIRO_FORMAT_INVALID:
    default:
	return "unhandled image format";
    }

    len = sprintf (buf, "%s %d %d 255\n", format_str, width, height);
    for (j = 0; j < height; j++) {
	const unsigned int *row = (unsigned int *) (data + stride * j);

	switch ((int) format) {
	case CAIRO_FORMAT_ARGB32:
	    len = _cairo_write (fd,
			  buf, sizeof (buf), len,
			  (unsigned char *) row, 4 * width);
	    break;
	case CAIRO_FORMAT_RGB24:
	    for (i = 0; i < width; i++) {
		unsigned char rgb[3];
		unsigned int p = *row++;
		rgb[0] = (p & 0xff0000) >> 16;
		rgb[1] = (p & 0x00ff00) >> 8;
		rgb[2] = (p & 0x0000ff) >> 0;
		len = _cairo_write (fd,
			      buf, sizeof (buf), len,
			      rgb, 3);
	    }
	    break;
	case CAIRO_FORMAT_A8:
	    len = _cairo_write (fd,
			  buf, sizeof (buf), len,
			  (unsigned char *) row, width);
	    break;
	}
	if (len < 0)
	    return "write failed";
    }

    if (len && ! _cairo_writen (fd, buf, len))
	return "write failed";

    return NULL;
}
开发者ID:Ashod,项目名称:WinCairoRequirements,代码行数:85,代码来源:any2ppm.c


示例15: to_ninepatch

static bool_t to_ninepatch(cairo_surface_t * surface, struct lninepatch_t * patch)
{
	cairo_surface_t * cs;
	cairo_t * cr;
	unsigned char * data;
	int width, height;
	int stride;
	int w, h;
	int i;

	if(!surface || !patch)
		return FALSE;

	width = cairo_image_surface_get_width(surface);
	height = cairo_image_surface_get_height(surface);
	if(width < 3 || height < 3)
		return FALSE;

	/* Nine patch chunk */
	cs = cairo_surface_create_similar_image(surface, CAIRO_FORMAT_ARGB32, width, height);
	cr = cairo_create(cs);
	cairo_set_source_surface(cr, surface, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);
	data = cairo_image_surface_get_data(cs);
	stride = cairo_image_surface_get_stride(cs);

	/* Nine patch default size */
	width = width - 2;
	height = height - 2;
	patch->width = width;
	patch->height = height;

	/* Stretch information */
	patch->left = 0;
	patch->right = 0;
	patch->top = 0;
	patch->right = 0;

	for(i = 0; i < width; i++)
	{
		if(detect_black_pixel(&data[(i + 1) * 4]))
		{
			patch->left = i;
			break;
		}
	}
	for(i = width - 1; i >= 0; i--)
	{
		if(detect_black_pixel(&data[(i + 1) * 4]))
		{
			patch->right = width - 1 - i;
			break;
		}
	}
	for(i = 0; i < height; i++)
	{
		if(detect_black_pixel(&data[stride * (i + 1)]))
		{
			patch->top = i;
			break;
		}
	}
	for(i = height - 1; i >= 0; i--)
	{
		if(detect_black_pixel(&data[stride * (i + 1)]))
		{
			patch->bottom = height - 1 - i;
			break;
		}
	}
	cairo_surface_destroy(cs);

	/* Left top */
	w = patch->left;
	h = patch->top;
	if(w > 0 && h > 0)
	{
		cs = cairo_surface_create_similar(surface, cairo_surface_get_content(surface), patch->left, patch->top);
		cr = cairo_create(cs);
		cairo_set_source_surface(cr, surface, -1, -1);
		cairo_paint(cr);
		cairo_destroy(cr);
		patch->lt = cs;
	}
	else
	{
		patch->lt = NULL;
	}

	/* Middle top */
	w = width - patch->left - patch->right;
	h = patch->top;
	if(w > 0 && h > 0)
	{
		cs = cairo_surface_create_similar(surface, cairo_surface_get_content(surface), w, h);
		cr = cairo_create(cs);
		cairo_set_source_surface(cr, surface, -patch->left - 1, -1);
		cairo_paint(cr);
		cairo_destroy(cr);
//.........这里部分代码省略.........
开发者ID:philippe-nuaa,项目名称:xboot,代码行数:101,代码来源:l-ninepatch.c


示例16: find_signed_distance

static double find_signed_distance(
	int              px,
	int              py,
	cairo_surface_t* surface,
	int              scan_width,
	int              scan_height
) {
	int            width         = cairo_image_surface_get_width(surface);
	unsigned char* data          = cairo_image_surface_get_data(surface);
	unsigned char  base          = data[(px * width) + py];
	int            base_solid    = base > 0;
	double         closest       = MAX_VALUE;
	int            closest_valid = 0;
	int            start_x       = px - (scan_width / 2);
	int            end_x         = start_x + scan_width;
	int            start_y       = py - (scan_height / 2);
	int            end_y         = start_y + scan_height;

	int x;
	int y;

	for(x = start_x; x < end_x; x++) {
		if(x < 0 || x >= width) continue;

		for(y = start_y; y < end_y; y++) {
			unsigned char c;

			if(y < 0 || y >= width) continue;

			c = data[(x * width) + y];

			if(base_solid) {
				if(c == 0) {
					double dist = separation(px, py, x, y);

					if (dist < closest) {
						closest       = dist;
						closest_valid = 1;
					}
				}
			}

			else {
				if(c > 0) {
					double dist = separation(px, py, x, y);

					if(dist < closest) {
						closest       = dist;
						closest_valid = 1;
					}
				}
			}
		}
	}

	if(base_solid) {
		if(closest_valid) return closest;

		else return MAX_VALUE;
	}

	else {
		if(closest_valid) return -closest;

		else return MIN_VALUE;
	}
}
开发者ID:cubicool,项目名称:osgcairo,代码行数:67,代码来源:distance-field.c


示例17: PyErr_SetString

void TileEngine::renderPixels(
    cairo_surface_t *destSurf,
    cairo_surface_t *cmapSurf,
    PyObject *tileFunction,
    PyObject *tileMap,
    int renderCol,
    int renderRow,
    int renderCols,
    int renderRows)
{
    if ((tileFunction != Py_None) &&
	!PyCallable_Check(tileFunction)) {
	PyErr_SetString(
	    PyExc_TypeError,
	    "expected tileFunction to be a callable function or None");
	return;
    }

    // The tileMap should be None, or an array of 4 byte integers,
    // mapping virtual tiles indices to absolute tile numbers.

    const int *tileMapData = NULL;
    unsigned int tileMapCount = 0;

    if (tileMap != Py_None) {

        if (!PySequence_Check(tileMap)) {
	    PyErr_SetString(
		PyExc_TypeError,
		"expected tileMap to be an array "
		"of 4 byte integers or None");
	    return;
	}

	tileMapCount = (unsigned int)PySequence_Size(tileMap);
	Py_ssize_t tileMapLength = 0;
	if (PyObject_AsReadBuffer(
	    tileMap,
	    (const void **)&tileMapData,
	    &tileMapLength) != 0) {
	    PyErr_SetString(
		PyExc_TypeError,
		"expected tileMap with read buffer");
	    return;
	}

	int tileMapDataCount = 
	    (int)tileMapLength / sizeof(unsigned int);

	if (tileMapDataCount != (int)tileMapCount) {
	  PyErr_SetString(
	    PyExc_TypeError,
	    "expected tileMap read buffer of 4 byte integers");
	  return;
	}
    }

    unsigned char *destData = cairo_image_surface_get_data(destSurf);
    int destStride = cairo_image_surface_get_stride(destSurf);

    unsigned char *cmapData = cairo_image_surface_get_data(cmapSurf);
    int cmapWidth = cairo_image_surface_get_width(cmapSurf);
    int cmapStride = cairo_image_surface_get_stride(cmapSurf);

    int r;
    for (r = 0; r < renderRows; r++) {
	int c;
	for (c = 0; c  < renderCols; c++) {
	    int col = (renderCol + c) % width;
	    int row = (renderRow + r) % height;

	    unsigned long tile = 
		getValue(
		    col,
		    row,
		    tileFunction,
		    tileMapData,
		    tileMapCount);

	    int sourceX = tile % cmapWidth;
	    int sourceY = tile / cmapWidth;

	    unsigned char *sourcePixel =
		cmapData +
		(sourceX * 4) +
		(sourceY * cmapStride);

	    unsigned char *destPixel =
		destData +
		(c * 4) +
		(r * destStride);

	    *(long *)destPixel = *(long *)sourcePixel;
	}
    }
}
开发者ID:DaveInKentucky,项目名称:micropolis,代码行数:96,代码来源:tileengine.cpp


示例18: pango_loadimage_ps

static void pango_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, boolean filled)
{
    cairo_surface_t *surface; 	/* source surface */
    cairo_format_t format;
    int X, Y, x, y, stride;
    unsigned char *data, *ix, alpha, red, green, blue;

    surface = cairo_loadimage(job, us);
    if (surface) {
       	format = cairo_image_surface_get_format(surface);
        if ((format != CAIRO_F 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cairo_image_surface_get_format函数代码示例发布时间:2022-05-30
下一篇:
C++ cairo_image_surface_create_from_png函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap