2
A small utility to generate embedded images for Keramik, especially structured for easy recoloring...
4
Copyright (c) 2002, 2005 Maksim Orlovich <maksim@kde.org>
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
26
#include <QtCore/QCoreApplication>
27
#include <QtGui/QColor>
28
#include <QtCore/QDataStream>
29
#include <QtCore/QFile>
30
#include <QtCore/QFileInfo>
31
#include <QtGui/QImage>
32
#include <QtCore/QMap>
33
#include <QtCore/QTextStream>
34
#include <QtCore/QVector>
36
#include <qimageblitz.h>
44
//NOTE: Use of old-style header is intentional for portability. See revisions 1.6 and 1.7
46
//Force-touch-embedded-revision: 2
48
#include "keramikimage.h"
51
Need to generate something like this:
52
TargetColorAlpha, GreyAdd, SrcAlpha;
54
so that one can do (R*T+GreyAdd, G*T+GreyAdd, B*T+GreyAdd, SrcAlpha) as pixel values
58
int evalSuffix(const QString &suffix)
87
if (suffix == "-separator")
88
return KeramikTileSeparator;
90
if (suffix == "-slider1")
91
return KeramikSlider1;
93
if (suffix == "-slider2")
94
return KeramikSlider2;
96
if (suffix == "-slider3")
97
return KeramikSlider3;
99
if (suffix == "-slider4")
100
return KeramikSlider4;
102
if (suffix == "-groove1")
103
return KeramikGroove1;
105
if (suffix == "-groove2")
106
return KeramikGroove2;
121
int main(int argc, char** argv)
126
QCoreApplication qapp(argc, argv);
127
QVector<KeramikEmbedImage> images;
129
QStringList imageList;
130
if (argc == 3 && (strcmp(argv[1], "--file")==0)) {
132
if (!f.open(QIODevice::ReadOnly))
134
QByteArray ba = f.readLine();
135
while (!ba.isEmpty()) {
136
imageList += ba.trimmed();
141
for (int c = 1; c<argc; c++)
142
imageList += argv[c];
145
cout<<"#include <QHash>\n\n";
146
cout<<"#include \"keramikimage.h\"\n\n";
148
QMap<QString, int> assignID;
151
for(QStringList::iterator it = imageList.begin(); it != imageList.end(); ++it)
154
input = input.convertToFormat( QImage::Format_ARGB32 );
157
QString s = fi.baseName();
159
KeramikEmbedImage image;
168
if ((pos = s.lastIndexOf("-")) != -1)
170
int suffix = evalSuffix(s.mid(pos));
178
if (!assignID.contains(id))
180
assignID[id] = nextID;
187
if (s.contains("button"))
188
Blitz::contrast(input, true);
190
int fullID = assignID[id] + readJustID;//Subwidget..
192
bool highlights = true;
200
if (s.contains("toolbar") || s.contains("tab-top-active") || s.contains("menubar") )
202
// highlights = false;
208
if (s.contains("scrollbar") && s.contains("groove"))
210
//highlights = false;
216
if (s.contains("scrollbar") && s.contains("slider"))
218
//highlights = false;
224
if (s.contains("menuitem"))
226
//highlights = false;
231
image.width = input.width();
232
image.height = input.height();
234
image.data = reinterpret_cast<unsigned char*>(strdup(s.toLatin1()));
237
bool reallySolid = true;
242
cout<<"static const unsigned char "<<qPrintable(s)<<"[]={\n";
244
quint32* read = reinterpret_cast< quint32* >(input.bits() );
245
int size = input.width()*input.height();
247
for (int pos=0; pos<size; pos++)
249
QRgb basePix = (QRgb)*read;
251
if (qAlpha(basePix) != 255)
260
image.haveAlpha = !reallySolid;
262
images.push_back(image);
264
read = reinterpret_cast< quint32* >(input.bits() );
265
for (int pos=0; pos<size; pos++)
267
QRgb basePix = (QRgb)*read;
268
//cout<<(r*destAlpha.alphas[pos])<<"\n";
269
//cout<<(int)destAlpha.alphas[pos]<<"\n";
272
clr.getHsv(&h,&s,&v);
276
int targetColorAlpha = 0 , greyAdd = 0;
277
//int srcAlpha = qAlpha(basePix);
286
if (s<17 && highlights) //A bit of a highligt..
288
float effectPortion = (16 - s)/15.0;
290
greyAdd = (int)(v/4.0 * effectPortion*1.2);
291
targetColorAlpha = v - greyAdd;
295
targetColorAlpha = v;//(int)(fv*255);
303
targetColorAlpha = 0;
308
targetColorAlpha = v;//(int)(fv*255);
316
cout<<targetColorAlpha<<","<<greyAdd<<",";
318
cout<<targetColorAlpha<<","<<greyAdd<<","<<qAlpha(basePix)<<",";
319
//cout<<qRed(basePix)<<","<<qGreen(basePix)<<","<<qBlue(basePix)<<","<<qAlpha(basePix)<<",";
327
//cerr<<qPrintable(s)<<":"<<pixSolid<<"/"<<pixCount<<"("<<reallySolid<<")\n";
329
cout<<!reallySolid<<"\n";
334
cout<<"static const KeramikEmbedImage image_db[] = {\n";
336
for (int c=0; c<images.size(); c++)
338
cout<<"\t{ "<<(images[c].haveAlpha?"true":"false")<<","<<images[c].width<<", "<<images[c].height<<", "<<images[c].id<<", "<<(char *)images[c].data<<"},";
341
cout<<"\t{0, 0, 0, 0, 0}\n";
344
cout<<"class KeramikImageDb\n";
347
cout<<"\tstatic KeramikImageDb* getInstance()\n";
349
cout<<"\t\tif (!instance) instance = new KeramikImageDb;\n";
350
cout<<"\t\treturn instance;\n";
352
cout<<"\tstatic void release()\n";
354
cout<<"\t\tdelete instance;\n";
355
cout<<"\t\tinstance=0;\n";
357
cout<<"\tconst KeramikEmbedImage* getImage(int id)\n";
359
cout<<"\t\treturn images[id];\n";
362
cout<<"\tKeramikImageDb()\n";
364
cout<<"\t\timages.reserve(503);";
365
cout<<"\t\tfor (int c=0; image_db[c].width; c++)\n";
366
cout<<"\t\t\timages.insert(image_db[c].id, &image_db[c]);\n";
368
cout<<"\tstatic KeramikImageDb* instance;\n";
369
cout<<"\tQHash<int, const KeramikEmbedImage*> images;\n";
371
cout<<"KeramikImageDb* KeramikImageDb::instance = 0;\n\n";
373
cout<<"const KeramikEmbedImage* KeramikGetDbImage(int id)\n";
375
cout<<"\treturn KeramikImageDb::getInstance()->getImage(id);\n";
378
cout<<"void KeramikDbCleanup()\n";
380
cout<<"\t\tKeramikImageDb::release();\n";
385
QFile file("keramikrc.h");
386
file.open(QIODevice::WriteOnly);
387
QTextStream ts( &file);
388
ts<<"#ifndef KERAMIK_RC_H\n";
389
ts<<"#define KERAMIK_RC_H\n";
391
ts<<"enum KeramikWidget {\n";
392
for (QMap<QString, int>::iterator i = assignID.begin(); i != assignID.end(); ++i)
394
QString name = "keramik_"+i.key();
395
name.replace('-','_');
396
ts<<"\t"<<name<<" = "<<i.value()<<",\n";
398
ts<<"\tkeramik_last\n";
407
// vim: ts=4 sw=4 noet