1 /* 2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 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. 8 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. 13 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. 18 */ 19 20 #include "config.h" 21 #include "ImageGStreamer.h" 22 23 #if USE(GSTREAMER) 24 #include "GOwnPtr.h" 25 26 using namespace std; 27 using namespace WebCore; 28 29 PassRefPtr<ImageGStreamer> ImageGStreamer::createImage(GstBuffer* buffer) 30 { 31 int width = 0, height = 0; 32 GstCaps* caps = gst_buffer_get_caps(buffer); 33 GstVideoFormat format; 34 if (!gst_video_format_parse_caps(caps, &format, &width, &height)) { 35 gst_caps_unref(caps); 36 return 0; 37 } 38 39 gst_caps_unref(caps); 40 41 QImage::Format imageFormat; 42 if (format == GST_VIDEO_FORMAT_RGB) 43 imageFormat = QImage::Format_RGB888; 44 else 45 imageFormat = QImage::Format_RGB32; 46 47 return adoptRef(new ImageGStreamer(buffer, IntSize(width, height), imageFormat)); 48 } 49 50 ImageGStreamer::ImageGStreamer(GstBuffer*& buffer, IntSize size, QImage::Format imageFormat) 51 : m_image(0) 52 { 53 QPixmap* surface = new QPixmap; 54 QImage image(GST_BUFFER_DATA(buffer), size.width(), size.height(), imageFormat); 55 surface->convertFromImage(image); 56 m_image = BitmapImage::create(surface); 57 } 58 59 ImageGStreamer::~ImageGStreamer() 60 { 61 if (m_image) 62 m_image.clear(); 63 64 m_image = 0; 65 } 66 #endif // USE(GSTREAMER) 67 68