/src/openexr/src/lib/OpenEXR/ImfPreviewImage.cpp
Line | Count | Source |
1 | | // |
2 | | // SPDX-License-Identifier: BSD-3-Clause |
3 | | // Copyright (c) Contributors to the OpenEXR Project. |
4 | | // |
5 | | |
6 | | //----------------------------------------------------------------------------- |
7 | | // |
8 | | // class PreviewImage |
9 | | // |
10 | | //----------------------------------------------------------------------------- |
11 | | |
12 | | #include "ImfPreviewImage.h" |
13 | | #include "Iex.h" |
14 | | #include "ImfCheckedArithmetic.h" |
15 | | #include "ImfNamespace.h" |
16 | | |
17 | | OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER |
18 | | |
19 | | PreviewImage::PreviewImage ( |
20 | | unsigned int width, unsigned int height, const PreviewRgba pixels[]) |
21 | 5.21k | { |
22 | 5.21k | _width = width; |
23 | 5.21k | _height = height; |
24 | 5.21k | _pixels = new PreviewRgba[checkArraySize ( |
25 | 5.21k | uiMult (_width, _height), sizeof (PreviewRgba))]; |
26 | | |
27 | 5.21k | if (pixels) |
28 | 2.60k | { |
29 | 352k | for (unsigned int i = 0; i < _width * _height; ++i) |
30 | 349k | _pixels[i] = pixels[i]; |
31 | 2.60k | } |
32 | 2.61k | else |
33 | 2.61k | { |
34 | 2.61k | for (unsigned int i = 0; i < _width * _height; ++i) |
35 | 0 | _pixels[i] = PreviewRgba (); |
36 | 2.61k | } |
37 | 5.21k | } |
38 | | |
39 | | PreviewImage::PreviewImage (const PreviewImage& other) |
40 | 2.60k | : _width (other._width) |
41 | 2.60k | , _height (other._height) |
42 | 2.60k | , _pixels (new PreviewRgba[other._width * other._height]) |
43 | 2.60k | { |
44 | 352k | for (unsigned int i = 0; i < _width * _height; ++i) |
45 | 349k | _pixels[i] = other._pixels[i]; |
46 | 2.60k | } |
47 | | |
48 | | PreviewImage::~PreviewImage () |
49 | 7.82k | { |
50 | 7.82k | delete[] _pixels; |
51 | 7.82k | } |
52 | | |
53 | | PreviewImage& |
54 | | PreviewImage::operator= (const PreviewImage& other) |
55 | 2.60k | { |
56 | 2.60k | if (this != &other) |
57 | 2.60k | { |
58 | 2.60k | delete[] _pixels; |
59 | | |
60 | 2.60k | _width = other._width; |
61 | 2.60k | _height = other._height; |
62 | 2.60k | _pixels = new PreviewRgba[other._width * other._height]; |
63 | | |
64 | 352k | for (unsigned int i = 0; i < _width * _height; ++i) |
65 | 349k | _pixels[i] = other._pixels[i]; |
66 | 2.60k | } |
67 | | |
68 | 2.60k | return *this; |
69 | 2.60k | } |
70 | | |
71 | | OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT |