~ubuntu-branches/ubuntu/feisty/kdetv/feisty

« back to all changes in this revision

Viewing changes to kdetv/libkdetv/kdetvvideo/kdetvimagepool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-09-17 23:25:16 UTC
  • Revision ID: james.westby@ubuntu.com-20050917232516-9wdsn3ckagbqieh8
Tags: upstream-0.8.8
ImportĀ upstreamĀ versionĀ 0.8.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                           kdetvimage.cpp
 
3
                           --------------
 
4
    begin                : Sat Jun 12 2004
 
5
    copyright            : (C) 2004 by Dirk Ziegelmeier
 
6
    email                : dziegel@gmx.de
 
7
 ***************************************************************************/
 
8
 
 
9
/*
 
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.
 
14
 *
 
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.
 
19
 *
 
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.
 
24
 */
 
25
 
 
26
#include <kdebug.h>
 
27
#include "kdetvimagepool.h"
 
28
 
 
29
KdetvImagePool::KdetvImagePool(unsigned int count, unsigned int size)
 
30
    : _first(NULL),
 
31
      _fillLevel(0),
 
32
      _minFillLevel(0),
 
33
      _images(NULL)
 
34
{
 
35
    if( count != 0 ) {
 
36
        setSize(count, size);
 
37
    }
 
38
}
 
39
 
 
40
KdetvImagePool::~KdetvImagePool()
 
41
{
 
42
    delete[] _images;
 
43
}
 
44
 
 
45
void* KdetvImagePool::getImageStorage()
 
46
{
 
47
    KdetvPooledImage* i = _first;
 
48
    _first = i->_next;
 
49
    _fillLevel--;
 
50
    if(_fillLevel < _minFillLevel) {
 
51
        _minFillLevel = _fillLevel;
 
52
    }
 
53
    Q_ASSERT(_fillLevel >= 0);
 
54
    Q_ASSERT(i != NULL);
 
55
 
 
56
    return i;
 
57
}
 
58
 
 
59
KdetvSharedImage* KdetvImagePool::getImage()
 
60
{
 
61
    KdetvPooledImage* i = new(this)KdetvPooledImage(this);
 
62
    if(_bufSize != 0) {
 
63
        i->setBuffer((unsigned char*)(i + sizeof(KdetvPooledImage)), _bufSize, false);
 
64
    }
 
65
    //    kdDebug() << "getImage: " << i << " Level: " << _fillLevel << " min: " << _minFillLevel << endl;
 
66
    return i;
 
67
}
 
68
 
 
69
void KdetvImagePool::putImage(KdetvPooledImage* img)
 
70
{
 
71
    img->_next = _first;
 
72
    _first = img;
 
73
    _fillLevel++;
 
74
    //    kdDebug() << "putImage: " << img << " Level: " << _fillLevel << endl;
 
75
}
 
76
 
 
77
void KdetvImagePool::setSize(unsigned int count, unsigned int bufsize)
 
78
{
 
79
    Q_ASSERT(_images == NULL);
 
80
    Q_ASSERT(count > 0);
 
81
 
 
82
    _images = new unsigned char[count * (sizeof(KdetvPooledImage) + bufsize)];
 
83
    _bufSize = bufsize;
 
84
    _first = reinterpret_cast<KdetvPooledImage*>(_images);
 
85
    _fillLevel = count;
 
86
    _minFillLevel = count;
 
87
 
 
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;
 
94
    }
 
95
 
 
96
    img = reinterpret_cast<KdetvPooledImage*>(curImage);
 
97
    img->_next = NULL;
 
98
}