• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KStyles

genembed.cpp

Go to the documentation of this file.
00001 
00026 #include <QtCore/QCoreApplication>
00027 #include <QtGui/QColor>
00028 #include <QtCore/QDataStream>
00029 #include <QtCore/QFile>
00030 #include <QtCore/QFileInfo>
00031 #include <QtGui/QImage>
00032 #include <QtCore/QMap>
00033 #include <QtCore/QTextStream>
00034 #include <QtCore/QVector>
00035 
00036 #include <qimageblitz.h>
00037 
00038 #include <iostream>
00039 using namespace std;
00040 
00041 #include <string.h>
00042 #include <math.h>
00043 
00044 //NOTE: Use of old-style header is intentional for portability. See revisions 1.6 and 1.7
00045 
00046 //Force-touch-embedded-revision: 2
00047 
00048 #include "keramikimage.h"
00049 
00058 int evalSuffix(const QString &suffix)
00059 {
00060     if (suffix == "-tl")
00061         return 0;
00062 
00063     if (suffix == "-tc")
00064         return 1;
00065 
00066     if (suffix == "-tr")
00067         return 2;
00068 
00069     if (suffix == "-cl")
00070         return 3;
00071 
00072     if (suffix == "-cc")
00073         return 4;
00074 
00075     if (suffix == "-cr")
00076         return 5;
00077 
00078     if (suffix == "-bl")
00079         return 6;
00080 
00081     if (suffix == "-bc")
00082         return 7;
00083 
00084     if (suffix == "-br")
00085         return 8;
00086 
00087     if (suffix == "-separator")
00088         return KeramikTileSeparator;
00089 
00090     if (suffix == "-slider1")
00091         return KeramikSlider1;
00092 
00093     if (suffix == "-slider2")
00094         return KeramikSlider2;
00095 
00096     if (suffix == "-slider3")
00097         return KeramikSlider3;
00098 
00099     if (suffix == "-slider4")
00100         return KeramikSlider4;
00101 
00102     if (suffix == "-groove1")
00103         return KeramikGroove1;
00104 
00105     if (suffix == "-groove2")
00106         return KeramikGroove2;
00107 
00108     if (suffix == "-1")
00109         return 1;
00110 
00111     if (suffix == "-2")
00112         return 2;
00113 
00114     if (suffix == "-3")
00115         return 3;
00116 
00117     return -1;
00118 }
00119 
00120 
00121 int main(int argc, char** argv)
00122 {
00123     if (argc < 2)
00124         return 0;
00125 
00126     QCoreApplication qapp(argc, argv);
00127     QVector<KeramikEmbedImage> images;
00128 
00129     QStringList imageList;
00130     if (argc == 3 && (strcmp(argv[1], "--file")==0)) {
00131         QFile f( argv[2] );
00132         if (!f.open(QIODevice::ReadOnly))
00133             return 0;
00134         QByteArray ba = f.readLine();
00135         while (!ba.isEmpty()) {
00136             imageList += ba.trimmed();
00137             ba = f.readLine();
00138         }
00139         f.close();
00140     } else {
00141         for (int c = 1; c<argc; c++)
00142             imageList += argv[c];
00143     }
00144 
00145     cout<<"#include <QHash>\n\n";
00146     cout<<"#include \"keramikimage.h\"\n\n";
00147 
00148     QMap<QString, int> assignID;
00149     int nextID = 0;
00150 
00151     for(QStringList::iterator it = imageList.begin(); it != imageList.end(); ++it)
00152     {
00153         QImage input((*it));
00154         input = input.convertToFormat( QImage::Format_ARGB32 );
00155 
00156         QFileInfo fi((*it));
00157         QString s = fi.baseName();
00158 
00159         KeramikEmbedImage image;
00160 
00161         int pos;
00162 
00163         QString id = s;
00164 
00165         int readJustID = 0;
00166 
00167 
00168         if ((pos = s.lastIndexOf("-")) != -1)
00169         {
00170                 int suffix = evalSuffix(s.mid(pos));
00171                 if (suffix !=-1 )
00172                 {
00173                         id = s.mid(0,pos);
00174                         readJustID = suffix;
00175                 }
00176         }
00177 
00178         if (!assignID.contains(id))
00179         {
00180             assignID[id] = nextID;
00181             nextID += 256;
00182         }
00183 
00184         s.replace("-","_");
00185 
00186 
00187         if (s.contains("button"))
00188             Blitz::contrast(input, true);
00189 
00190         int fullID = assignID[id] + readJustID;//Subwidget..
00191 
00192         bool highlights = true;
00193         bool shadows  = true;
00194 
00195         float gamma    = 1.0;
00196         int brightAdj = 0;
00197 
00198 
00199 
00200         if (s.contains("toolbar") || s.contains("tab-top-active") || s.contains("menubar") )
00201         {
00202 //          highlights = false;
00203             gamma    = 1/1.25f;
00204             //brightAdj = 10;
00205             shadows = false;
00206         }
00207 
00208         if (s.contains("scrollbar") && s.contains("groove"))
00209         {
00210             //highlights = false;
00211             //gamma = 1.5;
00212             shadows = false;
00213         }
00214             //brightAdj = -10;
00215 
00216         if (s.contains("scrollbar") && s.contains("slider"))
00217         {
00218             //highlights = false;
00219             gamma =1/0.7f;
00220             //shadows = false;
00221         }
00222 
00223 
00224         if (s.contains("menuitem"))
00225         {
00226             //highlights = false;
00227             gamma =1/0.6f;
00228             //shadows = false;
00229         }
00230 
00231         image.width   = input.width();
00232         image.height = input.height();
00233         image.id         = fullID;
00234         image.data     = reinterpret_cast<unsigned char*>(strdup(s.toLatin1()));
00235 
00236 
00237         bool reallySolid = true;
00238 
00239         int pixCount = 0;
00240         int pixSolid = 0;
00241 
00242         cout<<"static const unsigned char "<<qPrintable(s)<<"[]={\n";
00243 
00244         quint32* read  = reinterpret_cast< quint32* >(input.bits() );
00245         int size = input.width()*input.height();
00246 
00247         for (int pos=0; pos<size; pos++)
00248         {
00249             QRgb basePix = (QRgb)*read;
00250 
00251             if (qAlpha(basePix) != 255)
00252                 reallySolid = false;
00253             else
00254                 pixSolid++;
00255 
00256             pixCount++;
00257             read++;
00258         }
00259 
00260         image.haveAlpha = !reallySolid;
00261 
00262         images.push_back(image);
00263 
00264         read  = reinterpret_cast< quint32* >(input.bits() );
00265         for (int pos=0; pos<size; pos++)
00266         {
00267             QRgb basePix = (QRgb)*read;
00268             //cout<<(r*destAlpha.alphas[pos])<<"\n";
00269             //cout<<(int)destAlpha.alphas[pos]<<"\n";
00270             QColor clr(basePix);
00271             int h,s,v;
00272             clr.getHsv(&h,&s,&v);
00273 
00274             v=qGray(basePix);
00275 
00276             int targetColorAlpha = 0 , greyAdd = 0;
00277             //int srcAlpha = qAlpha(basePix);
00278 
00279             if (s>0 || v > 128)
00280             { //Non-shadow
00281                 float fv = v/255.0;
00282                 fv = pow(fv, gamma);
00283                 v = int(255.5*fv);
00284 
00285 
00286                 if (s<17 && highlights) //A bit of a highligt..
00287                 {
00288                     float effectPortion = (16 - s)/15.0;
00289 
00290                     greyAdd             = (int)(v/4.0 * effectPortion*1.2);
00291                     targetColorAlpha = v - greyAdd;
00292                 }
00293                 else
00294                 {
00295                     targetColorAlpha = v;//(int)(fv*255);
00296                     greyAdd              = 0;
00297                 }
00298             }
00299             else
00300             {
00301                 if (shadows)
00302                 {
00303                     targetColorAlpha = 0;
00304                     greyAdd              = v;
00305                 }
00306                 else
00307                 {
00308                     targetColorAlpha = v;//(int)(fv*255);
00309                     greyAdd              = 0;
00310                 }
00311             }
00312 
00313             greyAdd+=brightAdj;
00314 
00315             if (reallySolid)
00316                 cout<<targetColorAlpha<<","<<greyAdd<<",";
00317             else
00318                 cout<<targetColorAlpha<<","<<greyAdd<<","<<qAlpha(basePix)<<",";
00319             //cout<<qRed(basePix)<<","<<qGreen(basePix)<<","<<qBlue(basePix)<<","<<qAlpha(basePix)<<",";
00320 
00321             if (pos%8 == 7)
00322                 cout<<"\n";
00323 
00324             read++;
00325         }
00326 
00327         //cerr<<qPrintable(s)<<":"<<pixSolid<<"/"<<pixCount<<"("<<reallySolid<<")\n";
00328 
00329         cout<<!reallySolid<<"\n";
00330 
00331         cout<<"};\n\n";
00332     }
00333 
00334     cout<<"static const KeramikEmbedImage  image_db[] = {\n";
00335 
00336     for (int c=0; c<images.size(); c++)
00337     {
00338         cout<<"\t{ "<<(images[c].haveAlpha?"true":"false")<<","<<images[c].width<<", "<<images[c].height<<", "<<images[c].id<<", "<<(char *)images[c].data<<"},";
00339         cout<<"\n";
00340     }
00341     cout<<"\t{0, 0, 0, 0, 0}\n";
00342     cout<<"};\n\n";
00343 
00344     cout<<"class KeramikImageDb\n";
00345     cout<<"{\n";
00346     cout<<"public:\n";
00347     cout<<"\tstatic KeramikImageDb* getInstance()\n";
00348     cout<<"\t{\n";
00349     cout<<"\t\tif (!instance) instance = new KeramikImageDb;\n";
00350     cout<<"\t\treturn instance;\n";
00351     cout<<"\t}\n\n";
00352     cout<<"\tstatic void release()\n";
00353     cout<<"\t{\n";
00354     cout<<"\t\tdelete instance;\n";
00355     cout<<"\t\tinstance=0;\n";
00356     cout<<"\t}\n\n";
00357     cout<<"\tconst KeramikEmbedImage* getImage(int id)\n";
00358     cout<<"\t{\n";
00359     cout<<"\t\treturn images[id];\n";
00360     cout<<"\t}\n\n";
00361     cout<<"private:\n";
00362     cout<<"\tKeramikImageDb()\n";
00363     cout<<"\t{\n";
00364     cout<<"\t\timages.reserve(503);";
00365     cout<<"\t\tfor (int c=0; image_db[c].width; c++)\n";
00366     cout<<"\t\t\timages.insert(image_db[c].id, &image_db[c]);\n";
00367     cout<<"\t}\n";
00368     cout<<"\tstatic KeramikImageDb* instance;\n";
00369     cout<<"\tQHash<int, const KeramikEmbedImage*> images;\n";
00370     cout<<"};\n\n";
00371     cout<<"KeramikImageDb* KeramikImageDb::instance = 0;\n\n";
00372 
00373     cout<<"const KeramikEmbedImage* KeramikGetDbImage(int id)\n";
00374     cout<<"{\n";
00375     cout<<"\treturn KeramikImageDb::getInstance()->getImage(id);\n";
00376     cout<<"}\n\n";
00377 
00378     cout<<"void KeramikDbCleanup()\n";
00379     cout<<"{\n";
00380     cout<<"\t\tKeramikImageDb::release();\n";
00381     cout<<"}\n";
00382     cout.flush();
00383 
00384 
00385     QFile file("keramikrc.h");
00386     file.open(QIODevice::WriteOnly);
00387     QTextStream ts( &file);
00388     ts<<"#ifndef KERAMIK_RC_H\n";
00389     ts<<"#define KERAMIK_RC_H\n";
00390 
00391     ts<<"enum KeramikWidget {\n";
00392     for (QMap<QString, int>::iterator i = assignID.begin(); i != assignID.end(); ++i)
00393     {
00394         QString name = "keramik_"+i.key();
00395         name.replace("-","_");
00396         ts<<"\t"<<name<<" = "<<i.value()<<",\n";
00397     }
00398     ts<<"\tkeramik_last\n";
00399     ts<<"};\n";
00400 
00401     ts<<"#endif\n";
00402     file.close();
00403 
00404     return 0;
00405 }
00406 
00407 // vim: ts=4 sw=4 noet

KStyles

Skip menu "KStyles"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal