1// Aseprite Document Library
2// Copyright (C) 2018-2020 Igara Studio S.A.
3// Copyright (c) 2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef DOC_IMAGE_SPEC_H_INCLUDED
9#define DOC_IMAGE_SPEC_H_INCLUDED
10#pragma once
11
12#include "base/debug.h"
13#include "doc/color.h"
14#include "doc/color_mode.h"
15#include "gfx/color_space.h"
16#include "gfx/rect.h"
17#include "gfx/size.h"
18
19namespace doc {
20
21 class ImageSpec {
22 public:
23 ImageSpec(const ColorMode colorMode,
24 const int width,
25 const int height,
26 const color_t maskColor = 0,
27 const gfx::ColorSpaceRef& colorSpace = gfx::ColorSpace::MakeNone())
28 : m_colorMode(colorMode),
29 m_size(width, height),
30 m_maskColor(maskColor),
31 m_colorSpace(colorSpace) {
32 ASSERT(width > 0);
33 ASSERT(height > 0);
34 }
35
36 ColorMode colorMode() const { return m_colorMode; }
37 int width() const { return m_size.w; }
38 int height() const { return m_size.h; }
39 const gfx::Size& size() const { return m_size; }
40 gfx::Rect bounds() const { return gfx::Rect(m_size); }
41 const gfx::ColorSpaceRef& colorSpace() const { return m_colorSpace; }
42
43 // The transparent color for colored images (0 by default) or just 0 for RGBA and Grayscale
44 color_t maskColor() const { return m_maskColor; }
45
46 void setColorMode(const ColorMode colorMode) { m_colorMode = colorMode; }
47 void setWidth(const int width) { m_size.w = width; }
48 void setHeight(const int height) { m_size.h = height; }
49 void setMaskColor(const color_t color) { m_maskColor = color; }
50 void setColorSpace(const gfx::ColorSpaceRef& cs) { m_colorSpace = cs; }
51
52 void setSize(const int width,
53 const int height) {
54 m_size = gfx::Size(width, height);
55 }
56
57 void setSize(const gfx::Size& sz) {
58 m_size = sz;
59 }
60
61 bool operator==(const ImageSpec& that) const {
62 return (m_colorMode == that.m_colorMode &&
63 m_size == that.m_size &&
64 m_maskColor == that.m_maskColor &&
65 ((!m_colorSpace && !that.m_colorSpace) ||
66 (m_colorSpace && that.m_colorSpace &&
67 m_colorSpace->nearlyEqual(*that.m_colorSpace))));
68 }
69 bool operator!=(const ImageSpec& that) const {
70 return !operator==(that);
71 }
72
73 private:
74 ColorMode m_colorMode;
75 gfx::Size m_size;
76 color_t m_maskColor;
77 gfx::ColorSpaceRef m_colorSpace;
78 };
79
80} // namespace doc
81
82#endif
83