aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/engines/common/evas_image_data.c
blob: 2815ff8dfb1ac88acdc0238147b753ebb27f60d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <assert.h>

#include "evas_common.h"
#include "evas_private.h"
#include "evas_image.h"

int
evas_common_rgba_image_from_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
{
   RGBA_Image   *dst = (RGBA_Image *) ie_dst;

   switch (cspace)
     {
     case EVAS_COLORSPACE_ARGB8888:
	dst->cache_entry.w = w;
	dst->cache_entry.h = h;
	dst->image.data = image_data;
	dst->image.no_free = 1;
	dst->cache_entry.flags.alpha = alpha ? 1 : 0;
	break;
      case EVAS_COLORSPACE_YCBCR422P601_PL:
      case EVAS_COLORSPACE_YCBCR422P709_PL:
      case EVAS_COLORSPACE_YCBCR422601_PL:
      case EVAS_COLORSPACE_YCBCR420TM12601_PL:
      case EVAS_COLORSPACE_YCBCR420NV12601_PL:
	w &= ~0x1;
	dst->cache_entry.w = w;
	dst->cache_entry.h = h;
	dst->cs.data = image_data;
	dst->cs.no_free = 1;
	break;
      default:
	abort();
	break;
     }
   dst->cache_entry.space = cspace;
   evas_common_image_colorspace_dirty(dst);
   _evas_common_rgba_image_post_surface(ie_dst);
   return 0;
}

int
evas_common_rgba_image_from_copied_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
{
   RGBA_Image   *dst = (RGBA_Image *) ie_dst;

   /* FIXME: Is dst->image.data valid. */
   switch (cspace)
     {
      case EVAS_COLORSPACE_ARGB8888:
         dst->cache_entry.flags.alpha = alpha ? 1 : 0;
         if (image_data)
           memcpy(dst->image.data, image_data, w * h * sizeof(DATA32));
         break;
      case EVAS_COLORSPACE_YCBCR422P601_PL:
      case EVAS_COLORSPACE_YCBCR422P709_PL:
      case EVAS_COLORSPACE_YCBCR422601_PL:
      case EVAS_COLORSPACE_YCBCR420TM12601_PL:
      case EVAS_COLORSPACE_YCBCR420NV12601_PL:
         dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char*) * 2);
         if (image_data && (dst->cs.data))
           memcpy(dst->cs.data,  image_data, dst->cache_entry.h * sizeof(unsigned char*) * 2);
         break;
      default:
         abort();
         break;
     }

   dst->cache_entry.space = cspace;
   evas_common_image_colorspace_dirty(dst);
   _evas_common_rgba_image_post_surface(ie_dst);
   return 0;
}

int
evas_common_rgba_image_size_set(Image_Entry *ie_dst, const Image_Entry *ie_im, unsigned int w, unsigned int h __UNUSED__)
{
   RGBA_Image   *dst = (RGBA_Image *) ie_dst;
   RGBA_Image   *im = (RGBA_Image *) ie_im;

   if ((im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
       (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P709_PL) ||
       (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422601_PL) ||
       (im->cache_entry.space == EVAS_COLORSPACE_YCBCR420TM12601_PL) ||
       (im->cache_entry.space == EVAS_COLORSPACE_YCBCR420NV12601_PL))
     {
        w &= ~0x1;
        dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
     }

   dst->flags = im->flags;
   dst->cs.no_free = 0;
   evas_common_image_colorspace_dirty(dst);

   _evas_common_rgba_image_post_surface(ie_dst);
   return 0;
}

int
evas_common_rgba_image_colorspace_set(Image_Entry* ie_dst, int cspace)
{
   RGBA_Image   *dst = (RGBA_Image *) ie_dst;

   switch (cspace)
     {
      case EVAS_COLORSPACE_ARGB8888:
	if (dst->cs.data)
	  {
	     if (!dst->cs.no_free) free(dst->cs.data);
	     dst->cs.data = NULL;
	     dst->cs.no_free = 0;
	  }
	break;
      case EVAS_COLORSPACE_YCBCR422P601_PL:
      case EVAS_COLORSPACE_YCBCR422P709_PL:
      case EVAS_COLORSPACE_YCBCR422601_PL:
      case EVAS_COLORSPACE_YCBCR420TM12601_PL:
      case EVAS_COLORSPACE_YCBCR420NV12601_PL:
	if (dst->image.no_free)
	  {
             ie_dst->allocated.w = 0;
             ie_dst->allocated.h = 0;
#ifdef BUILD_ASYNC_PRELOAD
             ie_dst->flags.preload_done = 0;
#endif
             ie_dst->flags.loaded = 0;
             dst->image.data = NULL;
	     dst->image.no_free = 0;
             /* FIXME: Must allocate image.data surface cleanly. */
	  }
	if (dst->cs.data)
	  {
	     if (!dst->cs.no_free) free(dst->cs.data);
	  }
	dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
	dst->cs.no_free = 0;
	break;
      default:
	abort();
	break;
     }
   dst->cache_entry.space = cspace;
   evas_common_image_colorspace_dirty(dst);

   _evas_common_rgba_image_post_surface(ie_dst);
   return 0;
}