diff --git a/src/modules/Image/encodings/Makefile.in b/src/modules/Image/encodings/Makefile.in
index b703516f04327bfd7467dee0564b61f0826efd0d..30c35949c08b5deecb95acc986ecfe24804d4ab0 100644
--- a/src/modules/Image/encodings/Makefile.in
+++ b/src/modules/Image/encodings/Makefile.in
@@ -4,7 +4,7 @@ GIF_OBJS = gif.o gif_lzw.o png.o
 JPEG_OBJS = jpeg.o
 PNG_OBJS = png.o
 PNM_OBJS = pnm.o 
-OBJS=gif.a pnm.a
+OBJS=gif.a pnm.a png.a
 
 @SET_MAKE@
 
diff --git a/src/modules/Image/encodings/pnm.c b/src/modules/Image/encodings/pnm.c
index 88d3891aceb195b61e9033d899b30a4eada54a8c..c3a200c7ab0fc8b713f5fe224343869cf3850537 100644
--- a/src/modules/Image/encodings/pnm.c
+++ b/src/modules/Image/encodings/pnm.c
@@ -1,9 +1,9 @@
-/* $Id: pnm.c,v 1.3 1997/11/10 14:19:58 mirar Exp $ */
+/* $Id: pnm.c,v 1.4 1997/11/20 22:26:58 mirar Exp $ */
 
 /*
 **! module Image
 **! note
-**!	$Id: pnm.c,v 1.3 1997/11/10 14:19:58 mirar Exp $
+**!	$Id: pnm.c,v 1.4 1997/11/20 22:26:58 mirar Exp $
 **! submodule PNM
 **!
 **!	This submodule keep the PNM encode/decode capabilities
@@ -49,7 +49,7 @@
 
 #include "stralloc.h"
 #include "global.h"
-RCSID("$Id: pnm.c,v 1.3 1997/11/10 14:19:58 mirar Exp $");
+RCSID("$Id: pnm.c,v 1.4 1997/11/20 22:26:58 mirar Exp $");
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"
@@ -127,7 +127,7 @@ static INLINE INT32 getnextnum(struct pike_string *s,INT32 *pos)
 void img_pnm_decode(INT32 args)
 {
    INT32 type,c=0,maxval=255;
-   INT32 pos=0,x,y,i,n;
+   INT32 pos=0,x,y,i,n,nx;
    struct object *o;
    struct image *new;
    rgb_group *d;
@@ -174,6 +174,10 @@ void img_pnm_decode(INT32 args)
    n=x*y;
    i=0;
 
+   nx=x;
+
+   if (type=='6' && maxval==255) type='+';
+
    while (n--)
    {
       switch (type)
@@ -199,6 +203,7 @@ void img_pnm_decode(INT32 args)
 	       (unsigned char)~(((c>>7)&1)*255);
 	    c<<=1;
 	    i--;
+	    if (!--nx) { i=0; nx=x; } /* pbm; last byte on row is padded */
 	    break;
 	 case '5':
 	    c=getnext(s,&pos);
@@ -210,6 +215,11 @@ void img_pnm_decode(INT32 args)
 	    d->g=(unsigned char)((((INT32)getnext(s,&pos))*255L)/maxval);
 	    d->b=(unsigned char)((((INT32)getnext(s,&pos))*255L)/maxval);
 	    break;
+	 case '+': /* optimized P6 */
+	    d->r=getnext(s,&pos);
+	    d->g=getnext(s,&pos);
+	    d->b=getnext(s,&pos);
+	    break;
       }
       d++;
    }