summaryrefslogtreecommitdiff
path: root/src/modules/emotion/gstreamer1/emotion_convert.c
blob: 8ee43999669a4d70b2b53ecbcb48d77451558bb2 (plain) (blame)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "emotion_gstreamer.h"

static inline void
_evas_video_bgrx_step(unsigned char *evas_data, const unsigned char *gst_data,
                      unsigned int w, unsigned int h EINA_UNUSED,
                      unsigned int output_height, unsigned int step)
{
   unsigned int x, y;

   for (y = 0; y < output_height; ++y)
     {
        for (x = 0; x < w; x++)
          {
             evas_data[0] = gst_data[0];
             evas_data[1] = gst_data[1];
             evas_data[2] = gst_data[2];
             evas_data[3] = 255;
             gst_data += step;
             evas_data += 4;
          }
     }
}

static void
_evas_video_bgr(unsigned char *evas_data, const unsigned char *gst_data,
                unsigned int w, unsigned int h, unsigned int output_height,
                Emotion_Convert_Info *info EINA_UNUSED)
{
   // XXX: need to check offset and stride that gst provide and what they
   // mean with a non-planar format like bgra
   _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 3);
}

static void
_evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data,
                 unsigned int w, unsigned int h, unsigned int output_height,
                 Emotion_Convert_Info *info EINA_UNUSED)
{
   // XXX: need to check offset and stride that gst provide and what they
   // mean with a non-planar format like bgra
   _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 4);
}

static void
_evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data,
                 unsigned int w, unsigned int h EINA_UNUSED,
                 unsigned int output_height,
                 Emotion_Convert_Info *info EINA_UNUSED)
{
   unsigned int x, y;

   // XXX: need to check offset and stride that gst provide and what they
   // mean with a non-planar format like bgra
   for (y = 0; y < output_height; ++y)
     {
        unsigned char alpha;

        for (x = 0; x < w; ++x)
          {
             alpha = gst_data[3];
             evas_data[0] = (gst_data[0] * alpha) / 255;
             evas_data[1] = (gst_data[1] * alpha) / 255;
             evas_data[2] = (gst_data[2] * alpha) / 255;
             evas_data[3] = alpha;
             gst_data += 4;
             evas_data += 4;
          }
     }
}

static void
_evas_video_i420(unsigned char *evas_data,
                 const unsigned char *gst_data EINA_UNUSED,
                 unsigned int w EINA_UNUSED, unsigned int h EINA_UNUSED,
                 unsigned int output_height,
                 Emotion_Convert_Info *info)
{
   const unsigned char **rows, *ptr;
   unsigned int i, j, jump, rh;

   if (info->bpp[0] != 1) ERR("Plane 0 bpp != 1");
   if (info->bpp[1] != 1) ERR("Plane 1 bpp != 1");
   if (info->bpp[2] != 1) ERR("Plane 2 bpp != 1");

   rh = output_height;
   rows = (const unsigned char **)evas_data;

   ptr = info->plane_ptr[0];
   jump = info->stride[0];
   for (i = 0; i < rh; i++, ptr += jump) rows[i] = ptr;

   ptr = info->plane_ptr[1];
   jump = info->stride[1];
   for (j = 0; j < (rh / 2); j++, i++, ptr += jump) rows[i] = ptr;

   ptr = info->plane_ptr[2];
   jump = info->stride[2];
   for (j = 0; j < (rh / 2); j++, i++, ptr += jump) rows[i] = ptr;
}

static void
_evas_video_yv12(unsigned char *evas_data,
                 const unsigned char *gst_data EINA_UNUSED,
                 unsigned int w EINA_UNUSED, unsigned int h EINA_UNUSED,
                 unsigned int output_height,
                 Emotion_Convert_Info *info)
{
   const unsigned char **rows, *ptr;
   unsigned int i, j, jump, rh;

   if (info->bpp[0] != 1) ERR("Plane 0 bpp != 1");
   if (info->bpp[1] != 1) ERR("Plane 1 bpp != 1");
   if (info->bpp[2] != 1) ERR("Plane 2 bpp != 1");

   rh = output_height;
   rows = (const unsigned char **)evas_data;

   ptr = info->plane_ptr[0];
   jump = info->stride[0];
   for (i = 0; i < rh; i++, ptr += jump) rows[i] = ptr;

   ptr = info->plane_ptr[1];
   jump = info->stride[1];
   for (j = 0; j < (rh / 2); j++, i++, ptr += jump) rows[i] = ptr;

   ptr = info->plane_ptr[2];
   jump = info->stride[2];
   for (j = 0; j < (rh / 2); j++, i++, ptr += jump) rows[i] = ptr;
}

static void
_evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data,
                 unsigned int w, unsigned int h EINA_UNUSED,
                 unsigned int output_height,
                 Emotion_Convert_Info *info EINA_UNUSED)
{
   const unsigned char **rows;
   unsigned int i, stride;

   // XXX: need to check offset and stride that gst provide and what they
   // mean with a non-planar format like yuy2
   rows = (const unsigned char **)evas_data;

   stride = GST_ROUND_UP_4(w * 2);

   for (i = 0; i < output_height; i++) rows[i] = &gst_data[i * stride];
}

static void
_evas_video_nv12(unsigned char *evas_data,
                 const unsigned char *gst_data EINA_UNUSED,
                 unsigned int w EINA_UNUSED, unsigned int h EINA_UNUSED,
                 unsigned int output_height, Emotion_Convert_Info *info)
{
   const unsigned char **rows, *ptr;
   unsigned int i, j, jump, rh;

   if (info->bpp[0] != 1) ERR("Plane 0 bpp != 1");
   // XXX: not sure this should be 1 but 2 bytes per pixel... no?
   //if (info->bpp[1] != 1) ERR("Plane 1 bpp != 1");

   rh = output_height;
   rows = (const unsigned char **)evas_data;

   ptr = info->plane_ptr[0];
   jump = info->stride[0];
   for (i = 0; i < rh; i++, ptr += jump) rows[i] = ptr;

   ptr = info->plane_ptr[1];
   jump = info->stride[1];
   for (j = 0; j < (rh / 2); j++, i++, ptr += jump) rows[i] = ptr;
}

const ColorSpace_Format_Convertion colorspace_format_convertion[] = {
  { "I420-709", GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_BT709,
     EVAS_COLORSPACE_YCBCR422P709_PL, _evas_video_i420, EINA_TRUE },
  { "I420", GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_BT601,
     EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE },

  { "YV12-709", GST_VIDEO_FORMAT_YV12, GST_VIDEO_COLOR_MATRIX_BT709,
     EVAS_COLORSPACE_YCBCR422P709_PL, _evas_video_yv12, EINA_TRUE },
  { "YV12", GST_VIDEO_FORMAT_YV12, GST_VIDEO_COLOR_MATRIX_BT601,
     EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE },

  { "YUY2", GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_BT601,
     EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE },
  { "NV12", GST_VIDEO_FORMAT_NV12, GST_VIDEO_COLOR_MATRIX_BT601,
     EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
   // XXX:
   // XXX: need to add nv12 709 colorspace support to evas itself.
   // XXX: this makes gst streams work when they are nv12 709 but maybe
   // XXX: will display in slightly off color.. but in the end this needs
   // XXX: fixing to display correctly.
   // XXX:
  { "NV12-709", GST_VIDEO_FORMAT_NV12, GST_VIDEO_COLOR_MATRIX_BT709,
     EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
   // XXX:
   // XXX:
   // XXX:

  { "BGR", GST_VIDEO_FORMAT_BGR, GST_VIDEO_COLOR_MATRIX_UNKNOWN,
     EVAS_COLORSPACE_ARGB8888, _evas_video_bgr, EINA_FALSE },
  { "BGRx", GST_VIDEO_FORMAT_BGRx, GST_VIDEO_COLOR_MATRIX_UNKNOWN,
     EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx, EINA_FALSE },
  { "BGRA", GST_VIDEO_FORMAT_BGRA, GST_VIDEO_COLOR_MATRIX_UNKNOWN,
     EVAS_COLORSPACE_ARGB8888, _evas_video_bgra, EINA_FALSE },

  { NULL, 0, 0, 0, NULL, 0 }
};