Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / align_bitmap_image.c
1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers. 
3
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either package_version 2
9 of the License, or (at your option) any later package_version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19 USA.
20
21 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
22
23 */
24 #include "config.h"
25
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #endif
29
30 #ifdef HAVE_STRINGS_H
31 #include <strings.h>
32 #endif
33
34 #ifdef HAVE_STDLIB_H
35 #include <stdlib.h>
36 #endif
37
38 #include "definitions.h"
39
40 /* a vector of length W*H called 'unaligned_image' contains the data. 
41 This is written to a vector 'byte_aligned_image', which in general is longer
42 and is of length 'vector_aligned. This routine returns the lenght of the image, 
43 once it have been byte-aligned 
44
45 The image 'unaligned_image' is expected to have the top of the image at the top of the
46 file. This routine puts the image, so the bottom of the image is at the beggining of the 
47 vector 'byte_aligned_image' 
48 */
49
50 int align_bitmap_image(int W,int H,unsigned char *unaligned_image,unsigned char *byte_aligned_image)
51 {
52    int i, j, vector_aligned=0, vector_original=0;
53    /* put into the vector, in reverse order - i.e. from bottom to top */
54    for(j=0;j<H;j++)
55    {
56       for(i=0;i <W; ++i)
57       {
58          /* vector_aligned is the offset into the image that's padded
59          to allow 4-byte alignment */
60          /* offset is not, and so will allways be <=vector_offset */
61          if( (i==0) && (vector_aligned%4!=0) )
62             vector_aligned++;
63          if( (i==0) && (vector_aligned%4!=0) )
64             vector_aligned++;
65          if( (i==0) && (vector_aligned%4!=0) )
66             vector_aligned++; 
67          byte_aligned_image[vector_aligned]=unaligned_image[vector_original];
68          byte_aligned_image[vector_aligned+1]=unaligned_image[vector_original+1];
69          byte_aligned_image[vector_aligned+2]=unaligned_image[vector_original+2];
70          vector_original+=3;
71          vector_aligned+=3;
72       }
73    }
74    if( vector_aligned%4!=0 )
75       vector_aligned++;
76    if( vector_aligned%4!=0 )
77       vector_aligned++;
78    if( vector_aligned%4!=0 )
79       vector_aligned++;
80    return(vector_aligned);
81 }