Main Page | Class List | File List | Class Members | File Members

convert.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           convert.cpp  -  helper functions
00003                              -------------------
00004     begin                : Fre Jan 23 2004
00005     revision             : $Revision: 1.3 $
00006     last modified        : $Date: 2004/03/22 00:42:12 $ by $Author: gousiosg $    
00007     copyright            : (C) 2004 by Juergen  Kofler
00008     email                : kaffeine@gm---.net
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 //#include <kdebug.h>
00021  
00022 #include "convert.h"
00023 
00024 
00025 QString msToTimeString( int msec )
00026 {
00027   int hours;
00028   int min;
00029   int sec;
00030   int my_msec=msec;
00031   QString tmp;
00032   QString t;
00033 
00034     msec = msec/1000;  //sec
00035     hours = msec/3600;
00036     my_msec -= hours*3600*1000;
00037     t = t.setNum(hours);
00038     t.append(":");
00039 
00040     msec = msec - (hours*3600);
00041     min = msec / 60;
00042     my_msec -= min*60*1000;
00043     tmp = tmp.setNum(min);
00044     tmp = tmp.rightJustify(2, '0');
00045     t.append(tmp);
00046     t.append(":");
00047 
00048     sec = msec - (min*60);
00049     my_msec -= sec*1000;
00050     if(my_msec > 500)
00051         sec++;
00052     tmp = tmp.setNum(sec);
00053     tmp = tmp.rightJustify(2, '0');
00054     t.append(tmp);
00055 
00056    return t;
00057 }
00058 
00059 int timeStringToMs( QString timeString )
00060 {
00061   int sec = 0;
00062   QStringList tokens = QStringList::split(':',timeString);
00063   
00064   sec += tokens[0].toInt()*3600; //hours
00065   sec += tokens[1].toInt()*60; //minutes
00066   sec += tokens[2].toInt(); //secs
00067   
00068   return sec*1000; //return millisecs
00069 }
00070 
00071 /************************************************************
00072  *   Helpers to convert yuy and yv12 frames to rgb          *
00073  *   code from gxine modified for 32bit output              *
00074  *   Copyright (C) 2000-2003 the xine project               *
00075  ************************************************************/
00076 
00077 void yuy2Toyv12 (uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *input,
00078         int width, int height)
00079 {
00080 
00081   int    i, j, w2;
00082 
00083   w2 = width / 2;
00084 
00085   for (i = 0; i < height; i += 2) {
00086     for (j = 0; j < w2; j++) {
00087       /*
00088        * packed YUV 422 is: Y[i] U[i] Y[i+1] V[i]
00089        */
00090       *(y++) = *(input++);
00091       *(u++) = *(input++);
00092       *(y++) = *(input++);
00093       *(v++) = *(input++);
00094     }
00095 
00096     /*
00097      * down sampling
00098      */
00099 
00100     for (j = 0; j < w2; j++) {
00101       /*
00102        * skip every second line for U and V
00103        */
00104       *(y++) = *(input++);
00105       input++;
00106       *(y++) = *(input++);
00107       input++;
00108     }
00109   }
00110 }
00111 
00112 /*
00113  *   Create rgb data from yv12
00114  */
00115 
00116 #define clip_8_bit(val)              \
00117 {                                    \
00118    if (val < 0)                      \
00119       val = 0;                       \
00120    else                              \
00121       if (val > 255) val = 255;      \
00122 }
00123 
00124 uchar * yv12ToRgb (uint8_t *src_y, uint8_t *src_u, uint8_t *src_v,
00125            int width, int height)
00126 {
00127 
00128   int     i, j;
00129 
00130   int     y, u, v;
00131   int     r, g, b;
00132 
00133   int     sub_i_uv;
00134   int     sub_j_uv;
00135 
00136   int     uv_width, uv_height;
00137 
00138   uchar *rgb;
00139 
00140   uv_width  = width / 2;
00141   uv_height = height / 2;
00142 
00143   rgb = new uchar[(width * height * 4)]; //qt needs a 32bit align
00144   if (!rgb)
00145   {
00146 //    kdError(555) << "Not enough memory!" << endl;
00147     return NULL;
00148   }
00149 
00150   for (i = 0; i < height; ++i) {
00151     /*
00152      * calculate u & v rows
00153      */
00154     sub_i_uv = ((i * uv_height) / height);
00155 
00156     for (j = 0; j < width; ++j) {
00157       /*
00158        * calculate u & v columns
00159        */
00160       sub_j_uv = ((j * uv_width) / width);
00161 
00162       /***************************************************
00163        *
00164        *  Colour conversion from
00165        *    http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html#RTFToC30
00166        *
00167        *  Thanks to Billy Biggs <vektor@dumbterm.net>
00168        *  for the pointer and the following conversion.
00169        *
00170        *   R' = [ 1.1644         0    1.5960 ]   ([ Y' ]   [  16 ])
00171        *   G' = [ 1.1644   -0.3918   -0.8130 ] * ([ Cb ] - [ 128 ])
00172        *   B' = [ 1.1644    2.0172         0 ]   ([ Cr ]   [ 128 ])
00173        *
00174        *  Where in xine the above values are represented as
00175        *
00176        *   Y' == image->y
00177        *   Cb == image->u
00178        *   Cr == image->v
00179        *
00180        ***************************************************/
00181 
00182       y = src_y[(i * width) + j] - 16;
00183       u = src_u[(sub_i_uv * uv_width) + sub_j_uv] - 128;
00184       v = src_v[(sub_i_uv * uv_width) + sub_j_uv] - 128;
00185 
00186       r = (int)((1.1644 * (double)y) + (1.5960 * (double)v));
00187       g = (int)((1.1644 * (double)y) - (0.3918 * (double)u) - (0.8130 * (double)v));
00188       b = (int)((1.1644 * (double)y) + (2.0172 * (double)u));
00189 
00190       clip_8_bit (r);
00191       clip_8_bit (g);
00192       clip_8_bit (b);
00193 
00194       rgb[(i * width + j) * 4 + 0] = b;
00195       rgb[(i * width + j) * 4 + 1] = g;
00196       rgb[(i * width + j) * 4 + 2] = r;
00197       rgb[(i * width + j) * 4 + 3] = 0;
00198 
00199     }
00200   }
00201 
00202   return rgb;
00203 }
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 

Generated on Thu Apr 22 05:12:29 2004 for QXineWidget by doxygen 1.3.5