| 1 | /* glprgr.c */cxx . . $ `<file>/external/glpk/glprgr.c`/ |
| 2 | |
| 3 | /*********************************************************************** |
| 4 | * This code is part of GLPK (GNU Linear Programming Kit). |
| 5 | * |
| 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
| 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, |
| 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. |
| 9 | * E-mail: <[email protected]>. |
| 10 | * |
| 11 | * GLPK is free software: you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 19 | * License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with GLPK. If not, see <http://www.gnu.org/licenses/>. |
| 23 | ***********************************************************************/ |
| 24 | |
| 25 | #define _GLPSTD_ERRNOcxx . . $ `external/glpk/glprgr.c:25:9`! |
| 26 | #define _GLPSTD_STDIOcxx . . $ `external/glpk/glprgr.c:26:9`! |
| 27 | #include "glpenv.h"cxx . . $ `<file>/external/glpk/glpenv.h`/ |
| 28 | #include "glprgr.h"cxx . . $ `<file>/external/glpk/glprgr.h`/ |
| 29 | #define xfaultcxx . . $ `external/glpk/glprgr.c:29:9`! xerrorcxx . . $ `external/glpk/glpenv.h:158:9`! |
| 30 | |
| 31 | /*********************************************************************** |
| 32 | * NAME |
| 33 | * |
| 34 | * rgr_write_bmp16 - write 16-color raster image in BMP file format |
| 35 | * |
| 36 | * SYNOPSIS |
| 37 | * |
| 38 | * #include "glprgr.h" |
| 39 | * int rgr_write_bmp16(const char *fname, int m, int n, const char |
| 40 | * map[]); |
| 41 | * |
| 42 | * DESCRIPTION |
| 43 | * |
| 44 | * The routine rgr_write_bmp16 writes 16-color raster image in |
| 45 | * uncompressed BMP file format (Windows bitmap) to a binary file whose |
| 46 | * name is specified by the character string fname. |
| 47 | * |
| 48 | * The parameters m and n specify, respectively, the number of rows and |
| 49 | * the numbers of columns (i.e. height and width) of the raster image. |
| 50 | * |
| 51 | * The character array map has m*n elements. Elements map[0, ..., n-1] |
| 52 | * correspond to the first (top) scanline, elements map[n, ..., 2*n-1] |
| 53 | * correspond to the second scanline, etc. |
| 54 | * |
| 55 | * Each element of the array map specifies a color of the corresponding |
| 56 | * pixel as 8-bit binary number XXXXIRGB, where four high-order bits (X) |
| 57 | * are ignored, I is high intensity bit, R is red color bit, G is green |
| 58 | * color bit, and B is blue color bit. Thus, all 16 possible colors are |
| 59 | * coded as following hexadecimal numbers: |
| 60 | * |
| 61 | * 0x00 = black 0x08 = dark gray |
| 62 | * 0x01 = blue 0x09 = bright blue |
| 63 | * 0x02 = green 0x0A = bright green |
| 64 | * 0x03 = cyan 0x0B = bright cyan |
| 65 | * 0x04 = red 0x0C = bright red |
| 66 | * 0x05 = magenta 0x0D = bright magenta |
| 67 | * 0x06 = brown 0x0E = yellow |
| 68 | * 0x07 = light gray 0x0F = white |
| 69 | * |
| 70 | * RETURNS |
| 71 | * |
| 72 | * If no error occured, the routine returns zero; otherwise, it prints |
| 73 | * an appropriate error message and returns non-zero. */ |
| 74 | |
| 75 | static void put_bytecxx . . $ put_byte(e780f64711fb334f).(FILEcxx . . $ FILE# *fp, int c) |
| 76 | { fputccxx . . $ fputc(b1cd03d6c470d1bd).(c, fp); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | static void put_wordcxx . . $ put_word(e780f64711fb334f).(FILEcxx . . $ FILE# *fp, int w) |
| 81 | { /* big endian */ |
| 82 | put_bytecxx . . $ put_byte(e780f64711fb334f).(fp, w); |
| 83 | put_bytecxx . . $ put_byte(e780f64711fb334f).(fp, w >> 8); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | static void put_dwordcxx . . $ put_dword(e780f64711fb334f).(FILEcxx . . $ FILE# *fp, int d) |
| 88 | { /* big endian */ |
| 89 | put_wordcxx . . $ put_word(e780f64711fb334f).(fp, d); |
| 90 | put_wordcxx . . $ put_word(e780f64711fb334f).(fp, d >> 16); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | int rgr_write_bmp16cxx . . $ `external/glpk/glprgr.h:28:9`!(const char *fname, int m, int n, const char map[]) |
| 95 | { FILEcxx . . $ FILE# *fp; |
| 96 | int offset, bmsize, i, j, b, ret = 0; |
| 97 | if (!(1 <= m && m <= 32767)) |
| 98 | xfaultcxx . . $ `external/glpk/glprgr.c:29:9`!("rgr_write_bmp16: m = %d; invalid height\n", m); |
| 99 | if (!(1 <= n && n <= 32767)) |
| 100 | xfaultcxx . . $ `external/glpk/glprgr.c:29:9`!("rgr_write_bmp16: n = %d; invalid width\n", n); |
| 101 | fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(fname, "wb"); |
| 102 | if (fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 103 | { xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("rgr_write_bmp16: unable to create `%s' - %s\n", |
| 104 | fname, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 105 | ret = 1; |
| 106 | goto fini; |
| 107 | } |
| 108 | offset = 14 + 40 + 16 * 4; |
| 109 | bmsize = (4 * n + 31) / 32; |
| 110 | /* struct BMPFILEHEADER (14 bytes) */ |
| 111 | /* UINT bfType */ put_bytecxx . . $ put_byte(e780f64711fb334f).(fp, 'B'), put_bytecxx . . $ put_byte(e780f64711fb334f).(fp, 'M'); |
| 112 | /* DWORD bfSize */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, offset + bmsize * 4); |
| 113 | /* UINT bfReserved1 */ put_wordcxx . . $ put_word(e780f64711fb334f).(fp, 0); |
| 114 | /* UNIT bfReserved2 */ put_wordcxx . . $ put_word(e780f64711fb334f).(fp, 0); |
| 115 | /* DWORD bfOffBits */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, offset); |
| 116 | /* struct BMPINFOHEADER (40 bytes) */ |
| 117 | /* DWORD biSize */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 40); |
| 118 | /* LONG biWidth */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, n); |
| 119 | /* LONG biHeight */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, m); |
| 120 | /* WORD biPlanes */ put_wordcxx . . $ put_word(e780f64711fb334f).(fp, 1); |
| 121 | /* WORD biBitCount */ put_wordcxx . . $ put_word(e780f64711fb334f).(fp, 4); |
| 122 | /* DWORD biCompression */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0 /* BI_RGB */); |
| 123 | /* DWORD biSizeImage */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0); |
| 124 | /* LONG biXPelsPerMeter */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 2953 /* 75 dpi */); |
| 125 | /* LONG biYPelsPerMeter */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 2953 /* 75 dpi */); |
| 126 | /* DWORD biClrUsed */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0); |
| 127 | /* DWORD biClrImportant */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0); |
| 128 | /* struct RGBQUAD (16 * 4 = 64 bytes) */ |
| 129 | /* CGA-compatible colors: */ |
| 130 | /* 0x00 = black */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x000000); |
| 131 | /* 0x01 = blue */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x000080); |
| 132 | /* 0x02 = green */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x008000); |
| 133 | /* 0x03 = cyan */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x008080); |
| 134 | /* 0x04 = red */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x800000); |
| 135 | /* 0x05 = magenta */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x800080); |
| 136 | /* 0x06 = brown */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x808000); |
| 137 | /* 0x07 = light gray */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0xC0C0C0); |
| 138 | /* 0x08 = dark gray */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x808080); |
| 139 | /* 0x09 = bright blue */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x0000FF); |
| 140 | /* 0x0A = bright green */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x00FF00); |
| 141 | /* 0x0B = bright cyan */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0x00FFFF); |
| 142 | /* 0x0C = bright red */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0xFF0000); |
| 143 | /* 0x0D = bright magenta */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0xFF00FF); |
| 144 | /* 0x0E = yellow */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0xFFFF00); |
| 145 | /* 0x0F = white */ put_dwordcxx . . $ put_dword(e780f64711fb334f).(fp, 0xFFFFFF); |
| 146 | /* pixel data bits */ |
| 147 | b = 0; |
| 148 | for (i = m - 1; i >= 0; i--) |
| 149 | { for (j = 0; j < ((n + 7) / 8) * 8; j++) |
| 150 | { b <<= 4; |
| 151 | b |= (j < n ? map[i * n + j] & 15 : 0); |
| 152 | if (j & 1) put_bytecxx . . $ put_byte(e780f64711fb334f).(fp, b); |
| 153 | } |
| 154 | } |
| 155 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(fp); |
| 156 | if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(fp)) |
| 157 | { xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("rgr_write_bmp16: write error on `%s' - %s\n", |
| 158 | fname, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 159 | ret = 1; |
| 160 | } |
| 161 | fini: if (fp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | /* eof */ |