Changeset 821 for soft/giet_vm/applications/rosenfeld/src/bmpNR.c
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src/bmpNR.c
r798 r821 11 11 #include <math.h> 12 12 13 /* -- image -- */14 #ifdef CLI15 13 #include "nrc_os_config.h" 16 14 #include "nrtype.h" … … 18 16 #include "nrmacro.h" 19 17 #include "nralloc.h" 20 #endif21 18 22 19 #if TARGET_OS == LINUX … … 37 34 #define BI_RGB 0L 38 35 39 PRIVATE void ReadBMProw (int fd, long width, uint8 * row); 40 PRIVATE void WriteBMProw (uint8 * row, long width, int fd); 41 //PRIVATE void SetupPalette (RGBQUAD Palette[]); 42 43 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 44 //#pragma message("bmpio.h no WINDOWS echo") 45 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 46 #endif 47 48 /* ------------------------------------- */ 49 uint8 *ui8ArrayAppend(uint8 *ptr, uint8 x) 50 /* ------------------------------------- */ 36 static void ReadBMProw(int fd, long width, uint8 * row); 37 static void WriteBMProw(uint8 * row, long width, int fd); 38 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 39 40 /* --------------------------------------- */ 41 uint8 * ui8ArrayAppend(uint8 * ptr, uint8 x) 42 /* --------------------------------------- */ 51 43 { 52 44 *ptr++ = x; 53 45 return ptr; 54 46 } 47 55 48 /* ---------------------------------------- */ 56 uint8 * ui16ArrayAppend(uint8 *ptr, uint16 x)57 49 uint8 * ui16ArrayAppend(uint8 * ptr, uint16 x) 50 /* ---------------------------------------- */ 58 51 { 59 52 uint8 x0, x1; … … 67 60 return ptr; 68 61 } 69 /* -------------------------------------- */ 70 uint8 *ui32ArrayAppend(uint8 *ptr, uint32 x) 71 /* -------------------------------------- */ 62 63 /* ---------------------------------------- */ 64 uint8 * ui32ArrayAppend(uint8 * ptr, uint32 x) 65 /* ---------------------------------------- */ 72 66 { 73 67 uint8 x0, x1, x2, x3; … … 85 79 return ptr; 86 80 } 81 87 82 // Seul moyen de cache dans la librairie ces putains de types windoze 88 83 89 84 // -------------------------------------------------------- 90 PRIVATE void ReadBMProw(int fd, long width, uint8 *row)91 85 static void ReadBMProw(int fd, long width, uint8 * row) 86 // -------------------------------------------------------- 92 87 { 93 88 // Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin 94 89 read(fd, row, sizeof(uint8) * width); 95 90 } 91 96 92 // --------------------------------------------------------- 97 PRIVATE void WriteBMProw(uint8 *row, long width, int fd)98 93 static void WriteBMProw(uint8 * row, long width, int fd) 94 // --------------------------------------------------------- 99 95 { 100 96 // Le fichier est deja ouvert et ne sera pas ferme a la fin 101 97 write(fd, row, sizeof(uint8) * width); 102 98 } 103 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 104 //#pragma message("bmpio.h no WINDOWS echo") 99 105 100 /* ----------------------------------------------------------- */ 106 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad *src, RGBQUAD dst[])107 101 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]) 102 /* ----------------------------------------------------------- */ 108 103 { 109 104 int i; … … 115 110 } 116 111 } 117 #endif 118 119 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 120 //#pragma message("bmpio.h no WINDOWS echo") 121 /* --------------------------------------------------------------------------- */ 122 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 **m, int width, int height, RGBQuad *palette_RGBQuad, char *filename) 112 113 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 123 114 /* --------------------------------------------------------------------------- */ 124 115 /* sauvegarde 'image' au format bmp dans le fichier 'filename' */ 125 116 { 126 int rc = 0;127 128 117 int v_offset = 0; // no more implemented image->v_offset; 129 118 int h_offset = 0; // no more implemented image->h_offset; 130 119 int vmax = height - v_offset; 131 //int hmax = width - h_offset; 132 int height_utile = height - 2*v_offset; 133 int width_utile = width - 2*h_offset; 120 int height_utile = height - 2 * v_offset; 121 int width_utile = width - 2 * h_offset; 134 122 int taille_utile = height_utile * width_utile; 135 123 136 //int size;137 124 int padding_len; 138 125 139 126 BITMAPFILEHEADER Bitmap_File_Header; 140 /*BITMAPINFO; Bitmap_Info; */141 142 127 BITMAPINFOHEADER Bitmap_Info_Header; 143 /*RGBQUAD RGB_Quad; */144 128 145 129 RGBQUAD palette_RGBQUAD[256]; /* Windows */ … … 156 140 157 141 /* --- Header --- */ 158 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 159 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQuad)+taille_utile; /* taille avec header et palette */ 160 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 161 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 162 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 163 (DWORD) sizeof(BITMAPINFOHEADER) + 164 (DWORD) sizeof(RGBQUAD)*256; /* */ 142 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 143 /* taille avec header et palette */ 144 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQuad) + taille_utile; 145 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 146 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 147 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + (DWORD) sizeof(BITMAPINFOHEADER) + (DWORD) sizeof(RGBQUAD)*256; /* */ 165 148 166 149 … … 182 165 fd = open(filename, O_CREAT | O_TRUNC); 183 166 if (fd < 0) { 184 printf("*** Erreur : Ouverture du fichier impossible dans SaveBMP"); 167 printf("\n*** Erreur : Ouverture du fichier impossible dans SaveBMP\n"); 168 return -1; 185 169 } 186 170 … … 215 199 } 216 200 close(fd); 217 return rc;218 219 } 220 #endif 221 // ------------------------------------------------------------------------------------------------------------ 222 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad *palette_RGBQuad, char *filename)223 //------------------------------------------------------------------------------------------------------------224 201 return 0; 202 203 } 204 205 // ---------------------------------------------------------------------------------------------------------------- 206 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 207 // ---------------------------------------------------------------------------------------------------------------- 208 // sauvegarde 'image' au format bmp dans le fichier 'filename' 225 209 { 226 210 int taille_utile = height * width; 227 228 //int size;229 211 int padding_len; 230 212 … … 241 223 int fd; 242 224 int i; 243 244 //#pragma message("BMP warnin' data structure aligment must be 2")245 //#pragma message(" sizeof( BitmapFileHeader) must = 14, not 16")246 225 247 226 //DEBUG(printf("BMP0 : %d %d\n", sizeof( BITMAPFILEHEADER), sizeof( BITMAPINFOHEADER))); … … 298 277 //printf(" SaveBMP %s %dx%d\n", filename, width, height); 299 278 300 fd = open(filename, O_CREAT | O_TRUNC); 279 #if TARGET_OS != GIETVM 280 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 281 #else 282 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC); 283 #endif 301 284 if (fd < 0) { 302 printf("*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP", filename); 285 printf("\n*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP\n", filename); 286 return -1; 303 287 } 304 288 … … 326 310 327 311 328 // en 2x car le compilo est trop con ...329 312 padding_len = width % 4; 330 313 padding_len = (4 - padding_len) % 4;
Note: See TracChangeset
for help on using the changeset viewer.