1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers.
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
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.
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.
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,
21 Dr. David Kirkby, e-mail drkirkby at gmail.com
43 #include "definitions.h"
44 #include "exit_codes.h"
46 /* names, colours and Ers are all arrays of 10. It would be better they were
47 in a structure as they are all linked closely, but they are not and I
48 can't be bothered to change it */
53 /* This function can be used on any routines that writes .bmp files */
55 void write_bitmap_out(unsigned char *byte_aligned_image_data, FILE *image_data_fp,int sizeof_image, int W, int H)
59 struct Bitmap_File_Head_Struct Bitmap_File_Head;
60 struct Bitmap_Head_Struct Bitmap_Head;
63 printf("sizeof_image = %d in write_bitmap_out\n", sizeof_image);
68 /* fprintf(stderr,"file size=%ld\n",temp_long); */
70 Bitmap_File_Head.zzMagic[0]='B';
71 Bitmap_File_Head.zzMagic[1]='M';
72 Bitmap_File_Head.bfSize=sizeof_image+0x36;
73 Bitmap_File_Head.zzHotX=0;
74 Bitmap_File_Head.zzHotY=0;
75 Bitmap_File_Head.bfOffs=54;
76 Bitmap_File_Head.biSize=0x28;
79 Bitmap_Head.biWidth=W;
80 Bitmap_Head.biHeight=H;
81 Bitmap_Head.biPlanes=1;
82 Bitmap_Head.biBitCnt=24;
83 Bitmap_Head.biCompr=0;
84 Bitmap_Head.biSizeIm=sizeof_image;
85 Bitmap_Head.biXPels=W*10; /* Why ??? XXX */
86 Bitmap_Head.biYPels=H*10; /* Why ??? XXX */
87 Bitmap_Head.biClrUsed=0;
88 Bitmap_Head.biClrImp=0;
90 buff[0x00] = (unsigned char) (Bitmap_File_Head.zzMagic[0]);
91 buff[0x01] = (unsigned char) (Bitmap_File_Head.zzMagic[1]);
93 buff[0x02] = Bitmap_File_Head.bfSize);
94 buff[0x03] = Bitmap_File_Head.bfSize >> 8);
95 buff[0x04] = Bitmap_File_Head.bfSize >> 16);
96 buff[0x05] = Bitmap_File_Head.bfSize >> 24);
99 buff[0x02] = (unsigned char) (Bitmap_File_Head.bfSize);
100 buff[0x03] = (unsigned char) (Bitmap_File_Head.bfSize >> 8);
101 buff[0x04] = (unsigned char) (Bitmap_File_Head.bfSize >> 16);
102 buff[0x05] = (unsigned char) (Bitmap_File_Head.bfSize >> 24);
105 buff[0x06] = (unsigned char) (Bitmap_File_Head.zzHotX);
106 buff[0x07] = (unsigned char) (Bitmap_File_Head.zzHotX >> 8);
108 buff[0x08] = (unsigned char) (Bitmap_File_Head.zzHotY);
109 buff[0x09] = (unsigned char) (Bitmap_File_Head.zzHotY >> 8);
111 buff[0x0a] = (unsigned char) (Bitmap_File_Head.bfOffs);
112 buff[0x0b] = (unsigned char) (Bitmap_File_Head.bfOffs>> 8);
113 buff[0x0c] = (unsigned char) (Bitmap_File_Head.bfOffs>> 16);
114 buff[0x0d] = (unsigned char) (Bitmap_File_Head.bfOffs>> 24);
116 buff[0x0e] = (unsigned char) (Bitmap_File_Head.biSize);
117 buff[0x0f] = (unsigned char) (Bitmap_File_Head.biSize>> 8);
118 buff[0x10] = (unsigned char) (Bitmap_File_Head.biSize>> 16);
119 buff[0x11] = (unsigned char) (Bitmap_File_Head.biSize>> 24);
121 /* Write contents of Bitmap_Head_Struct */
123 buff[0x12] = (unsigned char) (Bitmap_Head.biWidth);
124 buff[0x13] = (unsigned char) (Bitmap_Head.biWidth>> 8);
125 buff[0x14] = (unsigned char) (Bitmap_Head.biWidth>> 16);
126 buff[0x15] = (unsigned char) (Bitmap_Head.biWidth>> 24);
128 buff[0x16] = (unsigned char) (Bitmap_Head.biHeight);
129 buff[0x17] = (unsigned char) (Bitmap_Head.biHeight>> 8);
130 buff[0x18] = (unsigned char) (Bitmap_Head.biHeight>> 16);
131 buff[0x19] = (unsigned char) (Bitmap_Head.biHeight>> 24);
133 buff[0x1a] = (unsigned char) (Bitmap_Head.biPlanes);
134 buff[0x1b] = (unsigned char) (Bitmap_Head.biPlanes>> 8);
136 buff[0x1c] = (unsigned char) (Bitmap_Head.biBitCnt);
137 buff[0x1d] = (unsigned char) (Bitmap_Head.biBitCnt>> 8);
139 buff[0x1e] = (unsigned char) (Bitmap_Head.biCompr);
140 buff[0x1f] = (unsigned char) (Bitmap_Head.biCompr>> 8);
141 buff[0x20] = (unsigned char) (Bitmap_Head.biCompr>> 16);
142 buff[0x21] = (unsigned char) (Bitmap_Head.biCompr>> 24);
144 buff[0x22] = (unsigned char) (Bitmap_Head.biSizeIm);
145 buff[0x23] = (unsigned char) (Bitmap_Head.biSizeIm>> 8);
146 buff[0x24] = (unsigned char) (Bitmap_Head.biSizeIm>> 16);
147 buff[0x25] = (unsigned char) (Bitmap_Head.biSizeIm>> 24);
149 buff[0x26] = (unsigned char) (Bitmap_Head.biXPels);
150 buff[0x27] = (unsigned char) (Bitmap_Head.biXPels>> 8);
151 buff[0x28] = (unsigned char) (Bitmap_Head.biXPels>> 16);
152 buff[0x29] = (unsigned char) (Bitmap_Head.biXPels>> 24);
154 buff[0x2a] = (unsigned char) (Bitmap_Head.biYPels);
155 buff[0x2b] = (unsigned char) (Bitmap_Head.biYPels>> 8);
156 buff[0x2c] = (unsigned char) (Bitmap_Head.biYPels>> 16);
157 buff[0x2d] = (unsigned char) (Bitmap_Head.biYPels>> 24);
159 buff[0x2e] = (unsigned char) (Bitmap_Head.biClrUsed);
160 buff[0x2f] = (unsigned char) (Bitmap_Head.biClrUsed>> 8);
161 buff[0x30] = (unsigned char) (Bitmap_Head.biClrUsed>> 16);
162 buff[0x31] = (unsigned char) (Bitmap_Head.biClrUsed>> 24);
164 buff[0x32] = (unsigned char) (Bitmap_Head.biClrImp);
165 buff[0x33] = (unsigned char) (Bitmap_Head.biClrImp>> 8);
166 buff[0x34] = (unsigned char) (Bitmap_Head.biClrImp>> 16);
167 buff[0x35] = (unsigned char) (Bitmap_Head.biClrImp>> 24);
169 if( fwrite((void *) buff, 0x36, 1, image_data_fp) != 1)
170 exit_with_msg_and_exit_code("Error#1: Failed to write bitmap file in write_bitmap_out.c",WRITE_FAILURE);
173 /* Now the reader is written, finally write the image */
174 if( fwrite(byte_aligned_image_data,(size_t) sizeof_image,1,image_data_fp) != 1)
175 exit_with_msg_and_exit_code("Error#1: Failed to write bitmap file in write_bitmap_out.c",WRITE_FAILURE);
176 if( fclose(image_data_fp) != 0)
177 exit_with_msg_and_exit_code("failed to close file in write_bitmap_out.c",CANT_CLOSE_FILE);