mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
dwebp: add PAM output support
retains the alpha channel rather than stripping it as with PPM. display from ImageMagick can render the files Change-Id: I4f3a5d332937e0aeaf4e3fbd214fdae3b5382fb8
This commit is contained in:
parent
c3a207b9f4
commit
d919ed06eb
@ -59,6 +59,7 @@ extern void* VP8GetCPUInfo; // opaque forward declaration.
|
|||||||
// Output types
|
// Output types
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PNG = 0,
|
PNG = 0,
|
||||||
|
PAM,
|
||||||
PPM,
|
PPM,
|
||||||
PGM,
|
PGM,
|
||||||
ALPHA_PLANE_ONLY // this is for experimenting only
|
ALPHA_PLANE_ONLY // this is for experimenting only
|
||||||
@ -201,15 +202,22 @@ static int WritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int WritePPM(FILE* fout, const WebPDecBuffer* const buffer) {
|
static int WritePPM(FILE* fout, const WebPDecBuffer* const buffer, int alpha) {
|
||||||
const uint32_t width = buffer->width;
|
const uint32_t width = buffer->width;
|
||||||
const uint32_t height = buffer->height;
|
const uint32_t height = buffer->height;
|
||||||
const unsigned char* const rgb = buffer->u.RGBA.rgba;
|
const unsigned char* const rgb = buffer->u.RGBA.rgba;
|
||||||
const int stride = buffer->u.RGBA.stride;
|
const int stride = buffer->u.RGBA.stride;
|
||||||
|
const size_t bytes_per_px = alpha ? 4 : 3;
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
fprintf(fout, "P6\n%d %d\n255\n", width, height);
|
|
||||||
|
if (alpha) {
|
||||||
|
fprintf(fout, "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\n"
|
||||||
|
"TUPLTYPE RGB_ALPHA\nENDHDR\n", width, height);
|
||||||
|
} else {
|
||||||
|
fprintf(fout, "P6\n%d %d\n255\n", width, height);
|
||||||
|
}
|
||||||
for (y = 0; y < height; ++y) {
|
for (y = 0; y < height; ++y) {
|
||||||
if (fwrite(rgb + y * stride, width, 3, fout) != 3) {
|
if (fwrite(rgb + y * stride, width, bytes_per_px, fout) != bytes_per_px) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,8 +297,10 @@ static void SaveOutput(const WebPDecBuffer* const buffer,
|
|||||||
#else
|
#else
|
||||||
ok &= WritePNG(fout, buffer);
|
ok &= WritePNG(fout, buffer);
|
||||||
#endif
|
#endif
|
||||||
|
} else if (format == PAM) {
|
||||||
|
ok &= WritePPM(fout, buffer, 1);
|
||||||
} else if (format == PPM) {
|
} else if (format == PPM) {
|
||||||
ok &= WritePPM(fout, buffer);
|
ok &= WritePPM(fout, buffer, 0);
|
||||||
} else if (format == PGM) {
|
} else if (format == PGM) {
|
||||||
ok &= WritePGM(fout, buffer);
|
ok &= WritePGM(fout, buffer);
|
||||||
} else if (format == ALPHA_PLANE_ONLY) {
|
} else if (format == ALPHA_PLANE_ONLY) {
|
||||||
@ -314,7 +324,8 @@ static void Help(void) {
|
|||||||
printf("Usage: dwebp in_file [options] [-o out_file]\n\n"
|
printf("Usage: dwebp in_file [options] [-o out_file]\n\n"
|
||||||
"Decodes the WebP image file to PNG format [Default]\n"
|
"Decodes the WebP image file to PNG format [Default]\n"
|
||||||
"Use following options to convert into alternate image formats:\n"
|
"Use following options to convert into alternate image formats:\n"
|
||||||
" -ppm ......... save the raw RGB samples as color PPM\n"
|
" -pam ......... save the raw RGBA samples as a color PAM\n"
|
||||||
|
" -ppm ......... save the raw RGB samples as a color PPM\n"
|
||||||
" -pgm ......... save the raw YUV samples as a grayscale PGM\n"
|
" -pgm ......... save the raw YUV samples as a grayscale PGM\n"
|
||||||
" file with IMC4 layout.\n"
|
" file with IMC4 layout.\n"
|
||||||
" Other options are:\n"
|
" Other options are:\n"
|
||||||
@ -367,6 +378,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
config.options.no_fancy_upsampling = 1;
|
config.options.no_fancy_upsampling = 1;
|
||||||
} else if (!strcmp(argv[c], "-nofilter")) {
|
} else if (!strcmp(argv[c], "-nofilter")) {
|
||||||
config.options.bypass_filtering = 1;
|
config.options.bypass_filtering = 1;
|
||||||
|
} else if (!strcmp(argv[c], "-pam")) {
|
||||||
|
format = PAM;
|
||||||
} else if (!strcmp(argv[c], "-ppm")) {
|
} else if (!strcmp(argv[c], "-ppm")) {
|
||||||
format = PPM;
|
format = PPM;
|
||||||
} else if (!strcmp(argv[c], "-version")) {
|
} else if (!strcmp(argv[c], "-version")) {
|
||||||
@ -434,6 +447,9 @@ int main(int argc, const char *argv[]) {
|
|||||||
output_buffer->colorspace = bitstream->has_alpha ? MODE_RGBA : MODE_RGB;
|
output_buffer->colorspace = bitstream->has_alpha ? MODE_RGBA : MODE_RGB;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
case PAM:
|
||||||
|
output_buffer->colorspace = MODE_RGBA;
|
||||||
|
break;
|
||||||
case PPM:
|
case PPM:
|
||||||
output_buffer->colorspace = MODE_RGB; // drops alpha for PPM
|
output_buffer->colorspace = MODE_RGB; // drops alpha for PPM
|
||||||
break;
|
break;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.\" Hey, EMACS: -*- nroff -*-
|
.\" Hey, EMACS: -*- nroff -*-
|
||||||
.TH DWEBP 1 "January 24, 2012"
|
.TH DWEBP 1 "July 20, 2012"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dwebp \- decompress a WebP file to an image file
|
dwebp \- decompress a WebP file to an image file
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -11,7 +11,7 @@ This manual page documents the
|
|||||||
.B dwebp
|
.B dwebp
|
||||||
command.
|
command.
|
||||||
.PP
|
.PP
|
||||||
\fBdwebp\fP decompresses WebP files into PNG, PPM or PGM images.
|
\fBdwebp\fP decompresses WebP files into PNG, PAM, PPM or PGM images.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
The basic options are:
|
The basic options are:
|
||||||
.TP
|
.TP
|
||||||
@ -24,8 +24,11 @@ Print the version number (as major.minor.revision) and exit.
|
|||||||
.B \-o string
|
.B \-o string
|
||||||
Specify the name of the output file (as PNG format by default).
|
Specify the name of the output file (as PNG format by default).
|
||||||
.TP
|
.TP
|
||||||
|
.B \-pam
|
||||||
|
Change the output format to PAM (retains alpha).
|
||||||
|
.TP
|
||||||
.B \-ppm
|
.B \-ppm
|
||||||
Change the output format to PPM.
|
Change the output format to PPM (discards alpha).
|
||||||
.TP
|
.TP
|
||||||
.B \-pgm
|
.B \-pgm
|
||||||
Change the output format to PGM. The output consist of luma/chroma
|
Change the output format to PGM. The output consist of luma/chroma
|
||||||
|
Loading…
Reference in New Issue
Block a user