| 1 |
/* pbmtowbmp.c - convert a portable bitmap to a Wireless Bitmap file |
| 2 |
|
| 3 |
This is derived for Netpbm from the pbmwbmp package from |
| 4 |
<http://www.looplab.com/wap/tools> on 2000.06.06. |
| 5 |
|
| 6 |
The specifications for the wbmp format are part of the Wireless |
| 7 |
Application Environment specification at |
| 8 |
<http://www.wapforum.org/what/technical.htm>. |
| 9 |
|
| 10 |
** Copyright (C) 1999 Terje Sannum <[email protected]>. |
| 11 |
** |
| 12 |
** Permission to use, copy, modify, and distribute this software and its |
| 13 |
** documentation for any purpose and without fee is hereby granted, provided |
| 14 |
** that the above copyright notice appear in all copies and that both that |
| 15 |
** copyright notice and this permission notice appear in supporting |
| 16 |
** documentation. This software is provided "as is" without express or |
| 17 |
** implied warranty. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "pbm.h" |
| 21 |
|
| 22 |
static void |
| 23 |
outputint(int i) { |
| 24 |
int c = 1; |
| 25 |
while(i & 0x7f << 7*c) c++; |
| 26 |
while(c > 1) putchar(0x80 | ((i >> 7*--c) & 0xff)); |
| 27 |
putchar(i & 0x7f); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
int |
| 33 |
main(int argc, char *argv[]) { |
| 34 |
FILE *f; |
| 35 |
bit **image; |
| 36 |
int rows, cols, row, col; |
| 37 |
int c, p; |
| 38 |
|
| 39 |
pbm_init(&argc, argv); |
| 40 |
if(argc > 2) { |
| 41 |
fprintf(stderr, "Copyright (C) 1999 Terje Sannum <[email protected]>\n"); |
| 42 |
pm_usage("[pbmfile]"); |
| 43 |
} |
| 44 |
|
| 45 |
f = argc == 2 ? pm_openr(argv[1]) : stdin; |
| 46 |
image = pbm_readpbm(f, &cols, &rows); |
| 47 |
pm_close(f); |
| 48 |
|
| 49 |
/* Header */ |
| 50 |
putchar(0); /* Type 0: B/W, no compression */ |
| 51 |
putchar(0); /* FixHeaderField */ |
| 52 |
/* Geometry */ |
| 53 |
outputint(cols); |
| 54 |
outputint(rows); |
| 55 |
/* Image data */ |
| 56 |
for(row = 0; row < rows; row++) { |
| 57 |
p = c = 0; |
| 58 |
for(col = 0; col < cols; col++) { |
| 59 |
if(image[row][col] == PBM_WHITE) c = c | (1 << (7-p)); |
| 60 |
if(++p == 8) { |
| 61 |
putchar(c); |
| 62 |
p = c = 0; |
| 63 |
} |
| 64 |
} |
| 65 |
if(p) putchar(c); |
| 66 |
} |
| 67 |
|
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|