<commit_before>#include "evas_common.h"
#include "evas_engine.h"

void
evas_buffer_outbuf_buf_init(void)
{
}

void
evas_buffer_outbuf_buf_free(Outbuf *buf)
{
   if (buf->priv.back_buf)
     {
        evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
     }
   free(buf);
}

Outbuf *
evas_buffer_outbuf_buf_setup_fb(int w, int h, Outbuf_Depth depth, void *dest, int dest_row_bytes, int use_color_key, DATA32 color_key, int alpha_level,
				void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes),
				void   (*free_update_region) (int x, int y, int w, int h, void *data)
				)
{
   Outbuf *buf;
   int y;
   int bpp;
   
   buf = calloc(1, sizeof(Outbuf));
   if (!buf) return NULL;

   buf->w = w;
   buf->h = h;
   buf->depth = depth;

   buf->dest = dest;
   buf->dest_row_bytes = dest_row_bytes;

   buf->alpha_level = alpha_level;
   buf->color_key = color_key;
   buf->use_color_key = use_color_key;

   buf->func.new_update_region = new_update_region;
   buf->func.free_update_region = free_update_region;

   bpp = sizeof(DATA32);
   if ((buf->depth == OUTBUF_DEPTH_RGB_24BPP_888_888) ||
       (buf->depth == OUTBUF_DEPTH_BGR_24BPP_888_888))
     bpp = 3;

   if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) &&
       (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
     {
	for (y = 0; y < h; y++)
	  memset(((unsigned char *)(buf->dest)) + (y * buf->dest_row_bytes), 
		 0, w * bpp);
	buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
                                                                  w, h,
                                                                  buf->dest,
                                                                  1, EVAS_COLORSPACE_ARGB8888);
     }
   else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) &&
       (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
     {
        buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
                                                                  w, h,
                                                                  buf->dest,
                                                                  0, EVAS_COLORSPACE_ARGB8888);
     }

   return buf;
}

RGBA_Image *
evas_buffer_outbuf_buf_new_region_for_update(Outbuf *buf, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch)
{
   RGBA_Image *im;

   if (buf->priv.back_buf)
     {
	*cx = x; *cy = y; *cw = w; *ch = h;
	return buf->priv.back_buf;
     }
   else
     {
	*cx = 0; *cy = 0; *cw = w; *ch = h;
	im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());<commit_msg>evas: ecore_evas_buffer_new(bla, *very large number*) would crash on memset<commit_after>#include "evas_common.h"
#include "evas_engine.h"

void
evas_buffer_outbuf_buf_init(void)
{
}

void
evas_buffer_outbuf_buf_free(Outbuf *buf)
{
   if (buf->priv.back_buf)
     {
        evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
     }
   free(buf);
}

Outbuf *
evas_buffer_outbuf_buf_setup_fb(int w, int h, Outbuf_Depth depth, void *dest, int dest_row_bytes, int use_color_key, DATA32 color_key, int alpha_level,
				void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes),
				void   (*free_update_region) (int x, int y, int w, int h, void *data)
				)
{
   Outbuf *buf;
   int bpp;
   
   buf = calloc(1, sizeof(Outbuf));
   if (!buf) return NULL;

   buf->w = w;
   buf->h = h;
   buf->depth = depth;

   buf->dest = dest;
   buf->dest_row_bytes = dest_row_bytes;

   buf->alpha_level = alpha_level;
   buf->color_key = color_key;
   buf->use_color_key = use_color_key;

   buf->func.new_update_region = new_update_region;
   buf->func.free_update_region = free_update_region;

   bpp = sizeof(DATA32);
   if ((buf->depth == OUTBUF_DEPTH_RGB_24BPP_888_888) ||
       (buf->depth == OUTBUF_DEPTH_BGR_24BPP_888_888))
     bpp = 3;

   if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) &&
       (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
     {
	memset(buf->dest, 0, h * buf->dest_row_bytes);
	buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
                                                                  w, h,
                                                                  buf->dest,
                                                                  1, EVAS_COLORSPACE_ARGB8888);
     }
   else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) &&
       (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
     {
        buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
                                                                  w, h,
                                                                  buf->dest,
                                                                  0, EVAS_COLORSPACE_ARGB8888);
     }

   return buf;
}

RGBA_Image *
evas_buffer_outbuf_buf_new_region_for_update(Outbuf *buf, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch)
{
   RGBA_Image *im;

   if (buf->priv.back_buf)
     {
	*cx = x; *cy = y; *cw = w; *ch = h;
	return buf->priv.back_buf;
     }
   else
     {
	*cx = 0; *cy = 0; *cw = w; *ch = h;
	im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
{'fraction_non_alphanumeric': 0.12667161961367013, 'fraction_numerical': 0.021731054977711738, 'mean_word_length': 2.0406549971767363, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5513438', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1912, 'n_words': 371}