gdk_pixbuf bug in reading of pnm files



I have found that the PNM filter of gdk-pixbuf fails to read pnm files
that have a white space character as the first byte of its pixel data.
The reason for this is that the spec of the PNM is quite slack.
According  to the definition a P[GP]M file looks like

P[56]<ws>
# comments
<ws>width<ws>height<ws>255<WS><... width * width (*3) bytes of pixel data...>

where <ws> stands for one or more white space characters. The problem
is what happens at <WS>. If <WS> is the same as <ws> then it is not
possible to have a white space character as the first bytes of pixel
data. The only way of solving this by assuming that <WS> is always be one
byte long.

The following patch should (hopefully) fix this.

Regards,
Dov

*** io-pnm.c.old        Sun Jan 28 13:39:30 2001
--- io-pnm.c    Sun Jan 28 13:33:20 2001
***************
*** 206,211 ****
--- 206,230 ----
          return PNM_SUSPEND;
  }
  
+ /* skip over a given number of bytes */
+ static gint
+ pnm_skip_n_bytes (PnmIOBuffer *inbuf, int n_bytes)
+ {
+         g_return_val_if_fail (inbuf != NULL, PNM_FATAL_ERR);
+         g_return_val_if_fail (inbuf->byte != NULL, PNM_FATAL_ERR);
+ 
+       if (n_bytes < inbuf->nbytes) {
+               inbuf->byte = inbuf->byte + n_bytes;
+               inbuf->nbytes-= nbytes;
+               return PNM_OK;
+       }
+ 
+       inbuf->byte = inbuf->byte + inbuf->nbytes;
+       inbuf->n_bytes = 0;
+ 
+       return PNM_SUSPEND;
+ }
+ 
  /* read next number from buffer */
  static gint
  pnm_read_next_value (PnmIOBuffer *inbuf, guint *value)
***************
*** 647,653 ****
                  
                  /* scan until we hit image data */
                  if (!context.did_prescan) {
!                         retval = pnm_skip_whitespace (inbuf);
                          if (retval == PNM_FATAL_ERR)
                                  return NULL;
                          else if (retval == PNM_SUSPEND)
--- 666,672 ----
                  
                  /* scan until we hit image data */
                  if (!context.did_prescan) {
!                         retval = pnm_skip_n_bytes (inbuf,1);
                          if (retval == PNM_FATAL_ERR)
                                  return NULL;
                          else if (retval == PNM_SUSPEND)
***************
*** 811,817 ****
                  
                  /* scan until we hit image data */
                  if (!context->did_prescan) {
!                         retval = pnm_skip_whitespace (inbuf);
                          
                          if (retval == PNM_FATAL_ERR)
                                  return FALSE;
--- 830,836 ----
                  
                  /* scan until we hit image data */
                  if (!context->did_prescan) {
!                         retval = pnm_skip_n_bytes (inbuf, 1);
                          
                          if (retval == PNM_FATAL_ERR)
                                  return FALSE;




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]