Qt 4.8
Public Types | Public Functions | Private Functions | Properties | List of all members
QGLCmap Class Reference

Public Types

enum  Flags { Reserved = 0x01, Reserved = 0x01 }
 
enum  Flags { Reserved = 0x01, Reserved = 0x01 }
 

Public Functions

int allocate (QRgb color, uint flags=0, quint8 context=0)
 
int allocate (QRgb color, uint flags=0, quint8 context=0)
 
const QRgbcolors () const
 
const QRgbcolors () const
 
int find (QRgb color) const
 
int find (QRgb color) const
 
int findNearest (QRgb color) const
 
int findNearest (QRgb color) const
 
int maxSize () const
 
int maxSize () const
 
QGLCmapoperator= (const QGLCmap &map)
 
QGLCmapoperator= (const QGLCmap &map)
 
 QGLCmap (int maxSize=256)
 
 QGLCmap (const QGLCmap &map)
 
 QGLCmap (int maxSize=256)
 
 QGLCmap (const QGLCmap &map)
 
void resize (int newSize)
 
void resize (int newSize)
 
void setEntry (int idx, QRgb color, uint flags=0, quint8 context=0)
 
void setEntry (int idx, QRgb color, uint flags=0, quint8 context=0)
 
int size () const
 
int size () const
 
 ~QGLCmap ()
 
 ~QGLCmap ()
 

Private Functions

void detach ()
 
void detach ()
 

Properties

QGLCmapPrivated
 

Detailed Description

Definition at line 180 of file qgl_win.cpp.

Enumerations

◆ Flags [1/2]

Enumerator
Reserved 
Reserved 

Definition at line 183 of file qgl_win.cpp.

183 { Reserved = 0x01 };

◆ Flags [2/2]

Enumerator
Reserved 
Reserved 

Definition at line 214 of file qgl_wince.cpp.

214 { Reserved = 0x01 };

Constructors and Destructors

◆ QGLCmap() [1/4]

QGLCmap::QGLCmap ( int  maxSize = 256)

Definition at line 211 of file qgl_win.cpp.

212 {
213  d = new QGLCmapPrivate;
214  d->maxSize = maxSize;
215 }
int maxSize() const
Definition: qgl_win.cpp:249
QGLCmapPrivate * d
Definition: qgl_win.cpp:207

◆ QGLCmap() [2/4]

QGLCmap::QGLCmap ( const QGLCmap map)

Definition at line 218 of file qgl_win.cpp.

219 {
220  d = map.d;
221  d->ref();
222 }
QGLCmapPrivate * d
Definition: qgl_win.cpp:207

◆ ~QGLCmap() [1/2]

QGLCmap::~QGLCmap ( )

Definition at line 225 of file qgl_win.cpp.

226 {
227  if (d && d->deref())
228  delete d;
229  d = 0;
230 }
bool deref()
Definition: qgl_win.cpp:156
QGLCmapPrivate * d
Definition: qgl_win.cpp:207

◆ QGLCmap() [3/4]

QGLCmap::QGLCmap ( int  maxSize = 256)

◆ QGLCmap() [4/4]

QGLCmap::QGLCmap ( const QGLCmap map)

◆ ~QGLCmap() [2/2]

QGLCmap::~QGLCmap ( )

Functions

◆ allocate() [1/2]

int QGLCmap::allocate ( QRgb  color,
uint  flags = 0,
quint8  context = 0 
)

Definition at line 333 of file qgl_win.cpp.

334 {
335  int idx = find(color);
336  if (idx >= 0)
337  return idx;
338 
339  int mapSize = d->colorArray.size();
341 
342  if (newIdx < 0) { // Must allocate more room
343  if (mapSize < d->maxSize) {
344  newIdx = mapSize;
345  mapSize++;
346  resize(mapSize);
347  }
348  else {
349  //# add a bool param that says what to do in case no more room -
350  // fail (-1) or return nearest?
351  return -1;
352  }
353  }
354 
355  d->colorArray[newIdx] = color;
356  if (flags & QGLCmap::Reserved) {
358  }
359  else {
361  d->colorMap.insert(color, newIdx);
362  }
363  d->contextArray[newIdx] = context;
364  return newIdx;
365 }
int maxSize() const
Definition: qgl_win.cpp:249
int find(QRgb color) const
Definition: qgl_win.cpp:292
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
QVector< quint8 > contextArray
Definition: qgl_win.cpp:164
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
Definition: qvector.h:698
void resize(int newSize)
Definition: qgl_win.cpp:273
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
QVector< quint8 > allocArray
Definition: qgl_win.cpp:163
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QMap< uint, int > colorMap
Definition: qgl_win.cpp:165
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ allocate() [2/2]

int QGLCmap::allocate ( QRgb  color,
uint  flags = 0,
quint8  context = 0 
)

◆ colors() [1/2]

const QRgb * QGLCmap::colors ( ) const

Definition at line 392 of file qgl_win.cpp.

393 {
394  return d->colorArray.data();
395 }
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ colors() [2/2]

const QRgb* QGLCmap::colors ( ) const

◆ detach() [1/2]

void QGLCmap::detach ( )
private

Definition at line 255 of file qgl_win.cpp.

256 {
257  if (d->count != 1) {
258  d->deref();
259  QGLCmapPrivate* newd = new QGLCmapPrivate;
260  newd->maxSize = d->maxSize;
261  newd->colorArray = d->colorArray;
262  newd->allocArray = d->allocArray;
263  newd->contextArray = d->contextArray;
264  newd->colorArray.detach();
265  newd->allocArray.detach();
266  newd->contextArray.detach();
267  newd->colorMap = d->colorMap;
268  d = newd;
269  }
270 }
void detach()
Definition: qvector.h:147
bool deref()
Definition: qgl_win.cpp:156
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
QVector< quint8 > contextArray
Definition: qgl_win.cpp:164
QVector< quint8 > allocArray
Definition: qgl_win.cpp:163
QMap< uint, int > colorMap
Definition: qgl_win.cpp:165
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ detach() [2/2]

void QGLCmap::detach ( )
private

◆ find() [1/2]

int QGLCmap::find ( QRgb  color) const

Definition at line 292 of file qgl_win.cpp.

293 {
295  if (it != d->colorMap.end())
296  return *it;
297  return -1;
298 }
#define it(className, varName)
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
QMap< uint, int > colorMap
Definition: qgl_win.cpp:165
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ find() [2/2]

int QGLCmap::find ( QRgb  color) const

◆ findNearest() [1/2]

int QGLCmap::findNearest ( QRgb  color) const

Definition at line 301 of file qgl_win.cpp.

302 {
303  int idx = find(color);
304  if (idx >= 0)
305  return idx;
306  int mapSize = size();
307  int mindist = 200000;
308  int r = qRed(color);
309  int g = qGreen(color);
310  int b = qBlue(color);
311  int rx, gx, bx, dist;
312  for (int i=0; i < mapSize; i++) {
314  continue;
315  QRgb ci = d->colorArray[i];
316  rx = r - qRed(ci);
317  gx = g - qGreen(ci);
318  bx = b - qBlue(ci);
319  dist = rx*rx + gx*gx + bx*bx; // calculate distance
320  if (dist < mindist) { // minimal?
321  mindist = dist;
322  idx = i;
323  }
324  }
325  return idx;
326 }
unsigned int QRgb
Definition: qrgb.h:53
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
int size() const
Definition: qgl_win.cpp:243
int find(QRgb color) const
Definition: qgl_win.cpp:292
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
QVector< quint8 > allocArray
Definition: qgl_win.cpp:163
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ findNearest() [2/2]

int QGLCmap::findNearest ( QRgb  color) const

◆ maxSize() [1/2]

int QGLCmap::maxSize ( ) const

Definition at line 249 of file qgl_win.cpp.

250 {
251  return d->maxSize;
252 }
QGLCmapPrivate * d
Definition: qgl_win.cpp:207

◆ maxSize() [2/2]

int QGLCmap::maxSize ( ) const

◆ operator=() [1/2]

QGLCmap & QGLCmap::operator= ( const QGLCmap map)

Definition at line 233 of file qgl_win.cpp.

234 {
235  map.d->ref();
236  if (d->deref())
237  delete d;
238  d = map.d;
239  return *this;
240 }
bool deref()
Definition: qgl_win.cpp:156
QGLCmapPrivate * d
Definition: qgl_win.cpp:207

◆ operator=() [2/2]

QGLCmap& QGLCmap::operator= ( const QGLCmap map)

◆ resize() [1/2]

void QGLCmap::resize ( int  newSize)

Definition at line 273 of file qgl_win.cpp.

274 {
275  if (newSize < 0 || newSize > d->maxSize) {
276  qWarning("QGLCmap::resize(): size out of range");
277  return;
278  }
279  int oldSize = size();
280  detach();
281  //if shrinking; remove the lost elems from colorMap
282  d->colorArray.resize(newSize);
283  d->allocArray.resize(newSize);
284  d->contextArray.resize(newSize);
285  if (newSize > oldSize) {
286  memset(d->allocArray.data() + oldSize, 0, newSize - oldSize);
287  memset(d->contextArray.data() + oldSize, 0, newSize - oldSize);
288  }
289 }
void detach()
Definition: qgl_win.cpp:255
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
int size() const
Definition: qgl_win.cpp:243
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
QVector< quint8 > contextArray
Definition: qgl_win.cpp:164
Q_CORE_EXPORT void qWarning(const char *,...)
QVector< quint8 > allocArray
Definition: qgl_win.cpp:163
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ resize() [2/2]

void QGLCmap::resize ( int  newSize)

◆ setEntry() [1/2]

void QGLCmap::setEntry ( int  idx,
QRgb  color,
uint  flags = 0,
quint8  context = 0 
)

Definition at line 368 of file qgl_win.cpp.

369 {
370  if (idx < 0 || idx >= d->maxSize) {
371  qWarning("QGLCmap::set(): Index out of range");
372  return;
373  }
374  detach();
375  int mapSize = size();
376  if (idx >= mapSize) {
377  mapSize = idx + 1;
378  resize(mapSize);
379  }
380  d->colorArray[idx] = color;
381  if (flags & QGLCmap::Reserved) {
383  }
384  else {
386  d->colorMap.insert(color, idx);
387  }
388  d->contextArray[idx] = context;
389 }
void detach()
Definition: qgl_win.cpp:255
int size() const
Definition: qgl_win.cpp:243
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
QVector< quint8 > contextArray
Definition: qgl_win.cpp:164
Q_CORE_EXPORT void qWarning(const char *,...)
void resize(int newSize)
Definition: qgl_win.cpp:273
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
QVector< quint8 > allocArray
Definition: qgl_win.cpp:163
QMap< uint, int > colorMap
Definition: qgl_win.cpp:165
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ setEntry() [2/2]

void QGLCmap::setEntry ( int  idx,
QRgb  color,
uint  flags = 0,
quint8  context = 0 
)

◆ size() [1/2]

int QGLCmap::size ( ) const

Definition at line 243 of file qgl_win.cpp.

244 {
245  return d->colorArray.size();
246 }
QGLCmapPrivate * d
Definition: qgl_win.cpp:207
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QVector< uint > colorArray
Definition: qgl_win.cpp:162

◆ size() [2/2]

int QGLCmap::size ( ) const

Properties

◆ d

QGLCmapPrivate * QGLCmap::d
private

Definition at line 207 of file qgl_win.cpp.

Referenced by operator=(), and QGLCmap().


The documentation for this class was generated from the following files: