move around - flatter.
[profile/ivi/evas.git] / src / lib / engines / common / evas_image_data.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #include <assert.h>
6
7 #include "evas_common.h"
8 #include "evas_private.h"
9
10 int
11 evas_common_rgba_image_from_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
12 {
13    RGBA_Image   *dst = (RGBA_Image *) ie_dst;
14
15    switch (cspace)
16      {
17      case EVAS_COLORSPACE_ARGB8888:
18         dst->cache_entry.w = w;
19         dst->cache_entry.h = h;
20         dst->image.data = image_data;
21         dst->image.no_free = 1;
22         dst->cache_entry.flags.alpha = alpha ? 1 : 0;
23         break;
24       case EVAS_COLORSPACE_YCBCR422P601_PL:
25       case EVAS_COLORSPACE_YCBCR422P709_PL:
26         w &= ~0x1;
27         dst->cache_entry.w = w;
28         dst->cache_entry.h = h;
29         dst->cs.data = image_data;
30         dst->cs.no_free = 1;
31         break;
32       default:
33         abort();
34         break;
35      }
36    dst->cache_entry.space = cspace;
37    evas_common_image_colorspace_dirty(dst);
38    return 0;
39 }
40
41 int
42 evas_common_rgba_image_from_copied_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
43 {
44    RGBA_Image   *dst = (RGBA_Image *) ie_dst;
45
46    /* FIXME: Is dst->image.data valid. */
47    switch (cspace)
48      {
49      case EVAS_COLORSPACE_ARGB8888:
50         dst->cache_entry.flags.alpha = alpha ? 1 : 0;
51         if (image_data)
52           memcpy(dst->image.data, image_data, w * h * sizeof(DATA32));
53         break;
54      case EVAS_COLORSPACE_YCBCR422P601_PL:
55      case EVAS_COLORSPACE_YCBCR422P709_PL:
56         dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char*) * 2);
57         if (image_data && (dst->cs.data))
58           memcpy(dst->cs.data,  image_data, dst->cache_entry.h * sizeof(unsigned char*) * 2);
59         break;
60      default:
61         abort();
62         break;
63      }
64
65    dst->cache_entry.space = cspace;
66    evas_common_image_colorspace_dirty(dst);
67    return 0;
68 }
69
70 int
71 evas_common_rgba_image_size_set(Image_Entry *ie_dst, const Image_Entry *ie_im, int w, int h)
72 {
73    RGBA_Image   *dst = (RGBA_Image *) ie_dst;
74    RGBA_Image   *im = (RGBA_Image *) ie_im;
75
76    if ((im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
77        (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P709_PL))
78      w &= ~0x1;
79
80    dst->flags = im->flags;
81    dst->cs.no_free = 0;
82    if ((im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
83        (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P709_PL))
84      dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
85    evas_common_image_colorspace_dirty(dst);
86
87    return 0;
88 }
89
90 int
91 evas_common_rgba_image_colorspace_set(Image_Entry* ie_dst, int cspace)
92 {
93    RGBA_Image   *dst = (RGBA_Image *) ie_dst;
94
95    switch (cspace)
96      {
97       case EVAS_COLORSPACE_ARGB8888:
98         if (dst->cs.data)
99           {
100              if (!dst->cs.no_free) free(dst->cs.data);
101              dst->cs.data = NULL;
102              dst->cs.no_free = 0;
103           }
104         break;
105       case EVAS_COLORSPACE_YCBCR422P601_PL:
106       case EVAS_COLORSPACE_YCBCR422P709_PL:
107         if (dst->image.no_free)
108           {
109              dst->image.data = NULL;
110              dst->image.no_free = 0;
111              /* FIXME: Must allocate image.data surface cleanly. */
112           }
113         if (dst->cs.data)
114           {
115              if (!dst->cs.no_free) free(dst->cs.data);
116           }
117         dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
118         dst->cs.no_free = 0;
119         break;
120       default:
121         abort();
122         break;
123      }
124    dst->cache_entry.space = cspace;
125    evas_common_image_colorspace_dirty(dst);
126
127    return 0;
128 }