Line data Source code
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 0 : void *imcpy( void *dest, void *src, size_t width, size_t height, size_t szof )
36 : {
37 0 : return memcpy( dest, src, width * height * szof );
38 : }
39 :
40 0 : void *imcpy_flipUD( void *dest, void *src, size_t width, size_t height, size_t szof )
41 : {
42 0 : for( size_t rr = 0; rr < height; ++rr )
43 : {
44 0 : memcpy( (char *)dest + rr * width * szof, (char *)src + ( height - 1 - rr ) * width * szof, width * szof );
45 : }
46 :
47 0 : return dest;
48 : }
49 :
50 0 : void *imcpy_flipLR( void *dest, void *src, size_t width, size_t height, size_t szof )
51 : {
52 0 : if( szof == 1 )
53 : {
54 0 : uint8_t *d = (uint8_t *)dest;
55 0 : uint8_t *s = (uint8_t *)src;
56 0 : for( size_t rr = 0; rr < height; ++rr )
57 : {
58 0 : for( size_t cc = 0; cc < width; ++cc )
59 : {
60 0 : d[rr * width + cc] = s[rr * width + ( width - 1 - cc )];
61 : }
62 : }
63 : }
64 0 : else if( szof == 2 )
65 : {
66 0 : uint16_t *d = (uint16_t *)dest;
67 0 : uint16_t *s = (uint16_t *)src;
68 0 : for( size_t rr = 0; rr < height; ++rr )
69 : {
70 0 : for( size_t cc = 0; cc < width; ++cc )
71 : {
72 0 : d[rr * width + cc] = s[rr * width + ( width - 1 - cc )];
73 : }
74 : }
75 : }
76 0 : else if( szof == 4 )
77 : {
78 0 : uint32_t *d = (uint32_t *)dest;
79 0 : uint32_t *s = (uint32_t *)src;
80 0 : for( size_t rr = 0; rr < height; ++rr )
81 : {
82 0 : for( size_t cc = 0; cc < width; ++cc )
83 : {
84 0 : d[rr * width + cc] = s[rr * width + ( width - 1 - cc )];
85 : }
86 : }
87 : }
88 0 : else if( szof == 8 )
89 : {
90 0 : uint64_t *d = (uint64_t *)dest;
91 0 : uint64_t *s = (uint64_t *)src;
92 0 : for( size_t rr = 0; rr < height; ++rr )
93 : {
94 0 : for( size_t cc = 0; cc < width; ++cc )
95 : {
96 0 : d[rr * width + cc] = s[rr * width + ( width - 1 - cc )];
97 : }
98 : }
99 : }
100 : else
101 : {
102 0 : uint8_t *d = (uint8_t *)dest;
103 0 : uint8_t *s = (uint8_t *)src;
104 0 : for( size_t rr = 0; rr < height; ++rr )
105 : {
106 0 : for( size_t cc = 0; cc < width * szof; cc += szof )
107 : {
108 0 : for( size_t pp = 0; pp < szof; ++pp )
109 : {
110 0 : d[rr * width * szof + cc + pp] = s[rr * width * szof + ( width * szof - szof - cc ) + pp];
111 : }
112 : }
113 : }
114 : }
115 0 : return dest;
116 : }
117 :
118 0 : void *imcpy_flipUDLR( void *dest, void *src, size_t width, size_t height, size_t szof )
119 : {
120 0 : if( szof == 1 )
121 : {
122 0 : uint8_t *d = (uint8_t *)dest;
123 0 : uint8_t *s = (uint8_t *)src;
124 0 : for( size_t rr = 0; rr < height; ++rr )
125 : {
126 0 : for( size_t cc = 0; cc < width; ++cc )
127 : {
128 : {
129 0 : d[rr * width + cc] = s[( height - 1 - rr ) * width + ( width - 1 - cc )];
130 : }
131 : }
132 : }
133 : }
134 0 : else if( szof == 2 )
135 : {
136 0 : uint16_t *d = (uint16_t *)dest;
137 0 : uint16_t *s = (uint16_t *)src;
138 0 : for( size_t rr = 0; rr < height; ++rr )
139 : {
140 0 : for( size_t cc = 0; cc < width; ++cc )
141 : {
142 : {
143 0 : d[rr * width + cc] = s[( height - 1 - rr ) * width + ( width - 1 - cc )];
144 : }
145 : }
146 : }
147 : }
148 0 : else if( szof == 4 )
149 : {
150 0 : uint32_t *d = (uint32_t *)dest;
151 0 : uint32_t *s = (uint32_t *)src;
152 0 : for( size_t rr = 0; rr < height; ++rr )
153 : {
154 0 : for( size_t cc = 0; cc < width; ++cc )
155 : {
156 : {
157 0 : d[rr * width + cc] = s[( height - 1 - rr ) * width + ( width - 1 - cc )];
158 : }
159 : }
160 : }
161 : }
162 0 : else if( szof == 8 )
163 : {
164 0 : uint64_t *d = (uint64_t *)dest;
165 0 : uint64_t *s = (uint64_t *)src;
166 0 : for( size_t rr = 0; rr < height; ++rr )
167 : {
168 0 : for( size_t cc = 0; cc < width; ++cc )
169 : {
170 : {
171 0 : d[rr * width + cc] = s[( height - 1 - rr ) * width + ( width - 1 - cc )];
172 : }
173 : }
174 : }
175 : }
176 : else
177 : {
178 0 : uint8_t *d = (uint8_t *)dest;
179 0 : uint8_t *s = (uint8_t *)src;
180 0 : for( size_t rr = 0; rr < height; ++rr )
181 : {
182 0 : for( size_t cc = 0; cc < width * szof; cc += szof )
183 : {
184 0 : for( size_t pp = 0; pp < szof; ++pp )
185 : {
186 0 : d[rr * width * szof + cc + pp] =
187 0 : s[( height - 1 - rr ) * width * szof + ( width * szof - szof - cc ) + pp];
188 : }
189 : }
190 : }
191 : }
192 :
193 0 : return dest;
194 : }
195 :
196 : } // namespace improc
197 : } // namespace mx
|