2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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 License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "ImageGStreamer.h"
23 #if ENABLE(VIDEO) && USE(GSTREAMER)
25 #include <gst/video/video.h>
27 #ifdef GST_API_VERSION_1
28 #include <gst/video/gstvideometa.h>
31 #include <wtf/gobject/GOwnPtr.h>
34 using namespace WebCore;
36 ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
39 GstVideoFormat format;
41 int pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride;
42 getVideoSizeAndFormatFromCaps(caps, size, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride);
44 #ifdef GST_API_VERSION_1
46 gst_buffer_map(buffer, &info, GST_MAP_READ);
47 uchar* bufferData = reinterpret_cast<uchar*>(info.data);
49 uchar* bufferData = reinterpret_cast<uchar*>(GST_BUFFER_DATA(buffer));
51 QImage::Format imageFormat;
52 QImage::InvertMode invertMode;
53 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
54 if (format == GST_VIDEO_FORMAT_BGRA) {
55 imageFormat = QImage::Format_ARGB32;
56 invertMode = QImage::InvertRgba;
58 imageFormat = QImage::Format_RGB32;
59 invertMode = QImage::InvertRgb;
62 imageFormat = (format == GST_VIDEO_FORMAT_ARGB) ? QImage::Format_ARGB32 : QImage::Format_RGB32;
65 QImage image(bufferData, size.width(), size.height(), imageFormat);
67 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
68 image.invertPixels(invertMode);
71 m_image = BitmapImage::create(new QImage(image));
73 #ifdef GST_API_VERSION_1
74 if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))
75 setCropRect(FloatRect(cropMeta->x, cropMeta->y, cropMeta->width, cropMeta->height));
77 gst_buffer_unmap(buffer, &info);
81 ImageGStreamer::~ImageGStreamer()
88 #endif // USE(GSTREAMER)