Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / write_bitmap.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
25 #include "config.h"
26
27 #ifdef HAVE_STRING_H
28 #include <string.h>
29 #endif
30
31 #ifdef HAVE_STRINGS_H
32 #include <strings.h>
33 #endif
34
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38
39 #include "definitions.h"
40 #include "Erdata.h" 
41
42 /* names, colours and Ers are all arrays of 10. It would be better they were 
43 in a structure as they are all linked closely, but they are not and I
44 can't be bothered to change it */
45
46 extern int W, H;
47
48 void write_bitmap(FILE *image_data_fp, struct transmission_line_properties xyz)
49 {
50    int colour_Er1=-1, colour_Er2=-1, vector_aligned;
51 #ifndef HAVE_MEMSET
52    int memory_location;
53 #endif
54    unsigned char *image_data, *unaligned_image_vector;
55
56    get_Er1_and_Er2_colours(&colour_Er1, &colour_Er2);
57    W+=2*BORDER;
58    H+=2*BORDER;
59    xyz.W+=2*BORDER;
60    xyz.H+=2*BORDER;
61    /* We create an vector big enough for the image. Since rows are 
62    aligned on 4-byte boundaries, we need to allow suffient space for
63    (W+2)*(H-1) bytes. */
64
65    /* when aligning data on 4-byte boundaries, the 
66    padding must be filled with 0's, to meet the 
67    .bmp standard */
68
69    image_data=ustring(0,(W+3)*3*H);
70    unaligned_image_vector=ustring(0,(W+3)*3*H);
71
72 #ifdef HAVE_MEMSET
73    (void) memset((void *) (image_data),0x0,(size_t) ((W+3)*3*H));
74 #else
75    for(memory_location=0; memory_location < (W+3)*3*H; ++ memory_location)
76      image_data[memory_location]=0;
77 #endif /* end of #ifdef HAVE_MEMSET */
78
79
80    /* Fill a vector with the initial (original) data on the 
81    tline. This is not aligned in any way */
82    /* The following function 'fill_image_vector_with_data' is *not* in the file
83    fill_image_vector_with_data.c, but instead different versions of it are 
84    located in files fill_rect_with_rect.c, fill_circ_with_circ.c, 
85    fill_rect_with_circ.c and fill_circ_with_rect.c */
86    fill_image_vector_with_data(unaligned_image_vector, colour_Er1, colour_Er2, xyz);
87    
88    /* put into the vector, in reverse order - i.e. from bottom to top and 
89    align each row on 4-byte boundaries */
90    vector_aligned=align_bitmap_image(W, H, unaligned_image_vector,image_data);
91    write_bitmap_out(image_data, image_data_fp,vector_aligned, W, H);
92 }