File indexing completed on 2024-04-28 04:43:23

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2006,2008 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation 
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public 
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #ifndef PHONON_EXPERIMENTAL_VIDEOFRAME2_H
0024 #define PHONON_EXPERIMENTAL_VIDEOFRAME2_H
0025 
0026 #include "export.h"
0027 #include "videodataoutput.h"
0028 #include <QImage>
0029 
0030 namespace Phonon
0031 {
0032 namespace Experimental
0033 {
0034     /**
0035      * \brief A single video frame.
0036      *
0037      * This simple class contains the data of a frame and metadata describing
0038      * how to interpret the data.
0039      *
0040      * \author Matthias Kretz <kretz@kde.org>
0041      */
0042     struct VideoFrame2
0043     {
0044         /**
0045          * Video frames come in a variety of formats. Depending on the format
0046          * you have to process it differently to convert it for displaying or
0047          * encoding.
0048          */
0049         enum Format {
0050             /**
0051              * The frame is invalid.
0052              */
0053             Format_Invalid = QImage::Format_Invalid,
0054             /**
0055              * The frame is stored in data0 using a 24-bit RGB format (8-8-8).
0056              */
0057             Format_RGB888 = QImage::Format_RGB888,
0058             Format_RGB32 = QImage::Format_RGB32,
0059             /**
0060              * The frame is stored in data0, data1 and data2 using data0 for the
0061              * Y data, data1 for the Cb data and data2 for the Cr data.
0062              *
0063              * data1 and data2 contain one byte per for adjacent pixels whereas data0
0064              * has one byte per pixel.
0065              */
0066             Format_YCbCr420 = 0x10000,
0067             Format_YV12 = Format_YCbCr420,
0068             /**
0069              * The frame is stored in data0 using a 32-bit Y0-Cb-Y1-Cr format (8-8-8-8).
0070              */
0071             Format_YCbCr422 = 0x10001,
0072             Format_YUY2 = Format_YCbCr422
0073         };
0074 
0075         /**
0076          * The width of the video frame in number of pixels.
0077          */
0078         int width;
0079 
0080         /**
0081          * The height of the video frame in number of pixels.
0082          */
0083         int height;
0084 
0085         /**
0086          * The aspect ratio the frame should be displayed with.
0087          *
0088          * Common values are 4/3, 16/9.
0089          */
0090         double aspectRatio;
0091 
0092         /**
0093          * Convenience function to calculate the aspect corrected width from the
0094          * aspectRatio and height values.
0095          *
0096          * It is recommended to display video frames with aspectCorrectedWidth x height
0097          */
0098         inline int aspectCorrectedWidth() const { return qRound(aspectRatio * height); }
0099 
0100         /**
0101          * Convenience function to calculate the aspect corrected height from the
0102          * aspectRatio and width values.
0103          *
0104          * It is recommended to display video frames with aspectCorrectedWidth x height
0105          */
0106         inline int aspectCorrectedHeight() const { return qRound(width / aspectRatio); }
0107 
0108         /**
0109          * Format of the frame.
0110          *
0111          * \see Format
0112          */
0113         Format format;
0114 
0115         /**
0116          * RGB8, YUY2 or Y-plane
0117          *
0118          * If format is Format_RGB888 then the data contains each pixel as three
0119          * consecutive bytes for red, green and blue.
0120          *
0121          * If format is Format_YUY2 the data contains every two pixels as four
0122          * consecutive bytes for Y0, Cb, Y1, Cr
0123          *
0124          * If format is Format_YV12 the data contains one byte per pixel with
0125          * the Y value.
0126          */
0127         QByteArray data0;
0128 
0129         /**
0130          * YV12 U-plane
0131          *
0132          * If format is Format_YV12 the data contains one byte per four adjacent
0133          * pixels with the Cb value.
0134          */
0135         QByteArray data1;
0136 
0137         /**
0138          * YV12 V-plane
0139          *
0140          * If format is Format_YV12 the data contains one byte per four adjacent
0141          * pixels with the Cr value.
0142          */
0143         QByteArray data2;
0144 
0145         inline QImage qImage() const
0146         {
0147             if (format == Format_RGB888) {
0148                 return QImage(reinterpret_cast<const uchar *>(data0.constData()),
0149                         width, height, QImage::Format_RGB888);
0150             }
0151             return QImage();
0152         }
0153     };
0154 } // namespace Experimental
0155 } // namespace Phonon
0156 
0157 Q_DECLARE_METATYPE(Phonon::Experimental::VideoFrame2)
0158 
0159 // vim: sw=4 ts=4 tw=80
0160 #endif // PHONON_EXPERIMENTAL_VIDEOFRAME2_H