forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.cpp
80 lines (66 loc) · 1.87 KB
/
image.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Aseprite Document Library
// Copyright (c) 2018-2020 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/image.h"
#include "doc/algo.h"
#include "doc/brush.h"
#include "doc/image_impl.h"
#include "doc/palette.h"
#include "doc/primitives.h"
#include "doc/rgbmap.h"
namespace doc {
Image::Image(const ImageSpec& spec)
: Object(ObjectType::Image)
, m_spec(spec)
{
}
Image::~Image()
{
}
int Image::getMemSize() const
{
return sizeof(Image) + getRowStrideSize()*height();
}
int Image::getRowStrideSize() const
{
return getRowStrideSize(width());
}
int Image::getRowStrideSize(int pixels_per_row) const
{
return calculate_rowstride_bytes(pixelFormat(), pixels_per_row);
}
// static
Image* Image::create(PixelFormat format, int width, int height,
const ImageBufferPtr& buffer)
{
return Image::create(ImageSpec((ColorMode)format, width, height, 0), buffer);
}
// static
Image* Image::create(const ImageSpec& spec,
const ImageBufferPtr& buffer)
{
ASSERT(spec.width() >= 1 && spec.height() >= 1);
if (spec.width() < 1 || spec.height() < 1)
return nullptr;
switch (spec.colorMode()) {
case ColorMode::RGB: return new ImageImpl<RgbTraits>(spec, buffer);
case ColorMode::GRAYSCALE: return new ImageImpl<GrayscaleTraits>(spec, buffer);
case ColorMode::INDEXED: return new ImageImpl<IndexedTraits>(spec, buffer);
case ColorMode::BITMAP: return new ImageImpl<BitmapTraits>(spec, buffer);
}
return nullptr;
}
// static
Image* Image::createCopy(const Image* image, const ImageBufferPtr& buffer)
{
ASSERT(image);
return crop_image(image, 0, 0, image->width(), image->height(),
image->maskColor(), buffer);
}
} // namespace doc