1
/***************************************************************************
4
begin : Sat Jun 12 2004
5
copyright : (C) 2004 by Dirk Ziegelmeier
7
***************************************************************************/
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
20
* You should have received a copy of the GNU Library General Public License
21
* along with this library; see the file COPYING.LIB. If not, write to
22
* the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
23
* Boston, MA 02110-1301, USA.
27
#include "kdetvimagepool.h"
29
KdetvImagePool::KdetvImagePool(unsigned int count, unsigned int size)
40
KdetvImagePool::~KdetvImagePool()
45
void* KdetvImagePool::getImageStorage()
47
KdetvPooledImage* i = _first;
50
if(_fillLevel < _minFillLevel) {
51
_minFillLevel = _fillLevel;
53
Q_ASSERT(_fillLevel >= 0);
59
KdetvSharedImage* KdetvImagePool::getImage()
61
KdetvPooledImage* i = new(this)KdetvPooledImage(this);
63
i->setBuffer((unsigned char*)(i + sizeof(KdetvPooledImage)), _bufSize, false);
65
// kdDebug() << "getImage: " << i << " Level: " << _fillLevel << " min: " << _minFillLevel << endl;
69
void KdetvImagePool::putImage(KdetvPooledImage* img)
74
// kdDebug() << "putImage: " << img << " Level: " << _fillLevel << endl;
77
void KdetvImagePool::setSize(unsigned int count, unsigned int bufsize)
79
Q_ASSERT(_images == NULL);
82
_images = new unsigned char[count * (sizeof(KdetvPooledImage) + bufsize)];
84
_first = reinterpret_cast<KdetvPooledImage*>(_images);
86
_minFillLevel = count;
88
unsigned char* curImage = _images;
89
KdetvPooledImage* img;
90
for(unsigned int i=0; i<(count-1); i++) {
91
img = reinterpret_cast<KdetvPooledImage*>(curImage);
92
img->_next = reinterpret_cast<KdetvPooledImage*>(curImage + sizeof(KdetvPooledImage) + bufsize);
93
curImage += sizeof(KdetvPooledImage) + bufsize;
96
img = reinterpret_cast<KdetvPooledImage*>(curImage);