2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
28 #include <videoflip.h>
31 #include "gstvideoflip.h"
33 static void gst_videoflip_planar411 (GstVideoflip *scale, unsigned char *dest, unsigned char *src);
35 static void gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
36 unsigned char *src, int sw, int sh, int dw, int dh);
38 struct videoflip_format_struct videoflip_formats[] = {
40 { "YV12", 12, gst_videoflip_planar411, },
41 { "I420", 12, gst_videoflip_planar411, },
44 int videoflip_n_formats = sizeof(videoflip_formats)/sizeof(videoflip_formats[0]);
47 videoflip_get_cap(struct videoflip_format_struct *format)
50 GstStructure *structure;
52 if(format->scale==NULL)
55 fourcc = GST_MAKE_FOURCC(format->fourcc[0],format->fourcc[1],format->fourcc[2],format->fourcc[3]);
58 structure = gst_structure_new("video/x-raw-rgb",
59 "depth", G_TYPE_INT, format->bpp,
60 "bpp", G_TYPE_INT, format->depth,
61 "endianness", G_TYPE_INT, format->endianness,
62 "red_mask", G_TYPE_INT, format->red_mask,
63 "green_mask", G_TYPE_INT, format->green_mask,
64 "blue_mask", G_TYPE_INT, format->blue_mask, NULL);
66 structure = gst_structure_new("video/x-raw-yuv",
67 "format", GST_TYPE_FOURCC, fourcc, NULL);
73 struct videoflip_format_struct *
74 videoflip_find_by_caps(const GstCaps *caps)
78 GST_DEBUG ("finding %p", caps);
80 g_return_val_if_fail(caps != NULL, NULL);
82 for (i = 0; i < videoflip_n_formats; i++){
85 c = gst_caps_new_full (videoflip_get_cap (videoflip_formats + i), NULL);
87 if(gst_caps_is_always_compatible(caps, c)){
89 return videoflip_formats + i;
99 gst_videoflip_setup (GstVideoflip *videoflip)
101 if(videoflip->from_width==0 || videoflip->from_height==0){
105 switch(videoflip->method){
106 case GST_VIDEOFLIP_METHOD_90R:
107 case GST_VIDEOFLIP_METHOD_90L:
108 case GST_VIDEOFLIP_METHOD_TRANS:
109 case GST_VIDEOFLIP_METHOD_OTHER:
110 videoflip->to_height = videoflip->from_width;
111 videoflip->to_width = videoflip->from_height;
113 case GST_VIDEOFLIP_METHOD_IDENTITY:
114 case GST_VIDEOFLIP_METHOD_180:
115 case GST_VIDEOFLIP_METHOD_HORIZ:
116 case GST_VIDEOFLIP_METHOD_VERT:
117 videoflip->to_height = videoflip->from_height;
118 videoflip->to_width = videoflip->from_width;
125 GST_DEBUG ("format=%p \"%s\" from %dx%d to %dx%d",
126 videoflip->format, videoflip->format->fourcc,
127 videoflip->from_width, videoflip->from_height,
128 videoflip->to_width, videoflip->to_height);
130 if(videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY){
131 GST_DEBUG ("videoflip: using passthru");
132 videoflip->passthru = TRUE;
133 videoflip->inited = TRUE;
137 videoflip->from_buf_size = (videoflip->from_width * videoflip->from_height
138 * videoflip->format->depth) / 8;
139 videoflip->to_buf_size = (videoflip->to_width * videoflip->to_height
140 * videoflip->format->depth) / 8;
142 videoflip->inited = TRUE;
146 gst_videoflip_planar411 (GstVideoflip *scale, unsigned char *dest, unsigned char *src)
148 int sw = scale->from_width;
149 int sh = scale->from_height;
150 int dw = scale->to_width;
151 int dh = scale->to_height;
153 GST_DEBUG ("videoflip: scaling planar 4:1:1 %dx%d to %dx%d", sw, sh, dw, dh);
155 gst_videoflip_flip(scale, dest, src, sw, sh, dw, dh);
165 gst_videoflip_flip(scale, dest, src, sw, sh, dw, dh);
170 gst_videoflip_flip(scale, dest, src, sw, sh, dw, dh);
174 gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
175 unsigned char *src, int sw, int sh, int dw, int dh)
179 switch(videoflip->method){
180 case GST_VIDEOFLIP_METHOD_90R:
183 dest[y*dw + x] = src[(sh - 1 - x)*sw + y];
187 case GST_VIDEOFLIP_METHOD_90L:
190 dest[y*dw + x] = src[x*sw + (sw - 1 - y)];
194 case GST_VIDEOFLIP_METHOD_180:
197 dest[y*dw + x] = src[(sh - 1 - y)*sw + (sw - 1 - x)];
201 case GST_VIDEOFLIP_METHOD_HORIZ:
204 dest[y*dw + x] = src[y*sw + (sw - 1 - x)];
208 case GST_VIDEOFLIP_METHOD_VERT:
211 dest[y*dw + x] = src[(sh - 1 - y)*sw + x];
215 case GST_VIDEOFLIP_METHOD_TRANS:
218 dest[y*dw + x] = src[x*sw + y];
222 case GST_VIDEOFLIP_METHOD_OTHER:
225 dest[y*dw + x] = src[(sh - 1 - x)*sw + (sw - 1 - y)];