summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2011-04-09 09:24:48 +0000
committerKim Woelders <kim@woelders.dk>2011-04-09 09:24:48 +0000
commitde93dc7e221c8346683f4aa6fa19a43d18a877a1 (patch)
tree530c4798e25a2a17a47d4b1b6e1543d644c6c1ad
parent41c3a967d03321166fb6194921dbdee3e31856e6 (diff)
downloadimlib2-de93dc7e221c8346683f4aa6fa19a43d18a877a1.tar.gz
Fix loading of .pbm's (P4) when width is not a multiple of 8.
SVN revision: 58519
-rw-r--r--src/modules/loaders/loader_pnm.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index afbee22..c4705fe 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -402,27 +402,59 @@ load(ImlibImage * im, ImlibProgressFunction progress,
}
break;
case '4': /* binary 1bit monochrome */
- data = malloc(1 * sizeof(DATA8));
+ data = malloc((w + 7) / 8 * sizeof(DATA8));
if (!data)
{
fclose(f);
return 0;
}
ptr2 = im->data;
- j = 0;
- while ((fread(data, 1, 1, f)) && (j < (w * h)))
+ for (y = 0; y < h; y++)
{
- for (i = 7; i >= 0; i--)
+ if (!fread(data, (w + 7) / 8, 1, f))
{
- if (j < (w * h))
+ free(data);
+ fclose(f);
+ return 0;
+ }
+ ptr = data;
+ for (x = 0; x < w; x += 8)
+ {
+ j = (w - x >= 8) ? 8 : w - x;
+ for (i = 0; i < j; i++)
{
- if (data[0] & (1 << i))
+ if (ptr[0] & (0x80 >> i))
*ptr2 = 0xff000000;
else
*ptr2 = 0xffffffff;
ptr2++;
}
- j++;
+ ptr++;
+ }
+ if (progress)
+ {
+ char per;
+ int l;
+
+ per = (char)((100 * y) / im->h);
+ if (((per - pper) >= progress_granularity)
+ || (y == (im->h - 1)))
+ {
+ l = y - pl;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ free(idata);
+ fclose(f);
+ return 2;
+ }
+ pper = per;
+ pl = y;
+ }
}
}
break;