|
Packit |
78deda |
/* pbmtowbmp.c - convert a portable bitmap to a Wireless Bitmap file
|
|
Packit |
78deda |
|
|
Packit |
78deda |
This is derived for Netpbm from the pbmwbmp package from
|
|
Packit |
78deda |
<http://www.looplab.com/wap/tools> on 2000.06.06.
|
|
Packit |
78deda |
|
|
Packit |
78deda |
The specifications for the wbmp format are part of the Wireless
|
|
Packit |
78deda |
Application Environment specification at
|
|
Packit |
78deda |
<http://www.wapforum.org/what/technical.htm>.
|
|
Packit |
78deda |
|
|
Packit |
78deda |
** Copyright (C) 1999 Terje Sannum <terje@looplab.com>.
|
|
Packit |
78deda |
**
|
|
Packit |
78deda |
** Permission to use, copy, modify, and distribute this software and its
|
|
Packit |
78deda |
** documentation for any purpose and without fee is hereby granted, provided
|
|
Packit |
78deda |
** that the above copyright notice appear in all copies and that both that
|
|
Packit |
78deda |
** copyright notice and this permission notice appear in supporting
|
|
Packit |
78deda |
** documentation. This software is provided "as is" without express or
|
|
Packit |
78deda |
** implied warranty.
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include "pbm.h"
|
|
Packit |
78deda |
|
|
Packit |
78deda |
static void
|
|
Packit |
78deda |
outputint(int i) {
|
|
Packit |
78deda |
int c = 1;
|
|
Packit |
78deda |
while(i & 0x7f << 7*c) c++;
|
|
Packit |
78deda |
while(c > 1) putchar(0x80 | ((i >> 7*--c) & 0xff));
|
|
Packit |
78deda |
putchar(i & 0x7f);
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
|
|
Packit |
78deda |
|
|
Packit |
78deda |
int
|
|
Packit |
78deda |
main(int argc, char *argv[]) {
|
|
Packit |
78deda |
FILE *f;
|
|
Packit |
78deda |
bit **image;
|
|
Packit |
78deda |
int rows, cols, row, col;
|
|
Packit |
78deda |
int c, p;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
pbm_init(&argc, argv);
|
|
Packit |
78deda |
if(argc > 2) {
|
|
Packit |
78deda |
fprintf(stderr, "Copyright (C) 1999 Terje Sannum <terje@looplab.com>\n");
|
|
Packit |
78deda |
pm_usage("[pbmfile]");
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
f = argc == 2 ? pm_openr(argv[1]) : stdin;
|
|
Packit |
78deda |
image = pbm_readpbm(f, &cols, &rows);
|
|
Packit |
78deda |
pm_close(f);
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Header */
|
|
Packit |
78deda |
putchar(0); /* Type 0: B/W, no compression */
|
|
Packit |
78deda |
putchar(0); /* FixHeaderField */
|
|
Packit |
78deda |
/* Geometry */
|
|
Packit |
78deda |
outputint(cols);
|
|
Packit |
78deda |
outputint(rows);
|
|
Packit |
78deda |
/* Image data */
|
|
Packit |
78deda |
for(row = 0; row < rows; row++) {
|
|
Packit |
78deda |
p = c = 0;
|
|
Packit |
78deda |
for(col = 0; col < cols; col++) {
|
|
Packit |
78deda |
if(image[row][col] == PBM_WHITE) c = c | (1 << (7-p));
|
|
Packit |
78deda |
if(++p == 8) {
|
|
Packit |
78deda |
putchar(c);
|
|
Packit |
78deda |
p = c = 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
if(p) putchar(c);
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|