tojpg, totif: change flags to better match those of the decoders

This commit is contained in:
ppatience0 2013-07-20 12:11:52 -04:00
parent 360cabb858
commit 105155880c
4 changed files with 82 additions and 79 deletions

View file

@ -70,7 +70,7 @@ jpg, gif, png, tif, ppm, bmp, v210, yuv, ico, tga, tojpg, togeordi, togif, toppm
.B -c .B -c
.I comment .I comment
] [ ] [
.B -gs .B -ks
] [ ] [
.I file .I file
] ]
@ -80,7 +80,7 @@ jpg, gif, png, tif, ppm, bmp, v210, yuv, ico, tga, tojpg, togeordi, togif, toppm
.B -c .B -c
.I comment .I comment
] [ ] [
.B -g .B -k
] [ ] [
.I file .I file
] ]
@ -133,7 +133,7 @@ jpg, gif, png, tif, ppm, bmp, v210, yuv, ico, tga, tojpg, togeordi, togif, toppm
.B -c .B -c
.I comment .I comment
] [ ] [
.B -bBgGhHlLmprtT .B -3bgGhklLptvyY
] [ ] [
.I file .I file
] ]
@ -269,10 +269,10 @@ option makes
output raw PPM. output raw PPM.
The default is to output plain PPM. The default is to output plain PPM.
The The
.B -g .B -k
option makes option makes
.I tojpg .I tojpg
output grayscale images, output grey-scale images,
and the and the
.B -s .B -s
option makes it output scratched JPEG images. option makes it output scratched JPEG images.
@ -285,48 +285,51 @@ script that invokes
.I Totif .I Totif
accepts many options. accepts many options.
Choosing Huffman, T4, or T6 compression Choosing Huffman, T4, or T6 compression
forces the output to be a bilevel image. forces the image to GREY1.
.TP
.B -3
Convert the image to a true color RGB image.
.TP .TP
.B -b .B -b
Output a bilevel (GREY1) image. Convert the image to a GREY1 black and white image.
.TP
.B -B
Output a grayscale (GREY2) image.
.TP .TP
.B -g .B -g
Output a grayscale (GREY4) image. Use T4 one-dimensional compression.
.TP .TP
.B -G .B -G
Output a grayscale (GREY8) image. Use T4 two-dimensional compression.
.TP .TP
.B -h .B -h
Use Huffman compression. Use Huffman compression.
.TP .TP
.B -H .B -k
Use T4 one-dimensional compression. Convert the image to a GREY8 grey-scale image.
.TP .TP
.B -l .B -l
Use LZW compression. Use LZW compression.
.TP .TP
.B -L .B -L
Use LZW compression with horizontal differencing. Use LZW compression with horizontal differencing.
Note that some TIFF decoders may not accept horizontal Some TIFF decoders may not support horizontal
differencing applied to images with depths less than eight. differencing applied to images of depths less than eight.
.TP
.B -m
Output a color (CMAP8) image.
.TP .TP
.B -p .B -p
Use Packbits compression. Use Packbits compression.
.TP .TP
.B -r
Output a color (BGR24) image.
.TP
.B -t .B -t
Use T4 two-dimensional compression.
.TP
.B -T
Use T6 compression. Use T6 compression.
.TP
.B -v
Convert the image to an RGBV color-mapped image.
.TP
.B -y
Convert the image to a GREY2 grey-scale image.
.I Totif
will then convert it to GREY4 before encoding
because TIFF does not support depths of two.
.TP
.B -Y
Convert the image to a GREY4 grey-scale image.
.PP .PP
If there is only one input picture, If there is only one input picture,
.I togif .I togif

View file

@ -9,7 +9,7 @@
void void
usage(void) usage(void)
{ {
fprint(2, "usage: %s [-c 'comment'] [-gs] [file]\n", argv0); fprint(2, "usage: %s [-c 'comment'] [-ks] [file]\n", argv0);
exits("usage"); exits("usage");
} }
@ -18,17 +18,17 @@ main(int argc, char *argv[])
{ {
Biobuf bout; Biobuf bout;
Memimage *i, *ni; Memimage *i, *ni;
int fd, gflag, sflag; int fd, kflag, sflag;
char *err, *file, *com; char *err, *file, *com;
gflag = sflag = 0; kflag = sflag = 0;
com = nil; com = nil;
ARGBEGIN { ARGBEGIN {
case 'c': case 'c':
com = EARGF(usage()); com = EARGF(usage());
break; break;
case 'g': case 'k':
gflag = 1; kflag = 1;
break; break;
case 's': case 's':
sflag = 1; sflag = 1;
@ -61,7 +61,7 @@ main(int argc, char *argv[])
freememimage(i); freememimage(i);
i = ni; i = ni;
} }
err = memwritejpg(&bout, i, com, gflag, sflag); err = memwritejpg(&bout, i, com, kflag, sflag);
freememimage(i); freememimage(i);
if(err != nil) if(err != nil)

View file

@ -11,7 +11,7 @@ void
usage(void) usage(void)
{ {
fprint(2, "usage: %s [-c 'comment'] " fprint(2, "usage: %s [-c 'comment'] "
"[-bBgGhHlLmprtT] [file]\n", argv0); "[-3bgGhklLptvyY] [file]\n", argv0);
exits("usage"); exits("usage");
} }
@ -29,31 +29,31 @@ main(int argc, char *argv[])
comp = 1; comp = 1;
c = nil; c = nil;
ARGBEGIN { ARGBEGIN {
case 'b': case '3': /* force RGB */
chan = GREY1; chan = BGR24;
chanflag = 1; chanflag = 1;
break; break;
case 'B': case 'b':
chan = GREY2; chan = GREY1;
chanflag = 1; chanflag = 1;
break; break;
case 'c': case 'c':
c = EARGF(usage()); c = EARGF(usage());
break; break;
case 'g': case 'g': /* t4 */
chan = GREY4; comp = 3;
chanflag = 1; opt = 0;
break; break;
case 'G': case 'G': /* t4 two-dimensional */
chan = GREY8; comp = 3;
chanflag = 1; opt = 1;
break; break;
case 'h': /* huffman */ case 'h': /* huffman */
comp = 2; comp = 2;
break; break;
case 'H': /* t4 */ case 'k':
comp = 3; chan = GREY8;
opt = 0; chanflag = 1;
break; break;
case 'l': /* lzw */ case 'l': /* lzw */
comp = 5; comp = 5;
@ -63,23 +63,23 @@ main(int argc, char *argv[])
comp = 5; comp = 5;
opt = 1; opt = 1;
break; break;
case 'm': /* palette */
chan = CMAP8;
chanflag = 1;
break;
case 'p': /* packbits */ case 'p': /* packbits */
comp = 0x8005; comp = 0x8005;
break; break;
case 'r': /* force BGR24 */ case 't': /* t6 */
chan = BGR24; comp = 4;
break;
case 'v': /* RGBV */
chan = CMAP8;
chanflag = 1; chanflag = 1;
break; break;
case 't': /* t4 two-dimensional */ case 'y':
comp = 3; chan = GREY2;
opt = 1; chanflag = 1;
break; break;
case 'T': /* t6 */ case 'Y':
comp = 4; chan = GREY4;
chanflag = 1;
break; break;
default: default:
usage(); usage();

View file

@ -552,7 +552,7 @@ toycc2(int *y, int *cb, int *cr, int jx, int jy, int dx, int dy,
static char * static char *
encode(Biobuf *fd, Rectangle r, uchar *data, ulong chan, encode(Biobuf *fd, Rectangle r, uchar *data, ulong chan,
int ndata, int gflag, int sflag) int ndata, int kflag, int sflag)
{ {
int k, x, y, dx, dy, depth, bpl, ncomp; int k, x, y, dx, dy, depth, bpl, ncomp;
int b[3][64], pred[3]; int b[3][64], pred[3];
@ -587,7 +587,7 @@ encode(Biobuf *fd, Rectangle r, uchar *data, ulong chan,
dy = min(Dy(r), 0xffff); dy = min(Dy(r), 0xffff);
depth = chantodepth(chan); depth = chantodepth(chan);
bpl = bytesperline(r, depth); bpl = bytesperline(r, depth);
ncomp = gflag? 1: 3; ncomp = kflag? 1: 3;
memset(pred, 0, sizeof pred); memset(pred, 0, sizeof pred);
for(x = 0, y = 0;;) { for(x = 0, y = 0;;) {
err = (*toycc)(b[0], b[1], b[2], x, y, dx, dy, err = (*toycc)(b[0], b[1], b[2], x, y, dx, dy,
@ -733,11 +733,11 @@ writehuffman(Biobuf *fd, int tc, int th)
} }
static void static void
writeframe(Biobuf *fd, int y, int x, int gflag) writeframe(Biobuf *fd, int y, int x, int kflag)
{ {
int n, nf; int n, nf;
nf = gflag? 0x01: 0x03; nf = kflag? 0x01: 0x03;
n = 0x0008 + 0x0003*nf; n = 0x0008 + 0x0003*nf;
Bputs(fd, 0xffc0); Bputs(fd, 0xffc0);
@ -752,7 +752,7 @@ writeframe(Biobuf *fd, int y, int x, int gflag)
Bputc(fd, (0x1<<4)|0x1); Bputc(fd, (0x1<<4)|0x1);
Bputc(fd, 0x00); Bputc(fd, 0x00);
if(!gflag) { if(!kflag) {
/* Cb component */ /* Cb component */
Bputc(fd, 0x01); Bputc(fd, 0x01);
Bputc(fd, (0x1<<4)|0x1); Bputc(fd, (0x1<<4)|0x1);
@ -766,11 +766,11 @@ writeframe(Biobuf *fd, int y, int x, int gflag)
} }
static void static void
writescan(Biobuf *fd, int gflag) writescan(Biobuf *fd, int kflag)
{ {
int n, ns; int n, ns;
ns = gflag? 0x01: 0x03; ns = kflag? 0x01: 0x03;
n = 0x0006 + 0x0002*ns; n = 0x0006 + 0x0002*ns;
Bputs(fd, 0xffda); Bputs(fd, 0xffda);
@ -781,7 +781,7 @@ writescan(Biobuf *fd, int gflag)
Bputc(fd, 0x00); Bputc(fd, 0x00);
Bputc(fd, (0x0<<4)|0x0); Bputc(fd, (0x0<<4)|0x0);
if(!gflag) { if(!kflag) {
/* Cb component */ /* Cb component */
Bputc(fd, 0x01); Bputc(fd, 0x01);
Bputc(fd, (0x1<<4)|0x1); Bputc(fd, (0x1<<4)|0x1);
@ -797,7 +797,7 @@ writescan(Biobuf *fd, int gflag)
} }
static void static void
writeheader(Biobuf *fd, int dx, int dy, char *s, int gflag, int sflag) writeheader(Biobuf *fd, int dx, int dy, char *s, int kflag, int sflag)
{ {
int i; int i;
@ -808,15 +808,15 @@ writeheader(Biobuf *fd, int dx, int dy, char *s, int gflag, int sflag)
writejfif(fd, dx, dy); writejfif(fd, dx, dy);
writecomment(fd, s); writecomment(fd, s);
writequant(fd, 0, sflag); writequant(fd, 0, sflag);
if(!gflag) if(!kflag)
writequant(fd, 1, sflag); writequant(fd, 1, sflag);
writeframe(fd, dy, dx, gflag); writeframe(fd, dy, dx, kflag);
for(i = 0; i < 2; i++) { for(i = 0; i < 2; i++) {
writehuffman(fd, i, 0); writehuffman(fd, i, 0);
if(!gflag) if(!kflag)
writehuffman(fd, i, 1); writehuffman(fd, i, 1);
} }
writescan(fd, gflag); writescan(fd, kflag);
} }
static void static void
@ -826,7 +826,7 @@ writetrailer(Biobuf *fd)
} }
static char * static char *
writedata(Biobuf *fd, Image *i, Memimage *m, int gflag, int sflag) writedata(Biobuf *fd, Image *i, Memimage *m, int kflag, int sflag)
{ {
char *err; char *err;
uchar *data; uchar *data;
@ -862,14 +862,14 @@ writedata(Biobuf *fd, Image *i, Memimage *m, int gflag, int sflag)
} }
snprint(err, ERRMAX, "WriteJPG: %r"); snprint(err, ERRMAX, "WriteJPG: %r");
} else } else
err = encode(fd, r, data, chan, ndata, gflag, sflag); err = encode(fd, r, data, chan, ndata, kflag, sflag);
free(data); free(data);
return err; return err;
} }
static char * static char *
writejpg0(Biobuf *fd, Image *image, Memimage *memimage, writejpg0(Biobuf *fd, Image *image, Memimage *memimage,
Rectangle r, ulong chan, char *s, int gflag, int sflag) Rectangle r, ulong chan, char *s, int kflag, int sflag)
{ {
int i; int i;
char *err; char *err;
@ -879,7 +879,7 @@ writejpg0(Biobuf *fd, Image *image, Memimage *memimage,
case GREY2: case GREY2:
case GREY4: case GREY4:
case GREY8: case GREY8:
gflag = 1; kflag = 1;
break; break;
case RGB24: case RGB24:
break; break;
@ -896,20 +896,20 @@ writejpg0(Biobuf *fd, Image *image, Memimage *memimage,
makehuf(ehufcoa[i], ehufsia[i], acbits[i], makehuf(ehufcoa[i], ehufsia[i], acbits[i],
achuffval[i], nelem(achuffval[i])); achuffval[i], nelem(achuffval[i]));
} }
writeheader(fd, Dx(r), Dy(r), s, gflag, sflag); writeheader(fd, Dx(r), Dy(r), s, kflag, sflag);
err = writedata(fd, image, memimage, gflag, sflag); err = writedata(fd, image, memimage, kflag, sflag);
writetrailer(fd); writetrailer(fd);
return err; return err;
} }
char * char *
writejpg(Biobuf *fd, Image *i, char *s, int gflag, int sflag) writejpg(Biobuf *fd, Image *i, char *s, int kflag, int sflag)
{ {
return writejpg0(fd, i, nil, i->r, i->chan, s, gflag, sflag); return writejpg0(fd, i, nil, i->r, i->chan, s, kflag, sflag);
} }
char * char *
memwritejpg(Biobuf *fd, Memimage *m, char *s, int gflag, int sflag) memwritejpg(Biobuf *fd, Memimage *m, char *s, int kflag, int sflag)
{ {
return writejpg0(fd, nil, m, m->r, m->chan, s, gflag, sflag); return writejpg0(fd, nil, m, m->r, m->chan, s, kflag, sflag);
} }