29 #define _unused(x) ((void)(x)) 31 #include "SUAPI-CppWrapper/model/ImageRep.hpp" 41 SUImageRepRef ImageRep::copy_reference(
const ImageRep& other) {
42 if (other.m_attached || SUIsInvalid(other.m_image_rep)) {
43 return other.m_image_rep;
46 new_copy.m_attached =
true;
47 return new_copy.ref();
55 m_image_rep(SU_INVALID),
60 m_image_rep(image_rep),
66 ImageRep(copy_reference(other), other.m_attached)
71 if (SUIsValid(m_image_rep) && !m_attached) {
72 SUResult res = SUImageRepRelease(&m_image_rep);
73 assert(res == SU_ERROR_NONE); _unused(res);
79 if (!m_attached && SUIsValid(m_image_rep)) {
80 SUResult res = SUImageRepRelease(&m_image_rep);
81 assert(res == SU_ERROR_NONE); _unused(res);
83 m_image_rep = copy_reference(other);
84 m_attached = other.m_attached;
90 return SUIsInvalid(m_image_rep);
94 SUImageRepRef ImageRep::ref()
const {
99 ImageRep::operator SUImageRepRef()
const {
104 ImageRep::operator SUImageRepRef*() {
111 throw std::logic_error(
"CW::ImageRep::copy(): ImageRep is null");
113 SUImageRepRef copy_image = SU_INVALID;
114 SUResult res = SUImageRepCreate(©_image);
115 assert(res == SU_ERROR_NONE);
116 res = SUImageRepCopy(copy_image, m_image_rep);
117 assert(res == SU_ERROR_NONE); _unused(res);
124 throw std::logic_error(
"CW::ImageRep::set_data(): ImageRep is null");
126 SUResult res = SUImageRepSetData(m_image_rep, width, height, bits_per_pixel, row_padding, &pixel_data[0]);
127 if (res == SU_ERROR_OUT_OF_RANGE) {
128 if (width == 0 || height == 0) {
129 throw std::invalid_argument(
"CW::ImageRep::set_data(): given width or height is 0 - it must be greater than 0");
132 throw std::invalid_argument(
"CW::ImageRep::set_data(): given bits_per_pixel must be 8, 24 or 32");
135 assert(res == SU_ERROR_NONE); _unused(res);
141 throw std::logic_error(
"CW::ImageRep::load_file(): ImageRep is null");
143 SUResult res = SUImageRepLoadFile(m_image_rep, file_path.c_str());
144 if (res == SU_ERROR_SERIALIZATION) {
145 throw std::invalid_argument(
"CW::ImageRep::load_file(): Loading file failed. Probably invalid file path given.");
147 assert(res == SU_ERROR_NONE); _unused(res);
153 throw std::logic_error(
"CW::ImageRep::save_to_file(): ImageRep is null");
155 SUResult res = SUImageRepSaveToFile(m_image_rep, file_path.c_str());
156 if (res == SU_ERROR_SERIALIZATION) {
157 throw std::invalid_argument(
"CW::ImageRep::save_to_file(): Saving file failed. Probably invalid file path given.");
159 else if (res == SU_ERROR_NO_DATA) {
160 throw std::logic_error(
"CW::ImageRep::save_to_file(): Image contains no data to save.");
162 assert(res == SU_ERROR_NONE); _unused(res);
169 throw std::logic_error(
"CW::ImageRep::width(): ImageRep is null");
173 SUResult res = SUImageRepGetPixelDimensions(m_image_rep, &width, &height);
174 assert(res == SU_ERROR_NONE); _unused(res);
181 throw std::logic_error(
"CW::ImageRep::height(): ImageRep is null");
185 SUResult res = SUImageRepGetPixelDimensions(m_image_rep, &width, &height);
186 assert(res == SU_ERROR_NONE); _unused(res);
193 throw std::logic_error(
"CW::ImageRep::row_padding(): ImageRep is null");
196 SUResult res = SUImageRepGetRowPadding(m_image_rep, &padding);
197 assert(res == SU_ERROR_NONE); _unused(res);
204 throw std::logic_error(
"CW::ImageRep::resize(): ImageRep is null");
206 SUResult res = SUImageRepResize(m_image_rep, width, height);
207 if (res == SU_ERROR_OUT_OF_RANGE) {
208 throw std::invalid_argument(
"CW::ImageRep::resize(): width and height must be greater than 0.");
210 assert(res == SU_ERROR_NONE); _unused(res);
216 throw std::logic_error(
"CW::ImageRep::convert_to_32bits(): ImageRep is null");
218 SUResult res = SUImageRepConvertTo32BitsPerPixel(m_image_rep);
219 if (res == SU_ERROR_NO_DATA) {
220 throw std::logic_error(
"CW::ImageRep::convert_to_32bits(): Image contains no data.");
222 assert(res == SU_ERROR_NONE); _unused(res);
228 throw std::logic_error(
"CW::ImageRep::data_size(): ImageRep is null");
232 SUResult res = SUImageRepGetDataSize(m_image_rep, &data_size, &bits_per_pixel);
233 assert(res == SU_ERROR_NONE); _unused(res);
240 throw std::logic_error(
"CW::ImageRep::bits_per_pixel(): ImageRep is null");
244 SUResult res = SUImageRepGetDataSize(m_image_rep, &data_size, &bits_per_pixel);
245 assert(res == SU_ERROR_NONE); _unused(res);
252 throw std::logic_error(
"CW::ImageRep::pixel_data(): ImageRep is null");
257 SUResult res = SUImageRepGetData(m_image_rep, data_size, &pixel_data[0]);
258 assert(res == SU_ERROR_NONE); _unused(res);
void load_file(const std::string file_path)
void set_data(size_t width, size_t height, size_t bits_per_pixel, size_t row_padding, std::vector< SUByte > pixel_data)
void resize(size_t width, size_t height)
ImageRep & operator=(const ImageRep &other)
size_t row_padding() const
size_t bits_per_pixel() const
SUResult save_to_file(const std::string file_path) const
std::vector< SUByte > pixel_data() const