From ff316fa357e5c88a34ba574bd2a7ddef62eeb263 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Sat, 7 Feb 2015 05:52:38 +0000 Subject: 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 --- src/Fl_PNM_Image.cxx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Fl_PNM_Image.cxx') 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 : -- cgit v1.2.3