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

View file

@ -9,7 +9,7 @@
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");
}
@ -18,17 +18,17 @@ main(int argc, char *argv[])
{
Biobuf bout;
Memimage *i, *ni;
int fd, gflag, sflag;
int fd, kflag, sflag;
char *err, *file, *com;
gflag = sflag = 0;
kflag = sflag = 0;
com = nil;
ARGBEGIN {
case 'c':
com = EARGF(usage());
break;
case 'g':
gflag = 1;
case 'k':
kflag = 1;
break;
case 's':
sflag = 1;
@ -61,7 +61,7 @@ main(int argc, char *argv[])
freememimage(i);
i = ni;
}
err = memwritejpg(&bout, i, com, gflag, sflag);
err = memwritejpg(&bout, i, com, kflag, sflag);
freememimage(i);
if(err != nil)

View file

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

View file

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