Qt 4.8
Classes | Macros | Functions | Variables
qxpmhandler.cpp File Reference
#include "private/qxpmhandler_p.h"
#include <private/qcolor_p.h>
#include <qimage.h>
#include <qmap.h>
#include <qtextstream.h>
#include <qvariant.h>

Go to the source code of this file.

Classes

struct  XPMRGBData
 

Macros

#define QRGB(r, g, b)   (r*65536 + g*256 + b)
 

Functions

static QString fbname (const QString &fileName)
 
static bool is_xpm_color_spec_prefix (const QByteArray &prefix)
 
bool operator< (const char *name, const XPMRGBData &data)
 
bool operator< (const XPMRGBData &data, const char *name)
 
static bool qt_get_named_xpm_rgb (const char *name_no_space, QRgb *rgb)
 
bool qt_read_xpm_image_or_array (QIODevice *device, const char *const *source, QImage &image)
 
static bool read_xpm_body (QIODevice *device, const char *const *source, int &index, QByteArray &state, int cpp, int ncols, int w, int h, QImage &image)
 
static bool read_xpm_header (QIODevice *device, const char *const *source, int &index, QByteArray &state, int *cpp, int *ncols, int *w, int *h)
 
static bool read_xpm_string (QByteArray &buf, QIODevice *d, const char *const *source, int &index, QByteArray &state)
 
static bool write_xpm_image (const QImage &sourceImage, QIODevice *device, const QString &fileName)
 
static const char * xpm_color_name (int cpp, int index)
 
static quint64 xpmHash (const QString &str)
 
static quint64 xpmHash (char *str)
 

Variables

static const struct XPMRGBData xpmRgbTbl []
 
static const int xpmRgbTblSize = 657
 

Macro Definition Documentation

◆ QRGB

#define QRGB (   r,
  g,
 
)    (r*65536 + g*256 + b)

Definition at line 82 of file qxpmhandler.cpp.

Function Documentation

◆ fbname()

static QString fbname ( const QString fileName)
static

Definition at line 767 of file qxpmhandler.cpp.

Referenced by write_xpm_image().

768 {
769  QString s = fileName;
770  if (!s.isEmpty()) {
771  int i;
772  if ((i = s.lastIndexOf(QLatin1Char('/'))) >= 0)
773  s = s.mid(i);
774  if ((i = s.lastIndexOf(QLatin1Char('\\'))) >= 0)
775  s = s.mid(i);
776  QRegExp r(QLatin1String("[a-zA-Z][a-zA-Z0-9_]*"));
777  int p = r.indexIn(s);
778  if (p == -1)
779  s.clear();
780  else
781  s = s.mid(p, r.matchedLength());
782  }
783  if (s.isEmpty())
784  s = QString::fromLatin1("dummy");
785  return s;
786 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ is_xpm_color_spec_prefix()

static bool is_xpm_color_spec_prefix ( const QByteArray prefix)
static

Definition at line 828 of file qxpmhandler.cpp.

Referenced by read_xpm_body().

829 {
830  return prefix == "c" ||
831  prefix == "g" ||
832  prefix == "g4" ||
833  prefix == "m" ||
834  prefix == "s";
835 }

◆ operator<() [1/2]

bool operator< ( const char *  name,
const XPMRGBData data 
)
inline

Definition at line 748 of file qxpmhandler.cpp.

749 { return qstrcmp(name, data.name) < 0; }
const char * name
Definition: qxpmhandler.cpp:88
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
const char * name

◆ operator<() [2/2]

bool operator< ( const XPMRGBData data,
const char *  name 
)
inline

Definition at line 750 of file qxpmhandler.cpp.

751 { return qstrcmp(data.name, name) < 0; }
const char * name
Definition: qxpmhandler.cpp:88
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
const char * name

◆ qt_get_named_xpm_rgb()

static bool qt_get_named_xpm_rgb ( const char *  name_no_space,
QRgb rgb 
)
inlinestatic

Definition at line 753 of file qxpmhandler.cpp.

Referenced by read_xpm_body().

754 {
755  const XPMRGBData *r = qBinaryFind(xpmRgbTbl, xpmRgbTbl + xpmRgbTblSize, name_no_space);
756  if (r != xpmRgbTbl + xpmRgbTblSize) {
757  *rgb = r->value;
758  return true;
759  } else {
760  return false;
761  }
762 }
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
static const int xpmRgbTblSize
Definition: qxpmhandler.cpp:84
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
static const struct XPMRGBData xpmRgbTbl[]

◆ qt_read_xpm_image_or_array()

bool qt_read_xpm_image_or_array ( QIODevice device,
const char *const *  source,
QImage image 
)

Definition at line 1025 of file qxpmhandler.cpp.

Referenced by QImage::QImage().

1026 {
1027  if (!source)
1028  return true;
1029 
1030  QByteArray buf(200, 0);
1031  QByteArray state;
1032 
1033  int cpp, ncols, w, h, index = 0;
1034 
1035  if (device) {
1036  // "/* XPM */"
1037  int readBytes;
1038  if ((readBytes = device->readLine(buf.data(), buf.size())) < 0)
1039  return false;
1040 
1041  if (buf.indexOf("/* XPM") != 0) {
1042  while (readBytes > 0) {
1043  device->ungetChar(buf.at(readBytes - 1));
1044  --readBytes;
1045  }
1046  return false;
1047  }// bad magic
1048  }
1049 
1050  if (!read_xpm_header(device, source, index, state, &cpp, &ncols, &w, &h))
1051  return false;
1052 
1053  return read_xpm_body(device, source, index, state, cpp, ncols, w, h, image);
1054 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void ungetChar(char c)
Puts the character c back into the device, and decrements the current position unless the position is...
Definition: qiodevice.cpp:1462
static bool read_xpm_body(QIODevice *device, const char *const *source, int &index, QByteArray &state, int cpp, int ncols, int w, int h, QImage &image)
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
quint16 index
static bool read_xpm_header(QIODevice *device, const char *const *source, int &index, QByteArray &state, int *cpp, int *ncols, int *w, int *h)

◆ read_xpm_body()

static bool read_xpm_body ( QIODevice device,
const char *const *  source,
int &  index,
QByteArray state,
int  cpp,
int  ncols,
int  w,
int  h,
QImage image 
)
static

Definition at line 860 of file qxpmhandler.cpp.

Referenced by qt_read_xpm_image_or_array(), and QXpmHandler::readImage().

863 {
864  QByteArray buf(200, 0);
865  int i;
866 
867  if (cpp < 0 || cpp > 15)
868  return false;
869 
870  // For > 256 colors, we delay creation of the image until
871  // after we have read the color specifications, so that we can
872  // create it in correct format (Format_RGB32 vs Format_ARGB32,
873  // depending on absence or presence of "c none", respectively)
874  if (ncols <= 256) {
875  if (image.size() != QSize(w, h) || image.format() != QImage::Format_Indexed8) {
876  image = QImage(w, h, QImage::Format_Indexed8);
877  if (image.isNull())
878  return false;
879  }
880  image.setColorCount(ncols);
881  }
882 
883  QMap<quint64, int> colorMap;
884  int currentColor;
885  bool hasTransparency = false;
886 
887  for(currentColor=0; currentColor < ncols; ++currentColor) {
888  if (!read_xpm_string(buf, device, source, index, state)) {
889  qWarning("QImage: XPM color specification missing");
890  return false;
891  }
893  index = buf.left(cpp);
894  buf = buf.mid(cpp).simplified().trimmed().toLower();
895  QList<QByteArray> tokens = buf.split(' ');
896  i = tokens.indexOf("c");
897  if (i < 0)
898  i = tokens.indexOf("g");
899  if (i < 0)
900  i = tokens.indexOf("g4");
901  if (i < 0)
902  i = tokens.indexOf("m");
903  if (i < 0) {
904  qWarning("QImage: XPM color specification is missing: %s", buf.constData());
905  return false; // no c/g/g4/m specification at all
906  }
907  QByteArray color;
908  while ((++i < tokens.size()) && !is_xpm_color_spec_prefix(tokens.at(i))) {
909  color.append(tokens.at(i));
910  }
911  if (color.isEmpty()) {
912  qWarning("QImage: XPM color value is missing from specification: %s", buf.constData());
913  return false; // no color value
914  }
915  buf = color;
916  if (buf == "none") {
917  hasTransparency = true;
918  int transparentColor = currentColor;
919  if (ncols <= 256) {
920  image.setColor(transparentColor, 0);
921  colorMap.insert(xpmHash(QLatin1String(index.constData())), transparentColor);
922  } else {
923  colorMap.insert(xpmHash(QLatin1String(index.constData())), 0);
924  }
925  } else {
926  QRgb c_rgb;
927  if (((buf.length()-1) % 3) && (buf[0] == '#')) {
928  buf.truncate(((buf.length()-1) / 4 * 3) + 1); // remove alpha channel left by imagemagick
929  }
930  if (buf[0] == '#') {
931  qt_get_hex_rgb(buf, &c_rgb);
932  } else {
933  qt_get_named_xpm_rgb(buf, &c_rgb);
934  }
935  if (ncols <= 256) {
936  image.setColor(currentColor, 0xff000000 | c_rgb);
937  colorMap.insert(xpmHash(QLatin1String(index.constData())), currentColor);
938  } else {
939  colorMap.insert(xpmHash(QLatin1String(index.constData())), 0xff000000 | c_rgb);
940  }
941  }
942  }
943 
944  if (ncols > 256) {
945  // Now we can create 32-bit image of appropriate format
946  QImage::Format format = hasTransparency ?
948  if (image.size() != QSize(w, h) || image.format() != format) {
949  image = QImage(w, h, format);
950  if (image.isNull())
951  return false;
952  }
953  }
954 
955  // Read pixels
956  for(int y=0; y<h; y++) {
957  if (!read_xpm_string(buf, device, source, index, state)) {
958  qWarning("QImage: XPM pixels missing on image line %d", y);
959  return false;
960  }
961  if (image.depth() == 8) {
962  uchar *p = image.scanLine(y);
963  uchar *d = (uchar *)buf.data();
964  uchar *end = d + buf.length();
965  int x;
966  if (cpp == 1) {
967  char b[2];
968  b[1] = '\0';
969  for (x=0; x<w && d<end; x++) {
970  b[0] = *d++;
971  *p++ = (uchar)colorMap[xpmHash(b)];
972  }
973  } else {
974  char b[16];
975  b[cpp] = '\0';
976  for (x=0; x<w && d<end; x++) {
977  memcpy(b, (char *)d, cpp);
978  *p++ = (uchar)colorMap[xpmHash(b)];
979  d += cpp;
980  }
981  }
982  // avoid uninitialized memory for malformed xpms
983  if (x < w) {
984  qWarning("QImage: XPM pixels missing on image line %d (possibly a C++ trigraph).", y);
985  memset(p, 0, w - x);
986  }
987  } else {
988  QRgb *p = (QRgb*)image.scanLine(y);
989  uchar *d = (uchar *)buf.data();
990  uchar *end = d + buf.length();
991  int x;
992  char b[16];
993  b[cpp] = '\0';
994  for (x=0; x<w && d<end; x++) {
995  memcpy(b, (char *)d, cpp);
996  *p++ = (QRgb)colorMap[xpmHash(b)];
997  d += cpp;
998  }
999  // avoid uninitialized memory for malformed xpms
1000  if (x < w) {
1001  qWarning("QImage: XPM pixels missing on image line %d (possibly a C++ trigraph).", y);
1002  memset(p, 0, (w - x)*4);
1003  }
1004  }
1005  }
1006 
1007  if (device) {
1008  // Rewind unused characters, and skip to the end of the XPM struct.
1009  for (int i = state.size() - 1; i >= 0; --i)
1010  device->ungetChar(state[i]);
1011  char c;
1012  while (device->getChar(&c) && c != ';') {}
1013  while (device->getChar(&c) && c != '\n') {}
1014  }
1015  return true;
1016 }
double d
Definition: qnumeric_p.h:62
Format
The following image formats are available in Qt.
Definition: qimage.h:91
unsigned int QRgb
Definition: qrgb.h:53
static bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb)
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
unsigned char c[8]
Definition: qnumeric_p.h:62
QByteArray & append(char c)
Appends the character ch to this byte array.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool getChar(char *c)
Reads one character from the device and stores it in c.
Definition: qiodevice.cpp:1536
QByteArray toLower() const
Returns a lowercase copy of the byte array.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void ungetChar(char c)
Puts the character c back into the device, and decrements the current position unless the position is...
Definition: qiodevice.cpp:1462
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
QByteArray simplified() const
Returns a byte array that has whitespace removed from the start and the end, and which has each seque...
unsigned char uchar
Definition: qglobal.h:994
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
static bool is_xpm_color_spec_prefix(const QByteArray &prefix)
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QRgb
An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static const KeyPair *const end
static bool read_xpm_string(QByteArray &buf, QIODevice *d, const char *const *source, int &index, QByteArray &state)
bool qt_get_hex_rgb(const char *name, QRgb *rgb)
Definition: qcolor_p.cpp:76
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static quint64 xpmHash(const QString &str)
Definition: qxpmhandler.cpp:59

◆ read_xpm_header()

static bool read_xpm_header ( QIODevice device,
const char *const *  source,
int &  index,
QByteArray state,
int *  cpp,
int *  ncols,
int *  w,
int *  h 
)
static

Definition at line 839 of file qxpmhandler.cpp.

Referenced by qt_read_xpm_image_or_array(), and QXpmHandler::readHeader().

842 {
843  QByteArray buf(200, 0);
844 
845  if (!read_xpm_string(buf, device, source, index, state))
846  return false;
847 
848 #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
849  if (sscanf_s(buf, "%d %d %d %d", w, h, ncols, cpp) < 4)
850 #else
851  if (sscanf(buf, "%d %d %d %d", w, h, ncols, cpp) < 4)
852 #endif
853  return false; // < 4 numbers parsed
854 
855  return true;
856 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
quint16 index
static bool read_xpm_string(QByteArray &buf, QIODevice *d, const char *const *source, int &index, QByteArray &state)

◆ read_xpm_string()

static bool read_xpm_string ( QByteArray buf,
QIODevice d,
const char *const *  source,
int &  index,
QByteArray state 
)
static

Definition at line 791 of file qxpmhandler.cpp.

Referenced by read_xpm_body(), and read_xpm_header().

793 {
794  if (source) {
795  buf = source[index++];
796  return true;
797  }
798 
799  buf = "";
800  bool gotQuote = false;
801  int offset = 0;
802  forever {
803  if (offset == state.size() || state.isEmpty()) {
804  char buf[2048];
805  qint64 bytesRead = d->read(buf, sizeof(buf));
806  if (bytesRead <= 0)
807  return false;
808  state = QByteArray(buf, int(bytesRead));
809  offset = 0;
810  }
811 
812  if (!gotQuote) {
813  if (state.at(offset++) == '"')
814  gotQuote = true;
815  } else {
816  char c = state.at(offset++);
817  if (c == '"')
818  break;
819  buf += c;
820  }
821  }
822  state.remove(0, offset);
823  return true;
824 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
__int64 qint64
Definition: qglobal.h:942
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ write_xpm_image()

static bool write_xpm_image ( const QImage sourceImage,
QIODevice device,
const QString fileName 
)
static

Definition at line 1089 of file qxpmhandler.cpp.

Referenced by QXpmHandler::write().

1090 {
1091  if (!device->isWritable())
1092  return false;
1093 
1094  QImage image;
1095  if (sourceImage.depth() != 32)
1096  image = sourceImage.convertToFormat(QImage::Format_RGB32);
1097  else
1098  image = sourceImage;
1099 
1100  QMap<QRgb, int> colorMap;
1101 
1102  int w = image.width(), h = image.height(), ncolors = 0;
1103  int x, y;
1104 
1105  // build color table
1106  for(y=0; y<h; y++) {
1107  QRgb * yp = (QRgb *)image.scanLine(y);
1108  for(x=0; x<w; x++) {
1109  QRgb color = *(yp + x);
1110  if (!colorMap.contains(color))
1111  colorMap.insert(color, ncolors++);
1112  }
1113  }
1114 
1115  // number of 64-bit characters per pixel needed to encode all colors
1116  int cpp = 1;
1117  for (int k = 64; ncolors > k; k *= 64) {
1118  ++cpp;
1119  // limit to 4 characters per pixel
1120  // 64^4 colors is enough for a 4096x4096 image
1121  if (cpp > 4)
1122  break;
1123  }
1124 
1125  QString line;
1126 
1127  // write header
1128  QTextStream s(device);
1129  s << "/* XPM */" << endl
1130  << "static char *" << fbname(fileName) << "[]={" << endl
1131  << '\"' << w << ' ' << h << ' ' << ncolors << ' ' << cpp << '\"';
1132 
1133  // write palette
1134  QMap<QRgb, int>::Iterator c = colorMap.begin();
1135  while (c != colorMap.end()) {
1136  QRgb color = c.key();
1137  if (image.format() != QImage::Format_RGB32 && !qAlpha(color))
1138  line.sprintf("\"%s c None\"",
1139  xpm_color_name(cpp, *c));
1140  else
1141  line.sprintf("\"%s c #%02x%02x%02x\"",
1142  xpm_color_name(cpp, *c),
1143  qRed(color),
1144  qGreen(color),
1145  qBlue(color));
1146  ++c;
1147  s << ',' << endl << line;
1148  }
1149 
1150  // write pixels, limit to 4 characters per pixel
1151  line.truncate(cpp*w);
1152  for(y=0; y<h; y++) {
1153  QRgb * yp = (QRgb *) image.scanLine(y);
1154  int cc = 0;
1155  for(x=0; x<w; x++) {
1156  int color = (int)(*(yp + x));
1157  QByteArray chars(xpm_color_name(cpp, colorMap[color]));
1158  line[cc++] = QLatin1Char(chars[0]);
1159  if (cpp > 1) {
1160  line[cc++] = QLatin1Char(chars[1]);
1161  if (cpp > 2) {
1162  line[cc++] = QLatin1Char(chars[2]);
1163  if (cpp > 3) {
1164  line[cc++] = QLatin1Char(chars[3]);
1165  }
1166  }
1167  }
1168  }
1169  s << ',' << endl << '\"' << line << '\"';
1170  }
1171  s << "};" << endl;
1172  return (s.status() == QTextStream::Ok);
1173 }
QTextStream & endl(QTextStream &stream)
Writes &#39; &#39; to the stream and flushes the stream.
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qmap.h:250
unsigned int QRgb
Definition: qrgb.h:53
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
Definition: qstring.cpp:5567
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
Definition: qiodevice.cpp:558
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char * xpm_color_name(int cpp, int index)
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
static QString fbname(const QString &fileName)
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ xpm_color_name()

static const char* xpm_color_name ( int  cpp,
int  index 
)
static

Definition at line 1056 of file qxpmhandler.cpp.

Referenced by write_xpm_image().

1057 {
1058  static char returnable[5];
1059  static const char code[] = ".#abcdefghijklmnopqrstuvwxyzABCD"
1060  "EFGHIJKLMNOPQRSTUVWXYZ0123456789";
1061  // cpp is limited to 4 and index is limited to 64^cpp
1062  if (cpp > 1) {
1063  if (cpp > 2) {
1064  if (cpp > 3) {
1065  returnable[3] = code[index % 64];
1066  index /= 64;
1067  } else
1068  returnable[3] = '\0';
1069  returnable[2] = code[index % 64];
1070  index /= 64;
1071  } else
1072  returnable[2] = '\0';
1073  // the following 4 lines are a joke!
1074  if (index == 0)
1075  index = 64*44+21;
1076  else if (index == 64*44+21)
1077  index = 0;
1078  returnable[1] = code[index % 64];
1079  index /= 64;
1080  } else
1081  returnable[1] = '\0';
1082  returnable[0] = code[index];
1083 
1084  return returnable;
1085 }
quint16 index

◆ xpmHash() [1/2]

static quint64 xpmHash ( const QString str)
static

Definition at line 59 of file qxpmhandler.cpp.

Referenced by read_xpm_body().

60 {
61  unsigned int hashValue = 0;
62  for (int i = 0; i < str.size(); ++i) {
63  hashValue <<= 8;
64  hashValue += (unsigned int)str.at(i).unicode();
65  }
66  return hashValue;
67 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102

◆ xpmHash() [2/2]

static quint64 xpmHash ( char *  str)
static

Definition at line 68 of file qxpmhandler.cpp.

69 {
70  unsigned int hashValue = 0;
71  while (*str != '\0') {
72  hashValue <<= 8;
73  hashValue += (unsigned int)*str;
74  ++str;
75  }
76  return hashValue;
77 }

Variable Documentation

◆ xpmRgbTbl

const struct XPMRGBData xpmRgbTbl[]
static

Referenced by qt_get_named_xpm_rgb().

◆ xpmRgbTblSize

const int xpmRgbTblSize = 657
static

Definition at line 84 of file qxpmhandler.cpp.

Referenced by qt_get_named_xpm_rgb().