GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/imageset.cpp Lines: 20 25 80.0 %
Date: 2017-11-29 Branches: 8 12 66.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "resources/imageset.h"
24
25
#include "logger.h"
26
27
#include "resources/image/image.h"
28
29
#include "utils/cast.h"
30
#include "utils/dtor.h"
31
32
#include "debug.h"
33
34
2594
ImageSet::ImageSet(Image *const img, const int width, const int height,
35
2594
                   const int margin, const int spacing) :
36
    Resource(),
37
    mImages(),
38
    mWidth(width),
39
    mHeight(height),
40
    mOffsetX(0),
41
7782
    mOffsetY(0)
42
{
43
2594
    if (img != nullptr)
44
    {
45
2594
        const int hAdd = height + spacing;
46
2594
        const int wAdd = width + spacing;
47
17176
        for (int y = margin; y + height <= img->getHeight() - margin;
48
5994
             y += hAdd)
49
        {
50
145440
            for (int x = margin; x + width <= img->getWidth() - margin;
51
44484
                 x += wAdd)
52
            {
53
44484
                Image *const image = img->getSubImage(x, y, width, height);
54
44484
                image->mNotCount = true;
55
44484
                mImages.push_back(image);
56
            }
57
        }
58
    }
59
2594
}
60
61
10376
ImageSet::~ImageSet()
62
{
63
5188
    delete_all(mImages);
64
5188
}
65
66
38750
Image* ImageSet::get(const size_type i) const
67
{
68
77500
    if (i >= mImages.size())
69
    {
70
        logger->log("Warning: No sprite %d in this image set",
71
            CAST_S32(i));
72
        return nullptr;
73
    }
74
77500
    return mImages[i];
75
}
76
77
int ImageSet::calcMemoryLocal() const
78
{
79
    return static_cast<int>(sizeof(ImageSet)) +
80
        Resource::calcMemoryLocal() +
81
        static_cast<int>(mImages.capacity() * sizeof(Image));
82
}