mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
imageUtils.cpp
Go to the documentation of this file.
1 /** \file imageUtils.cpp
2  * \author Jared R. Males
3  * \brief Implementation of image processing utilities
4  * \ingroup image_processing_files
5  *
6  */
7 
8 //***********************************************************************//
9 // Copyright 2021 Jared R. Males (jaredmales@gmail.com)
10 //
11 // This file is part of mxlib.
12 //
13 // mxlib is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // mxlib is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 //***********************************************************************//
26 
27 #include "improc/imageUtils.hpp"
28 #include <cstring>
29 
30 namespace mx
31 {
32 namespace improc
33 {
34 
35 void * imcpy( void * dest,
36  void * src,
37  size_t width,
38  size_t height,
39  size_t szof
40  )
41 {
42  return memcpy(dest, src, width*height*szof);
43 }
44 
45 void * imcpy_flipUD( void * dest,
46  void * src,
47  size_t width,
48  size_t height,
49  size_t szof
50  )
51 {
52  for(size_t rr=0; rr< height; ++rr)
53  {
54  memcpy((char *)dest + rr*width*szof, (char *)src + (height-1-rr)*width*szof, width*szof);
55  }
56 
57  return dest;
58 }
59 
60 void * imcpy_flipLR( void * dest,
61  void * src,
62  size_t width,
63  size_t height,
64  size_t szof
65  )
66 {
67  if(szof == 1)
68  {
69  uint8_t * d = (uint8_t *) dest;
70  uint8_t * s = (uint8_t *)src;
71  for(size_t rr=0; rr< height; ++rr)
72  {
73  for(size_t cc=0; cc<width; ++cc)
74  {
75  d[rr*width + cc] = s[rr*width + (width-1-cc)];
76  }
77  }
78  }
79  else if(szof == 2)
80  {
81  uint16_t * d = (uint16_t *) dest;
82  uint16_t * s = (uint16_t *) src;
83  for(size_t rr=0; rr< height; ++rr)
84  {
85  for(size_t cc=0; cc<width; ++cc)
86  {
87  d[rr*width + cc] = s[rr*width + (width-1-cc)];
88  }
89  }
90  }
91  else if(szof == 4)
92  {
93  uint32_t * d = (uint32_t *) dest;
94  uint32_t * s = (uint32_t *) src;
95  for(size_t rr=0; rr< height; ++rr)
96  {
97  for(size_t cc=0; cc<width; ++cc)
98  {
99  d[rr*width + cc] = s[rr*width + (width-1-cc)];
100  }
101  }
102  }
103  else if(szof == 8)
104  {
105  uint64_t * d = (uint64_t *) dest;
106  uint64_t * s = (uint64_t *) src;
107  for(size_t rr=0; rr< height; ++rr)
108  {
109  for(size_t cc=0; cc<width; ++cc)
110  {
111  d[rr*width + cc] = s[rr*width + (width-1-cc)];
112  }
113  }
114  }
115  else
116  {
117  uint8_t * d = (uint8_t *) dest;
118  uint8_t * s = (uint8_t *) src;
119  for(size_t rr=0; rr< height; ++rr)
120  {
121  for(size_t cc=0; cc<width*szof; cc += szof)
122  {
123  for(size_t pp=0; pp<szof;++pp)
124  {
125  d[rr*width*szof + cc + pp] = s[rr*width*szof + (width*szof-szof-cc) +pp];
126  }
127  }
128  }
129  }
130  return dest;
131 }
132 
133 void * imcpy_flipUDLR( void * dest,
134  void * src,
135  size_t width,
136  size_t height,
137  size_t szof
138  )
139 {
140  if(szof == 1)
141  {
142  uint8_t * d = (uint8_t *) dest;
143  uint8_t * s = (uint8_t *) src;
144  for(size_t rr=0; rr< height; ++rr)
145  {
146  for(size_t cc=0; cc<width; ++cc)
147  {
148  {
149  d[rr*width + cc] = s[(height-1-rr)*width + (width-1-cc)];
150  }
151  }
152  }
153  }
154  else if(szof == 2)
155  {
156  uint16_t * d = (uint16_t *) dest;
157  uint16_t * s = (uint16_t *) src;
158  for(size_t rr=0; rr< height; ++rr)
159  {
160  for(size_t cc=0; cc<width; ++cc)
161  {
162  {
163  d[rr*width + cc] = s[(height-1-rr)*width + (width-1-cc)];
164  }
165  }
166  }
167  }
168  else if(szof == 4)
169  {
170  uint32_t * d = (uint32_t *) dest;
171  uint32_t * s = (uint32_t *) src;
172  for(size_t rr=0; rr< height; ++rr)
173  {
174  for(size_t cc=0; cc<width; ++cc)
175  {
176  {
177  d[rr*width + cc] = s[(height-1-rr)*width + (width-1-cc)];
178  }
179  }
180  }
181  }
182  else if(szof == 8)
183  {
184  uint64_t * d = (uint64_t *) dest;
185  uint64_t * s = (uint64_t *) src;
186  for(size_t rr=0; rr< height; ++rr)
187  {
188  for(size_t cc=0; cc<width; ++cc)
189  {
190  {
191  d[rr*width + cc] = s[(height-1-rr)*width + (width-1-cc)];
192  }
193  }
194  }
195  }
196  else
197  {
198  uint8_t * d = (uint8_t *) dest;
199  uint8_t * s = (uint8_t *) src;
200  for(size_t rr=0; rr< height; ++rr)
201  {
202  for(size_t cc=0; cc<width*szof; cc += szof)
203  {
204  for(size_t pp=0; pp<szof;++pp)
205  {
206  d[rr*width*szof + cc + pp] = s[(height-1-rr)*width*szof + (width*szof-szof-cc) +pp];
207  }
208  }
209  }
210  }
211 
212  return dest;
213 }
214 
215 } //namespace math
216 } //namespace mx
217 
void * imcpy(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, with no transformation.
Definition: imageUtils.cpp:35
void * imcpy_flipLR(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping left-right.
Definition: imageUtils.cpp:60
void * imcpy_flipUDLR(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping up-down and left-right.
Definition: imageUtils.cpp:133
void * imcpy_flipUD(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping up-down.
Definition: imageUtils.cpp:45
Header for the image processing utilities.
The mxlib c++ namespace.
Definition: mxError.hpp:107