示例#1
0
void evas_common_convert_rgba_to_8bpp_rgb_232_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith, dith2;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 3);
   dith2 = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
/*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 3);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith2) && (r < 0x03)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 3))) >= dith ) && (g < 0x07)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith2) && (b < 0x03)) b++;*/
   r = (R_VAL(src_ptr)) * 3 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith2) && (r < 0x03)) r++;
   g = (G_VAL(src_ptr)) * 7 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 7)) >= dith ) && (g < 0x07)) g++;
   b = (B_VAL(src_ptr)) * 3 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith2) && (b < 0x03)) b++;

   *dst_ptr = pal[(r << 5) | (g << 2) | (b)];

   CONVERT_LOOP_END_ROT_0();
}
示例#2
0
void evas_common_convert_rgba_to_8bpp_rgb_666_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith;
   static int tables_calcualted = 0;

   if (!tables_calcualted)
     {
	int i;

	tables_calcualted = 1;
	for (i = 0; i < 256; i++)
	  p_to_6[i] = (i * 5) / 255;
	for (i = 0; i < 256; i++)
	  p_to_6_err[i] = ((i * 5) - (p_to_6[i] * 255)) * DM_DIV / 255;
     }
   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   r = p_to_6[(R_VAL(src_ptr))];
   g = p_to_6[(G_VAL(src_ptr))];
   b = p_to_6[(B_VAL(src_ptr))];
   dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK];
   if ((p_to_6_err[(R_VAL(src_ptr))] >= dith ) && (r < 5)) r++;
   if ((p_to_6_err[(G_VAL(src_ptr))] >= dith ) && (g < 5)) g++;
   if ((p_to_6_err[(B_VAL(src_ptr))] >= dith ) && (b < 5)) b++;

   *dst_ptr = pal[(r * 36) + (g * 6) + (b)];

   CONVERT_LOOP_END_ROT_0();
}
示例#3
0
void
rg_etc2_rgba8_decode_block(const unsigned char *etc, unsigned int *bgra)
{
   const uint8_t zeros[7] = {0};
   uint32_t table_index;
   int base_codeword;
   int multiplier;

   base_codeword = etc[0];

   // Fast path if alpha is the same for all pixels
   if (!memcmp(etc + 1, zeros, 7))
     {
        if (!base_codeword)
          memset(bgra, 0, 64);
        else
          {
             rg_etc2_rgb8_decode_block(etc + 8, bgra);
             if (base_codeword != 255)
               for (int k = 0; k < 16; k++)
                 {
                    const uint32_t rgb = *bgra;
                    const int R = MIN(R_VAL(&rgb), base_codeword);
                    const int G = MIN(G_VAL(&rgb), base_codeword);
                    const int B = MIN(B_VAL(&rgb), base_codeword);
                    *bgra++ = BGRA(R, G, B, base_codeword);
                 }
          }
        return;
     }

   rg_etc2_rgb8_decode_block(etc + 8, bgra);

   multiplier = BITS(etc[1], 4, 7);
   table_index = BITS(etc[1], 0, 3);

   for (int x = 0, k = 0; x < 4; x++)
     for (int y = 0; y < 4; y++, k += 3)
       {
          const uint32_t byte = (k >> 3); // = [k/8]
          const uint32_t bit = k - (byte << 3); // = k%8
          const uint32_t rgb = bgra[(y << 2) + x];
          uint32_t index, alpha, R, G, B;

          if (bit < 6)
            index = BITS(etc[byte + 2], 5 - bit, 7 - bit);
          else if (bit == 6)
            index = (BITS(etc[byte + 2], 0, 1) << 1) | BIT(etc[byte + 3], 7);
          else // bit == 7
            index = (BIT(etc[byte + 2], 0) << 2) | BITS(etc[byte + 3], 6, 7);
          alpha = CLAMP(base_codeword + kAlphaModifiers[table_index][index] * multiplier);
          R = MIN(R_VAL(&rgb), alpha);
          G = MIN(G_VAL(&rgb), alpha);
          B = MIN(B_VAL(&rgb), alpha);
          bgra[(y << 2) + x] = BGRA(R, G, B, alpha);
       }
}
示例#4
0
static int
__imlib_FilterGet(ImlibFilterColor * fil, DATA32 * data,
                  int w, int h, int x, int y)
{
   int                 i, off, ret;
   ImlibFilterPixel   *pix;
   DATA32             *p;

   ret = fil->cons;
   pix = fil->pixels;
   for (i = fil->entries; --i >= 0;)
     {
        off = x + pix->xoff;
        if (off < 0)
           off = 0;
        if (off >= w)
           off = w - 1;
        p = data + off;
        off = y + pix->yoff;
        if (off < 0)
           off = 0;
        if (off >= h)
           off = h - 1;
        p += off * w;
        ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r +
            G_VAL(p) * pix->g + B_VAL(p) * pix->b;
        pix++;
     }
   return ret;
}
EAPI void
evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a)
{
   R_VAL(&(dc->col.col)) = (DATA8)r;
   G_VAL(&(dc->col.col)) = (DATA8)g;
   B_VAL(&(dc->col.col)) = (DATA8)b;
   A_VAL(&(dc->col.col)) = (DATA8)a;
}
示例#6
0
/*\ Filter an image with the a, r, g, b filters in fil
|*|  NB: This is currently not very optimal, and could probably be improved
\*/
void
__imlib_FilterImage(ImlibImage * im, ImlibFilter * fil)
{
   int                 x, y, a, r, g, b, ad, rd, gd, bd;
   DATA32             *data, *p1, *p2;

   data = malloc(im->w * im->h * sizeof(DATA32));
   if (!data)
      return;

   ad = __imlib_FilterCalcDiv(&fil->alpha);
   rd = __imlib_FilterCalcDiv(&fil->red);
   gd = __imlib_FilterCalcDiv(&fil->green);
   bd = __imlib_FilterCalcDiv(&fil->blue);

   p1 = im->data;
   p2 = data;

   for (y = 0; y < im->h; y++)
     {
        for (x = 0; x < im->w; x++)
          {
             *p2 = *p1;
             if (ad)
               {
                  a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x,
                                        y);
                  a /= ad;
                  A_VAL(p2) = SATURATE(a);
               }
             if (rd)
               {
                  r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x,
                                        y);
                  r /= rd;
                  R_VAL(p2) = SATURATE(r);
               }
             if (gd)
               {
                  g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x,
                                        y);
                  g /= gd;
                  G_VAL(p2) = SATURATE(g);
               }
             if (bd)
               {
                  b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x,
                                        y);
                  b /= bd;
                  B_VAL(p2) = SATURATE(b);
               }
             p1++;
             p2++;
          }
     }
   free(im->data);
   im->data = data;
}
示例#7
0
EAPI void
evas_common_draw_context_set_multiplier(RGBA_Draw_Context *dc, int r, int g, int b, int a)
{
   dc->mul.use = 1;
   R_VAL(&(dc->mul.col)) = (DATA8)r;
   G_VAL(&(dc->mul.col)) = (DATA8)g;
   B_VAL(&(dc->mul.col)) = (DATA8)b;
   A_VAL(&(dc->mul.col)) = (DATA8)a;
}
示例#8
0
void
__imlib_DataCmodApply(DATA32 * data, int w, int h, int jump,
                      ImlibImageFlags * fl, ImlibColorModifier * cm)
{
   int                 x, y;
   DATA32             *p;

   /* We might be adding alpha */
   if (fl && !(*fl & F_HAS_ALPHA))
     {
        p = data;
        for (y = 0; y < h; y++)
          {
             for (x = 0; x < w; x++)
               {
                  R_VAL(p) = R_CMOD(cm, R_VAL(p));
                  G_VAL(p) = G_CMOD(cm, G_VAL(p));
                  B_VAL(p) = B_CMOD(cm, B_VAL(p));
                  p++;
               }
             p += jump;
          }
        return;
     }

   p = data;
   for (y = 0; y < h; y++)
     {
        for (x = 0; x < w; x++)
          {
             R_VAL(p) = R_CMOD(cm, R_VAL(p));
             G_VAL(p) = G_CMOD(cm, G_VAL(p));
             B_VAL(p) = B_CMOD(cm, B_VAL(p));
             A_VAL(p) = A_CMOD(cm, A_VAL(p));
             p++;
          }
        p += jump;
     }
}
示例#9
0
/***********************************************************************
 * Evas helpers
 **********************************************************************/
static void
_context_get_color(RGBA_Draw_Context *dc, int *r, int *g, int *b, int *a)
{
   DATA32 col;

   if (dc->mul.use)
     col = dc->mul.col;
   else
     col = dc->col.col;

   *r = R_VAL(&col);
   *g = G_VAL(&col);
   *b = B_VAL(&col);
   *a = A_VAL(&col);
}
void evas_common_convert_rgba_to_8bpp_pal_gray64(DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x EINA_UNUSED, int dith_y EINA_UNUSED, DATA8 *pal)
{
    DATA32 *src_ptr;
    DATA8 *dst_ptr;
    int x, y;
    DATA8 Y;

    dst_ptr = dst;
    CONVERT_LOOP_START_ROT_0();

    /* RGB -> YUV conversion */
    Y = ((R_VAL(src_ptr) * 76) + 
         (G_VAL(src_ptr) * 151) + 
         (B_VAL(src_ptr) * 29)) >> 10;
    *dst_ptr = pal[Y];

    CONVERT_LOOP_END_ROT_0();
}
示例#11
0
EAPI void
evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a)
{
   R_VAL(&(dc->col.col)) = (DATA8)r;
   G_VAL(&(dc->col.col)) = (DATA8)g;
   B_VAL(&(dc->col.col)) = (DATA8)b;
   A_VAL(&(dc->col.col)) = (DATA8)a;
#ifdef HAVE_PIXMAN
   if (dc && dc->col.pixman_color_image)
     pixman_image_unref(dc->col.pixman_color_image);
   
   pixman_color_t pixman_color;
   
   pixman_color.alpha =  (dc->col.col & 0xff000000) >> 16;
   pixman_color.red = (dc->col.col & 0x00ff0000) >> 8;
   pixman_color.green = (dc->col.col & 0x0000ff00);
   pixman_color.blue = (dc->col.col & 0x000000ff) << 8;

   dc->col.pixman_color_image = pixman_image_create_solid_fill(&pixman_color);
#endif

}
示例#12
0
void
evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h)
{
   /* copy update image to out buf & convert */
   switch (buf->depth)
     {
      case OUTBUF_DEPTH_RGB_24BPP_888_888:
	/* copy & pack into 24bpp - if colorkey is enabled... etc. */
	  {
	     DATA8 thresh;
	     int xx, yy;
	     int row_bytes;
	     DATA8 *dest;
	     DATA32 colorkey;
	     DATA32 *src;
	     DATA8 *dst;

	     colorkey = buf->color_key;
	     thresh = buf->alpha_level;
	     row_bytes = buf->dest_row_bytes;
	     dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
	     if (buf->func.new_update_region)
	       {
		  dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
	       }
	     if (!dest) break;
	     if (buf->use_color_key)
	       {
		  for (yy = 0; yy < h; yy++)
		    {
		       dst = dest + (yy * row_bytes);
		       src = update->image.data + (yy * update->cache_entry.w);
		       for (xx = 0; xx < w; xx++)
			 {
			    if (A_VAL(src) > thresh)
			      {
				 *dst++ = R_VAL(src);
				 *dst++ = G_VAL(src);
				 *dst++ = B_VAL(src);
			      }
			    else
			      {
				 *dst++ = R_VAL(&colorkey);
				 *dst++ = G_VAL(&colorkey);
				 *dst++ = B_VAL(&colorkey);
			      }
			    src++;
			 }
		    }
	       }
	     else
	       {
		  for (yy = 0; yy < h; yy++)
		    {
		       dst = dest + (yy * row_bytes);
		       src = update->image.data + (yy * update->cache_entry.w);
		       for (xx = 0; xx < w; xx++)
			 {
			    *dst++ = R_VAL(src);
			    *dst++ = G_VAL(src);
			    *dst++ = B_VAL(src);
			    src++;
			 }
		    }
	       }
	     if (buf->func.free_update_region)
	       {
		  buf->func.free_update_region(x, y, w, h, dest);
	       }
	  }
	break;
      case OUTBUF_DEPTH_BGR_24BPP_888_888:
	/* copy & pack into 24bpp - if colorkey is enabled... etc. */
	  {
	     DATA8 thresh;
	     int xx, yy;
	     int row_bytes;
	     DATA8 *dest;
	     DATA32 colorkey;
	     DATA32 *src;
	     DATA8 *dst;

	     colorkey = buf->color_key;
	     thresh = buf->alpha_level;
	     row_bytes = buf->dest_row_bytes;
	     dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
	     if (buf->func.new_update_region)
	       {
		  dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
	       }
	     if (!dest) break;
	     if (buf->use_color_key)
	       {
		  for (yy = 0; yy < h; yy++)
		    {
		       dst = dest + (yy * row_bytes);
		       src = update->image.data + (yy * update->cache_entry.w);
		       for (xx = 0; xx < w; xx++)
			 {
			    if (A_VAL(src) > thresh)
			      {
				 *dst++ = B_VAL(src);
				 *dst++ = G_VAL(src);
				 *dst++ = R_VAL(src);
			      }
			    else
			      {
				 *dst++ = B_VAL(&colorkey);
				 *dst++ = G_VAL(&colorkey);
				 *dst++ = R_VAL(&colorkey);
			      }
			    src++;
			 }
		    }
	       }
	     else
	       {
		  for (yy = 0; yy < h; yy++)
		    {
		       dst = dest + (yy * row_bytes);
		       src = update->image.data + (yy * update->cache_entry.w);
		       for (xx = 0; xx < w; xx++)
			 {
			    *dst++ = B_VAL(src);
			    *dst++ = G_VAL(src);
			    *dst++ = R_VAL(src);
			    src++;
			 }
		    }
	       }
	     if (buf->func.free_update_region)
	       {
		  buf->func.free_update_region(x, y, w, h, dest);
	       }
	  }
	break;
      case OUTBUF_DEPTH_RGB_32BPP_888_8888:
      case OUTBUF_DEPTH_ARGB_32BPP_8888_8888:
	  {
	     DATA32 *dest, *src, *dst;
	     int yy, row_bytes;

	     row_bytes = buf->dest_row_bytes;
	     dest = (DATA32 *)((DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4));
	     if (buf->func.new_update_region)
	       {
		  dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
	       }
	     /* no need src == dest */
	     if (!buf->priv.back_buf)
	       {
		  Gfx_Func_Copy func;
		  
		  func = evas_common_draw_func_copy_get(w, 0);
		  if (func)
		    {
		       for (yy = 0; yy < h; yy++)
			 {
			    src = update->image.data + (yy * update->cache_entry.w);
			    dst = (DATA32 *)((DATA8 *)(buf->dest) + ((y + yy) * row_bytes));
			    func(src, dst, w);
			 }
		       
		    }
	       }
	     if (buf->func.free_update_region)
	       {
		  buf->func.free_update_region(x, y, w, h, dest);
	       }
	  }
	break;
      case OUTBUF_DEPTH_BGR_32BPP_888_8888:
	  {
	     DATA32 *src, *dst;
	     DATA8 *dest;
	     int xx, yy, row_bytes;
	     
	     row_bytes = buf->dest_row_bytes;
	     dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
	     if (buf->func.new_update_region)
	       {
		  dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
	       }
	     for (yy = 0; yy < h; yy++)
	       {
		  dst = (DATA32 *)(dest + (yy * row_bytes));
		  src = update->image.data + (yy * update->cache_entry.w);
		  for (xx = 0; xx < w; xx++)
		    {
		       A_VAL(dst) = B_VAL(src);
		       R_VAL(dst) = G_VAL(src);
		       G_VAL(dst) = R_VAL(src);
		       dst++;
		       src++;
		    }
	       }
	     if (buf->func.free_update_region)
	       {
		  buf->func.free_update_region(x, y, w, h, dest);
	       }
	 }
	break;
      case OUTBUF_DEPTH_BGRA_32BPP_8888_8888:
	  {
	     DATA32 *src, *dst;
	     DATA8 *dest;
	     int xx, yy, row_bytes;
	     
	     row_bytes = buf->dest_row_bytes;
	     dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
	     if (buf->func.new_update_region)
	       {
		  dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
	       }
	     for (yy = 0; yy < h; yy++)
	       {
		  dst = (DATA32 *)(dest + (yy * row_bytes));
		  src = update->image.data + (yy * update->cache_entry.w);
		  for (xx = 0; xx < w; xx++)
		    {
		       A_VAL(dst) = B_VAL(src);
		       R_VAL(dst) = G_VAL(src);
		       G_VAL(dst) = R_VAL(src);
		       dst++;
		       src++;
		    }
	       }
	     if (buf->func.free_update_region)
	       {
		  buf->func.free_update_region(x, y, w, h, dest);
	       }
	 }
	break;
      default:
	break;
     }
}
示例#13
0
static void
_bumpmap(Efx_Bumpmap_Data *ebd)
{
   Evas_Object  *o;
   int w;
   int h;
   int i, j;

   int x;
   int y;
   int z;
   int depth;
   int red;
   int green;
   int blue;
   int ambient;

   double z_2, lightx, lighty;
   int mx;
   int my;
   unsigned int *d1;
   unsigned int *d2;
   unsigned int *src;
   unsigned int *mp;
   unsigned int *mpy;
   unsigned int *mpp;

   x = ebd->x;
   y = ebd->y;
   z = ebd->z;

   red = ebd->red / 0x100;
   green = ebd->green / 0x100;
   blue = ebd->blue / 0x100;
   ambient = ebd->ambient / 0x100;
   depth = ebd->depth / 0x100;
   depth /= (255 * (255 + 255 + 255));
   z_2 = z * z;

   o = ebd->e->obj;
   evas_object_image_size_get(o, &w, &h);
   if ((!w) || (!h)) return;

   d1 = malloc(w * h * sizeof(int));
   memcpy(d1, ebd->img_data, w * h * sizeof(int));
   src = d1;

   d2 = malloc(w * h * sizeof(int));
   memcpy(d2, ebd->img_data, w * h * sizeof(int));
   mpp = d2;

   my = h;
   lighty = -y;
   for (j = h; --j >= 0;)
     {
       mp = mpp;
       mpp += w;
       if (--my <= 0)
         {
           mpp -= w * h;
           my = h;
         }
       mpy = mpp;
       mx = w;
       lightx = -x;
       i = w - 1;
       do
         {
            double x1, y_1, v;
            int r, g, b, gr;

            gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp));
            y_1 = depth * (double)(A_VAL(mpy) * (R_VAL(mpy) +
                                                G_VAL(mpy) +
                                                B_VAL(mpy)) -
                                  gr);
            mp++;
            mpy++;
            if (--mx <= 0)
              {
                mp -= w;
                mpy -= w;
                mx = w;
              }
            x1 = depth * (double)(A_VAL(mp) * (R_VAL(mp) +
                                           G_VAL(mp) + B_VAL(mp)) - gr);
            v = x1 * lightx + y_1 * lighty + z;
            v /= sqrt((x1 * x1) + (y_1 * y_1) + 1.0);
            v /= sqrt((lightx * lightx) + (lighty * lighty) + z_2);
            v += ambient;
            r = v * R_VAL(src) * red;
            g = v * G_VAL(src) * green;
            b = v * B_VAL(src) * blue;
            if (r < 0)
              r = 0;
            else if (r > 255)
              r = 255;
            if (g < 0)
              g = 0;
            else if (g > 255)
              g = 255;
            if (b < 0)
              b = 0;
            else if (b > 255)
              b = 255;
            R_VAL(src) = r;
            G_VAL(src) = g;
            B_VAL(src) = b;

            lightx++;
            src++;
         } while (--i >= 0);
       lighty++;
     }

   unsigned int *m;
   m = (unsigned int *)evas_object_image_data_get(o, 1);
   memcpy(m, d1, w * h * sizeof(unsigned int));
   evas_object_image_data_set(o, m);
   evas_object_image_data_update_add(o, 0, 0, w, h);
   free(d1);
   free(d2);
}
Eina_Bool
evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error)
{
   unsigned int         w, h;
   int                  alpha, compression, quality, lossy, ok;
   Eet_File            *ef;
   DATA32              *body, *p, *end;
   DATA32               nas = 0;
   Eina_Bool		res = EINA_FALSE;

   if (!key)
     {
	*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   if (ie->flags.loaded)
     {
	*error = EVAS_LOAD_ERROR_NONE;
	return EINA_TRUE;
     }
   ef = eet_open(file, EET_FILE_MODE_READ);
   if (!ef)
     {
	*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   ok = eet_data_image_header_read(ef, key,
				   &w, &h, &alpha, &compression, &quality, &lossy);
   if (IMG_TOO_BIG(w, h))
     {
	*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
	goto on_error;
     }
   if (!ok)
     {
	*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
	goto on_error;
     }
   evas_cache_image_surface_alloc(ie, w, h);
   ok = eet_data_image_read_to_surface(ef, key, 0, 0,
				       evas_cache_image_pixels(ie), w, h, w * 4,
				       &alpha, &compression, &quality, &lossy);
   if (!ok)
     {
	*error = EVAS_LOAD_ERROR_GENERIC;
	goto on_error;
     }
   if (alpha)
     {
	ie->flags.alpha = 1;

	body = evas_cache_image_pixels(ie);

	end = body +(w * h);
	for (p = body; p < end; p++)
	  {
	     DATA32 r, g, b, a;

	     a = A_VAL(p);
	     r = R_VAL(p);
	     g = G_VAL(p);
	     b = B_VAL(p);
	     if ((a == 0) || (a == 255)) nas++;
	     if (r > a) r = a;
	     if (g > a) g = a;
	     if (b > a) b = a;
	     *p = ARGB_JOIN(a, r, g, b);
	  }
	if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
	  ie->flags.alpha_sparse = 1;
     }
// result is already premultiplied now if u compile with edje
//   evas_common_image_premul(im);
   *error = EVAS_LOAD_ERROR_NONE;
   res = EINA_TRUE;

 on_error:
   eet_close(ef);
   return res;
}
示例#15
0
#ifdef BUILD_CONVERT_8_GRY_1
void evas_common_convert_rgba_to_8bpp_gry_256_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x __UNUSED__, int dith_y __UNUSED__, DATA8 *pal __UNUSED__)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA32 gry8;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   r = (R_VAL(src_ptr));
   g = (G_VAL(src_ptr));
   b = (B_VAL(src_ptr));

   // Y = 0.299 * R + 0.587 * G + 0.114 * B;
   gry8 = ((r * 19595) + (g * 38469) + (b * 7471)) >> 16;

   *dst_ptr = gry8;

   CONVERT_LOOP_END_ROT_0();
}
#endif

#ifdef BUILD_CONVERT_8_GRY_4
void evas_common_convert_rgba_to_8bpp_gry_64_dith      (DATA32 *src __UNUSED__, DATA8 *dst __UNUSED__, int src_jump __UNUSED__, int dst_jump __UNUSED__, int w __UNUSED__, int h __UNUSED__, int dith_x __UNUSED__, int dith_y __UNUSED__, DATA8 *pal __UNUSED__){}
#endif

#ifdef BUILD_CONVERT_8_GRY_16
示例#16
0
static void
eng_image_draw(void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth)
{
   Render_Engine *re;
   Evas_Cairo_Context *ctxt;
   Evas_Cairo_Image *im;
   DATA32 *pix;

   re = (Render_Engine *)data;
   ctxt = (Evas_Cairo_Context *)context;
   if (!image) return;

   im = image;
   evas_common_load_image_data_from_file(im->im);
   pix = im->im->image->data;
   if (pix)
     {
	if (!im->surface)
	  {
	     im->mulpix = malloc(im->im->image->w * im->im->image->h * sizeof(DATA32));
	     if (im->mulpix)
	       {
		  int i, n;
		  DATA32 *p;

		  n = im->im->image->w * im->im->image->h;
		  p = im->mulpix;
		  for (i = 0; i < n; i++)
		    {
		       int a;

		       a = A_VAL(pix);
		       R_VAL(p) = (R_VAL(pix) * a) / 255;
		       G_VAL(p) = (G_VAL(pix) * a) / 255;
		       B_VAL(p) = (B_VAL(pix) * a) / 255;
		       A_VAL(p) = a;
		       p++;
		       pix++;
		    }
		  im->surface = cairo_image_surface_create_for_data(im->mulpix,
								    CAIRO_FORMAT_ARGB32,
								    im->im->image->w,
								    im->im->image->h,
								    0);
		  im->pattern = cairo_pattern_create_for_surface(im->surface);
	       }
	  }

	if (smooth)
	  cairo_pattern_set_filter(im->pattern, CAIRO_FILTER_BILINEAR);
	else
	  cairo_pattern_set_filter(im->pattern, CAIRO_FILTER_NEAREST);
	cairo_save(ctxt->cairo);
	cairo_translate(ctxt->cairo, dst_x, dst_y);
	cairo_scale(ctxt->cairo,
		    (double)src_w / (double)dst_w,
		    (double)src_h / (double)dst_h);
	cairo_move_to(ctxt->cairo, 0, 0);
	//     cairo_set_rgb_color(re->win->cairo,
	//			  (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0,
	//			  (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0,
	//			  (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0);
	//     cairo_set_alpha(re->win->cairo,
	//		     (double)(A_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0);
	cairo_set_source_surface(ctxt->cairo,
				 im->surface,
				 im->im->image->w,
				 im->im->image->h);
	cairo_paint(ctxt->cairo);
	cairo_restore(ctxt->cairo);
     }
}
示例#17
0
static              Imlib_Image
bump_map(Imlib_Image im, pIFunctionParam par)
{
   Imlib_Image         map = im;
   pIFunctionParam     ptr;
   double              an = 0, el = 30, d = 0x200;
   double              red = 0x200, green = 0x200, blue = 0x200;
   double              ambient = 0;

   int                 free_map = 0;
   DATA32             *src;
   DATA32             *mp, *mpy, *mpp;
   double              z, x2, y2;
   int                 w, h, i, j, w2, h2, wh2, mx, my;

   for (ptr = par; ptr; ptr = ptr->next)
     {
        ASSIGN_IMAGE("map", map);
        ASSIGN_INT("angle", an);
        ASSIGN_INT("elevation", el);
        ASSIGN_INT("depth", d);
        ASSIGN_INT("red", red);
        ASSIGN_INT("green", green);
        ASSIGN_INT("blue", blue);
        ASSIGN_INT("ambient", ambient);
     }
   if (!map)
      return im;

   red /= 0x100;
   green /= 0x100;
   blue /= 0x100;
   ambient /= 0x100;
   d /= 0x100;

   imlib_context_set_image(im);
   src = imlib_image_get_data();
   w = imlib_image_get_width();
   h = imlib_image_get_height();

   imlib_context_set_image(map);
   mpp = imlib_image_get_data_for_reading_only();
   w2 = imlib_image_get_width();
   h2 = imlib_image_get_height();
   wh2 = w2 * h2;

   an *= (PI / 180);
   el *= (PI / 180);

   x2 = sin(an) * cos(el);
   y2 = cos(an) * cos(el);
   z = sin(el);

   d /= (255 * (255 + 255 + 255));

   my = h2;
   for (j = h; --j >= 0;)
     {
        mp = mpp;
        mpp += w2;
        if (--my <= 0)
          {
             mpp -= wh2;
             my = h2;
          }
        mpy = mpp;
        mx = w2;
        for (i = w; --i >= 0;)
          {
             double              x1, y1, v;
             int                 r, g, b, gr;

             gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp));
             y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) +
                                             G_VAL(mpy) + B_VAL(mpy)) - gr);
             mp++;
             mpy++;
             if (--mx <= 0)
               {
                  mp -= w2;
                  mpy -= w2;
                  mx = w2;
               }
             x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) +
                                            G_VAL(mp) + B_VAL(mp)) - gr);
             v = x1 * x2 + y1 * y2 + z;
             v /= sqrt((x1 * x1) + (y1 * y1) + 1.0);
             v += ambient;
             r = v * R_VAL(src) * red;
             g = v * G_VAL(src) * green;
             b = v * B_VAL(src) * blue;
             if (r < 0)
                r = 0;
             if (r > 255)
                r = 255;
             if (g < 0)
                g = 0;
             if (g > 255)
                g = 255;
             if (b < 0)
                b = 0;
             if (b > 255)
                b = 255;
             R_VAL(src) = r;
             G_VAL(src) = g;
             B_VAL(src) = b;

             src++;
          }
     }
   if (free_map)
     {
        imlib_context_set_image(map);
        imlib_free_image();
     }
   return im;
}
示例#18
0
文件: evas_engine.c 项目: Limsik/e17
/* internal engine routines */
static void *
_output_setup(int w,
	      int h,
	      void *dest_buffer,
	      int dest_buffer_row_bytes,
	      int depth_type,
	      int use_color_key,
	      int alpha_threshold,
	      int color_key_r,
	      int color_key_g,
	      int color_key_b,
	      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),
              void *(*switch_buffer) (void *data, void *dest_buffer),
              void *switch_data
	      )
{
   Render_Engine *re;

   re = calloc(1, sizeof(Render_Engine));
   if (!re)
     return NULL;
   /* if we haven't initialized - init (automatic abort if already done) */
   evas_common_cpu_init();

   evas_common_blend_init();
   evas_common_image_init();
   evas_common_convert_init();
   evas_common_scale_init();
   evas_common_rectangle_init();
   evas_common_polygon_init();
   evas_common_line_init();
   evas_common_font_init();
   evas_common_draw_init();
   evas_common_tilebuf_init();

   evas_buffer_outbuf_buf_init();

     {
	Outbuf_Depth dep;
	DATA32 color_key = 0;

	dep = OUTBUF_DEPTH_BGR_24BPP_888_888;
	if      (depth_type == EVAS_ENGINE_BUFFER_DEPTH_ARGB32)
	  dep = OUTBUF_DEPTH_ARGB_32BPP_8888_8888;
	else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB32)
	  dep = OUTBUF_DEPTH_RGB_32BPP_888_8888;
	else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGRA32)
	  dep = OUTBUF_DEPTH_BGRA_32BPP_8888_8888;
	else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB24)
	  dep = OUTBUF_DEPTH_RGB_24BPP_888_888;
	else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGR24)
	  dep = OUTBUF_DEPTH_BGR_24BPP_888_888;
	R_VAL(&color_key) = color_key_r;
	G_VAL(&color_key) = color_key_g;
	B_VAL(&color_key) = color_key_b;
	A_VAL(&color_key) = 0;
	re->ob = evas_buffer_outbuf_buf_setup_fb(w,
						 h,
						 dep,
						 dest_buffer,
						 dest_buffer_row_bytes,
						 use_color_key,
						 color_key,
						 alpha_threshold,
						 new_update_region,
						 free_update_region,
                                                 switch_buffer,
                                                 switch_data);
     }
   re->tb = evas_common_tilebuf_new(w, h);
   evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
   eina_inarray_step_set(&re->previous_rects, sizeof (Eina_Inarray), sizeof (Eina_Rectangle), 8);
   return re;
}
示例#19
0
Eina_Bool
evas_image_load_file_data_eet(Evas_Img_Load_Params *ilp, const char *file, const char *key, int *error)
{
   unsigned int         w, h;
   int                  alpha, compression, quality, lossy, ok;
   Eet_File            *ef;
   DATA32              *body, *p, *end, *data;
   DATA32               nas = 0;
   Eina_Bool		res = EINA_FALSE;

   if (!key)
     {
	*error = CSERVE2_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   ef = eet_open(file, EET_FILE_MODE_READ);
   if (!ef)
     {
	*error = CSERVE2_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   ok = eet_data_image_header_read(ef, key,
				   &w, &h, &alpha, &compression, &quality, &lossy);
   if (IMG_TOO_BIG(w, h))
     {
	*error = CSERVE2_RESOURCE_ALLOCATION_FAILED;
	goto on_error;
     }
   if (!ok)
     {
	*error = CSERVE2_DOES_NOT_EXIST;
	goto on_error;
     }
   data = ilp->buffer;
   if (!data)
     {
	*error = CSERVE2_RESOURCE_ALLOCATION_FAILED;
	goto on_error;
     }
   ok = eet_data_image_read_to_surface(ef, key, 0, 0,
				       data, w, h, w * 4,
				       &alpha, &compression, &quality, &lossy);
   if (!ok)
     {
	*error = CSERVE2_GENERIC;
	goto on_error;
     }
   if (alpha)
     {
	ilp->alpha = 1;

	body = ilp->buffer;

	end = body + (w * h);
	for (p = body; p < end; p++)
	  {
	     DATA32 r, g, b, a;

	     a = A_VAL(p);
	     r = R_VAL(p);
	     g = G_VAL(p);
	     b = B_VAL(p);
	     if ((a == 0) || (a == 255)) nas++;
	     if (r > a) r = a;
	     if (g > a) g = a;
	     if (b > a) b = a;
	     *p = ARGB_JOIN(a, r, g, b);
	  }
	if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (w * h))
	  ilp->alpha_sparse = 1;
     }
   *error = CSERVE2_NONE;
   res = EINA_TRUE;

 on_error:
   eet_close(ef);
   return res;
}