diff --git a/CHANGES b/CHANGES index 93fbd6616..eef617f25 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ CHANGES IN FLTK 1.3.4 RELEASED: ??? ?? ???? or not (STR #3142). It also captures subwindows of GL windows. - Fl::delete_widget() now hides the widget or window immediately (i.e. when called) - only destruction is delayed as before. + - Reading of .pbm image files is fixed: 1 is now interpreted as + black, and images of width a multiple of 8 are correctly read. CHANGES IN FLTK 1.3.3 RELEASED: Nov 03 2014 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 :