mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
wrlib: Improved NETPBM support
- re-add PPM to the list of supported format, because legacy apps may expect to find it from the list; - add the copyright notice related to the code that have been borrowed from Netpbm; - fixed a small error in PPM format check in the loading procedure; - and a few minor code improvements Signed-off-by: Christophe CURIS <christophe.curis@free.fr> Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
051a30f550
commit
34ca63c59f
@@ -73,13 +73,19 @@ static WRImgFormat identFile(const char *path);
|
|||||||
|
|
||||||
char **RSupportedFileFormats(void)
|
char **RSupportedFileFormats(void)
|
||||||
{
|
{
|
||||||
static char *tmp[IM_TYPES + 1];
|
static char *tmp[IM_TYPES + 2];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
/* built-in */
|
/* built-in */
|
||||||
tmp[i++] = "XPM";
|
tmp[i++] = "XPM";
|
||||||
/* built-in PNM here refers to anymap format: PPM, PGM, PBM */
|
/* built-in PNM here refers to anymap format: PPM, PGM, PBM */
|
||||||
tmp[i++] = "PNM";
|
tmp[i++] = "PNM";
|
||||||
|
/*
|
||||||
|
* PPM is a just a sub-type of PNM, but it has to be in the list
|
||||||
|
* for compatibility with legacy programs that may expect it but
|
||||||
|
* not the new PNM type
|
||||||
|
*/
|
||||||
|
tmp[i++] = "PPM";
|
||||||
#ifdef USE_TIFF
|
#ifdef USE_TIFF
|
||||||
tmp[i++] = "TIFF";
|
tmp[i++] = "TIFF";
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,10 +32,18 @@
|
|||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
|
|
||||||
/* fileio.c - routines to read elements based on Netpbm
|
/*
|
||||||
**
|
* fileio.c - routines to read elements based on Netpbm
|
||||||
** Copyright (C) 1988 by Jef Poskanzer.
|
*
|
||||||
*/
|
* Copyright (C) 1988 by Jef Poskanzer.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
|
* documentation for any purpose and without fee is hereby granted, provided
|
||||||
|
* that the above copyright notice appear in all copies and that both that
|
||||||
|
* copyright notice and this permission notice appear in supporting
|
||||||
|
* documentation. This software is provided "as is" without express or
|
||||||
|
* implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
char pm_getc(FILE * const fileP)
|
char pm_getc(FILE * const fileP)
|
||||||
{
|
{
|
||||||
@@ -103,6 +111,7 @@ int pm_getuint(FILE * const ifP)
|
|||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
/* end of fileio.c re-used code */
|
||||||
/******************************************************************************************/
|
/******************************************************************************************/
|
||||||
|
|
||||||
/* PGM: support for portable graymap ascii and binary encoding */
|
/* PGM: support for portable graymap ascii and binary encoding */
|
||||||
@@ -127,6 +136,7 @@ static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
|||||||
ptr = image->data;
|
ptr = image->data;
|
||||||
if (raw == '2') {
|
if (raw == '2') {
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
val = pm_getuint(file);
|
val = pm_getuint(file);
|
||||||
@@ -146,6 +156,7 @@ static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
|||||||
} else {
|
} else {
|
||||||
if (raw == '5') {
|
if (raw == '5') {
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
buf = malloc(w + 1);
|
buf = malloc(w + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
@@ -177,8 +188,8 @@ static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
|||||||
static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
||||||
{
|
{
|
||||||
RImage *image;
|
RImage *image;
|
||||||
|
int i;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (raw != '3' && raw != '6') {
|
if (raw != '3' && raw != '6') {
|
||||||
RErrorCode = RERR_BADFORMAT;
|
RErrorCode = RERR_BADFORMAT;
|
||||||
@@ -195,6 +206,7 @@ static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
|||||||
if (max < 256) {
|
if (max < 256) {
|
||||||
if (raw == '3') {
|
if (raw == '3') {
|
||||||
int x, y, val;
|
int x, y, val;
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
@@ -213,6 +225,8 @@ static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
|||||||
}
|
}
|
||||||
} else if (raw == '6') {
|
} else if (raw == '6') {
|
||||||
char buf[3];
|
char buf[3];
|
||||||
|
|
||||||
|
i = 0;
|
||||||
while (i < w * h) {
|
while (i < w * h) {
|
||||||
if (fread(buf, 1, 3, file) != 3) {
|
if (fread(buf, 1, 3, file) != 3) {
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
@@ -251,6 +265,7 @@ static RImage *load_bitmap(FILE * file, int w, int h, int max, int raw)
|
|||||||
ptr = image->data;
|
ptr = image->data;
|
||||||
if (raw == '1') {
|
if (raw == '1') {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < w * h) {
|
while (i < w * h) {
|
||||||
val = pm_getuint(file);
|
val = pm_getuint(file);
|
||||||
|
|
||||||
@@ -314,7 +329,7 @@ RImage *RLoadPPM(const char *file_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* accept bitmaps, pixmaps or graymaps */
|
/* accept bitmaps, pixmaps or graymaps */
|
||||||
if (buffer[0] != 'P' || (buffer[1] < '1' && buffer[1] > '6')) {
|
if (buffer[0] != 'P' || (buffer[1] < '1' || buffer[1] > '6')) {
|
||||||
RErrorCode = RERR_BADFORMAT;
|
RErrorCode = RERR_BADFORMAT;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -359,16 +374,14 @@ RImage *RLoadPPM(const char *file_name)
|
|||||||
m = 1;
|
m = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check portable bitmap type, ascii = 1 and binary = 4 */
|
if (type == '1' || type == '4') {
|
||||||
if (type == '1' || type == '4')
|
/* Portable Bit Map: P1 is for 'plain' (ascii, rare), P4 for 'regular' (binary) */
|
||||||
image = load_bitmap(file, w, h, m, type);
|
image = load_bitmap(file, w, h, m, type);
|
||||||
else {
|
} else if (type == '2' || type == '5') {
|
||||||
/* check portable graymap type, ascii = 2 and binary = 5 */
|
/* Portable Gray Map: P2 is for 'plain' (ascii, rare), P5 for 'regular' (binary) */
|
||||||
if (type == '2' || type == '5')
|
|
||||||
image = load_graymap(file, w, h, m, type);
|
image = load_graymap(file, w, h, m, type);
|
||||||
else
|
} else if (type == '3' || type == '6') {
|
||||||
/* check portable pixmap type, ascii = 3 and binary = 6 */
|
/* Portable Pix Map: P3 is for 'plain' (ascii, rare), P6 for 'regular' (binary) */
|
||||||
if (type == '3' || type == '6')
|
|
||||||
image = load_pixmap(file, w, h, m, type);
|
image = load_pixmap(file, w, h, m, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user