1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5
6 //----------------------------------------------------------------------------
7 //
8 // class ImageLevel
9 //
10 //----------------------------------------------------------------------------
11
12 #include "ImfImageLevel.h"
13 #include <Iex.h>
14 #include <cassert>
15
16 using namespace IMATH_NAMESPACE;
17 using namespace IEX_NAMESPACE;
18 using namespace std;
19
20 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
21
22
ImageLevel(Image & image,int xLevelNumber,int yLevelNumber)23 ImageLevel::ImageLevel
24 (Image& image,
25 int xLevelNumber,
26 int yLevelNumber)
27 :
28 _image (image),
29 _xLevelNumber (xLevelNumber),
30 _yLevelNumber (yLevelNumber),
31 _dataWindow (Box2i (V2i (0, 0), V2i (-1, -1)))
32 {
33 // empty
34 }
35
36
~ImageLevel()37 ImageLevel::~ImageLevel ()
38 {
39 // empty
40 }
41
42
43 void
resize(const Box2i & dataWindow)44 ImageLevel::resize (const Box2i& dataWindow)
45 {
46 if (dataWindow.max.x < dataWindow.min.x - 1||
47 dataWindow.max.y < dataWindow.min.y - 1)
48 {
49 THROW (ArgExc,
50 "Cannot reset data window for image level to "
51 "(" << dataWindow.min.x << ", " << dataWindow.min.y << ") - "
52 "(" << dataWindow.max.x << ", " << dataWindow.max.y << "). "
53 "The new data window is invalid.");
54 }
55
56 _dataWindow = dataWindow;
57 }
58
59
60 void
shiftPixels(int dx,int dy)61 ImageLevel::shiftPixels (int dx, int dy)
62 {
63 _dataWindow.min.x += dx;
64 _dataWindow.min.y += dy;
65 _dataWindow.max.x += dx;
66 _dataWindow.max.y += dy;
67 }
68
69
70 void
throwChannelExists(const string & name) const71 ImageLevel::throwChannelExists (const string& name) const
72 {
73 THROW (ArgExc, "Cannot insert a new image channel with "
74 "name \"" << name << "\" into an image level. "
75 "A channel with the same name exists already.");
76 }
77
78
79 void
throwBadChannelName(const string & name) const80 ImageLevel::throwBadChannelName (const string& name) const
81 {
82 THROW (ArgExc, "Attempt to access non-existent "
83 "image channel \"" << name << "\".");
84 }
85
86
87 void
throwBadChannelNameOrType(const string & name) const88 ImageLevel::throwBadChannelNameOrType (const string& name) const
89 {
90 THROW (ArgExc, "Image channel \"" << name << "\" does not exist "
91 "or is not of the expected type.");
92 }
93
94
95 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
96