Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
simage13.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Kongsberg Oil & Gas Technologies
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <assert.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif /* HAVE_CONFIG_H */
24 
25 #include <simage.h>
26 #include <simage_private.h>
27 #include <string.h>
28 
29 unsigned char * simage_resize3d(unsigned char *src,
30  int width, int height,
31  int nc, int layers,
32  int newwidth, int newheight,
33  int newlayers)
34 {
35  float sx, sy, sz, dx, dy, dz;
36  int src_bpr, dest_bpr, src_bpl, dest_bpl, xstop, ystop, zstop;
37  int x, y, z, offset, i;
38  unsigned char *dest =
39  (unsigned char*) malloc((size_t)newwidth*newheight*nc*newlayers);
40 
41  dx = ((float)width)/((float)newwidth);
42  dy = ((float)height)/((float)newheight);
43  dz = ((float)layers)/((float)newlayers);
44  src_bpr = width * nc;
45  dest_bpr = newwidth * nc;
46  src_bpl = src_bpr * height;
47  dest_bpl = dest_bpr * newheight;
48 
49  zstop = newlayers * dest_bpl;
50  ystop = dest_bpl;
51  xstop = dest_bpr;
52  sz = 0.0f;
53  for (z = 0; z < zstop; z += dest_bpl) {
54  sy = 0.0f;
55  for (y = 0; y < ystop; y += dest_bpr) {
56  sx = 0.0f;
57  for (x = 0; x < xstop; x += nc) {
58  offset = ((int)sz)*src_bpl + ((int)sy)*src_bpr + ((int)sx)*nc;
59  for (i = 0; i < nc; i++) dest[x+y+z+i] = src[offset+i];
60  sx += dx;
61  }
62  sy += dy;
63  }
64  sz += dz;
65  }
66  return dest;
67 }
unsigned char * simage_resize3d(unsigned char *src, int width, int height, int nc, int layers, int newwidth, int newheight, int newlayers)
Definition: simage13.c:29
Windows specific information.