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
This commit is contained in:
Manolo Gouy 2015-02-07 05:52:38 +00:00
parent 6cf13f1308
commit ff316fa357
2 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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 :