#include "mfcpch.h"
#include <unistd.h>
#include <stdio.h>
#include "img.h"
#include "imgbmp.h"
Go to the source code of this file.
Read the header of a bmp format image and prepare to read the rest.
Definition at line 86 of file imgbmp.cpp.
00093 { 00094 UINT32 nread; //current bits 00095 BMPHEADER0 head0; //first part of header 00096 BMPHEADER head1; //first part of header 00097 BMPHEADER2 head2; //first part of header 00098 00099 *photo = 1; 00100 nread = read (fd, &head0, sizeof (head0)); 00101 if (nread != sizeof (head0)) 00102 return -1; 00103 nread = read (fd, &head1, sizeof (head1)); 00104 if (nread != sizeof (head1)) 00105 return -1; 00106 nread = read (fd, &head2, sizeof (head2)); 00107 if (nread != sizeof (head2)) 00108 return -1; 00109 00110 if (head0.bfType1 != 'B') 00111 return -1; 00112 if (head0.bfType2 != 'M') 00113 return -1; 00114 lseek (fd, head1.bfOffBits, SEEK_SET); 00115 *bpp = head2.biBitCount; 00116 *xsize = head2.biWidth; 00117 *ysize = head2.biHeight; 00118 *res = 300; //make up resolution 00119 return -2; //success 00120 }
Read a whole lz format image and close the file.
Definition at line 126 of file imgbmp.cpp.
00133 { 00134 UINT32 bpl; //bytes per line 00135 UINT32 wpl; //words per line 00136 UINT32 nread; //current bits 00137 INT32 index; //to cols 00138 00139 bpl = (xsize * bpp + 7) / 8; //bytes per line 00140 wpl = (bpl + 3) / 4; 00141 wpl *= 4; 00142 for (index = 0; index < ysize; index++) { 00143 nread = read (fd, pixels + bpl * (ysize - 1 - index), bpl); 00144 if (nread != bpl) 00145 return -1; 00146 if (wpl != bpl) 00147 lseek (fd, wpl - bpl, SEEK_CUR); 00148 } 00149 return 0; 00150 }
INT8 write_bmp_image | ( | int | fd, | |
UINT8 * | pixels, | |||
INT32 | xsize, | |||
INT32 | ysize, | |||
INT8 | bpp, | |||
INT8 | , | |||
INT32 | res | |||
) |
Write a whole lz format image and close the file.
Definition at line 156 of file imgbmp.cpp.
References BMPHEADER::bfOffBits, BMPHEADER::bfReserved1, BMPHEADER::bfReserved2, BMPHEADER0::bfType1, BMPHEADER0::bfType2, BMPHEADER2::biBitCount, BMPHEADER2::biClrImportant, BMPHEADER2::biClrUsed, BMPHEADER2::biCompression, BMPHEADER2::biHeight, BMPHEADER2::biPlanes, BMPHEADER2::biSize, BMPHEADER2::biSizeImage, BMPHEADER2::biWidth, BMPHEADER2::biXPelsPerMeter, BMPHEADER2::biYPelsPerMeter, WIN32_RGBQUAD::rgbBlue, WIN32_RGBQUAD::rgbGreen, WIN32_RGBQUAD::rgbRed, and WIN32_RGBQUAD::rgbReserved.
00164 { 00165 UINT32 bpl; //bytes per line 00166 UINT32 wpl; //words per line 00167 UINT32 nread; //current bits 00168 INT32 cols; //entries in table 00169 INT32 index; //to cols 00170 BMPHEADER0 head0; //first part of header 00171 BMPHEADER head1; //first part of header 00172 BMPHEADER2 head2; //first part of header 00173 WIN32_RGBQUAD coltab[256]; //colour table 00174 00175 if (bpp == 24) 00176 cols = 0; 00177 else 00178 cols = 1 << bpp; //size of colour table 00179 bpl = (xsize * bpp + 7) / 8; //bytes per line 00180 wpl = (bpl + 3) / 4; 00181 00182 head2.biSize = sizeof (head2); //size of struct 00183 head2.biWidth = xsize; //image width 00184 head2.biHeight = ysize; //image height 00185 head2.biPlanes = 1; //1 00186 head2.biBitCount = bpp; //bpp 00187 head2.biCompression = 0; //0 for uncompressed 00188 //image size 00189 head2.biSizeImage = wpl * 4 * ysize; 00190 //res in pp metre 00191 head2.biXPelsPerMeter = (UINT32) (res * 39.37); 00192 head2.biYPelsPerMeter = (UINT32) (res * 39.37); 00193 head2.biClrUsed = cols; //0 or actual size of colour table 00194 head2.biClrImportant = 0; //usually 0 00195 00196 head0.bfType1 = 'B'; 00197 head0.bfType2 = 'M'; 00198 head1.bfReserved1 = 0; //zero 00199 head1.bfReserved2 = 0; //zero 00200 //offset to bitmap 00201 head1.bfOffBits = sizeof (head0) + sizeof (head1) + 00202 sizeof (head2) + sizeof (WIN32_RGBQUAD) * cols; 00203 //filesize 00204 head1.bfSize = head1.bfOffBits + head2.biSizeImage; 00205 00206 for (index = 0; index < cols; index++) { 00207 coltab[index].rgbBlue = index * 255 / (cols - 1); 00208 coltab[index].rgbGreen = coltab[index].rgbBlue; 00209 coltab[index].rgbRed = coltab[index].rgbBlue; 00210 coltab[index].rgbReserved = 0; 00211 } 00212 00213 nread = write (fd, &head0, sizeof (head0)); 00214 if (nread != sizeof (head0)) 00215 return -1; 00216 nread = write (fd, &head1, sizeof (head1)); 00217 if (nread != sizeof (head1)) 00218 return -1; 00219 nread = write (fd, &head2, sizeof (head2)); 00220 if (nread != sizeof (head2)) 00221 return -1; 00222 nread = write (fd, coltab, cols * sizeof (WIN32_RGBQUAD)); 00223 if (nread != cols * sizeof (WIN32_RGBQUAD)) 00224 return -1; 00225 for (index = 0; index < ysize; index++) { 00226 nread = write (fd, pixels + bpl * (ysize - 1 - index), wpl * 4); 00227 if (nread != wpl * 4) 00228 return -1; 00229 } 00230 close(fd); //done it 00231 return 0; 00232 }