summaryrefslogtreecommitdiff
path: root/src/Fl_PNM_Image.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2015-02-07 05:52:38 +0000
committerManolo Gouy <Manolo>2015-02-07 05:52:38 +0000
commitff316fa357e5c88a34ba574bd2a7ddef62eeb263 (patch)
tree3e61adb13bc14b5e240d22c8e93bd66ea64299ed /src/Fl_PNM_Image.cxx
parent6cf13f13084c0b246399d6f77d4ea95e4617df72 (diff)
Fixed reading of .pbm image files: the black & white pixels were reversed,
and P4-formatted files of width a multiple of 8 were handled incorrectly. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10558 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_PNM_Image.cxx')
-rw-r--r--src/Fl_PNM_Image.cxx24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Fl_PNM_Image.cxx b/src/Fl_PNM_Image.cxx
index bfd97d65d..c4a65076f 100644
--- a/src/Fl_PNM_Image.cxx
+++ b/src/Fl_PNM_Image.cxx
@@ -133,6 +133,10 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
switch (format) {
case 1 :
+ for (x = w(); x > 0; x --)
+ if (fscanf(fp, "%d", &val) == 1) *ptr++ = (uchar)(255 * (1-val));
+ break;
+
case 2 :
for (x = w(); x > 0; x --)
if (fscanf(fp, "%d", &val) == 1) *ptr++ = (uchar)(255 * val / maxval);
@@ -147,17 +151,17 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
break;
case 4 :
- for (x = w(), byte = (uchar)getc(fp), bit = 128; x > 0; x --) {
- if (byte & bit) *ptr++ = 255;
- else *ptr++ = 0;
-
- if (bit > 1) bit >>= 1;
- else {
- bit = 128;
- byte = (uchar)getc(fp);
- }
+ for (x = w(), byte = (uchar)getc(fp), bit = 128; x > 0; x --) {
+ if ((byte & bit) == 0) *ptr++ = 255; // 0 bit for white pixel
+ else *ptr++ = 0; // 1 bit for black pixel
+
+ if (bit > 1) bit >>= 1;
+ else {
+ bit = 128;
+ if (x > 1) byte = (uchar)getc(fp);
}
- break;
+ }
+ break;
case 5 :
case 6 :