Logo Search packages:      
Sourcecode: djvulibre version File versions

void GPixmap::save_ppm ( ByteStream bs,
int  raw = 1 
) const

Saves the image into ByteStream bs# using the PPM format. Argument raw# selects the ``Raw PPM'' (1) or the ``Ascii PPM'' (0) format. See {PNM and RLE file formats} for more information.

Definition at line 585 of file GPixmap.cpp.

References GPixel::b, GUTF8String::format(), GPixel::g, GBaseString::length(), GPixel::r, rowsize(), ByteStream::writall(), and ByteStream::write().

{
  GUTF8String head;
  head.format("P%c\n%d %d\n255\n", (raw ? '6' : '3'), ncolumns, nrows);
  bs.writall((void*)(const char *)head, head.length());
  if (raw)
    {
      int rowsize = ncolumns+ncolumns+ncolumns;
      GTArray<unsigned char> xrgb(rowsize);
      for (int y=nrows-1; y>=0; y--) 
        {
          const GPixel *p = (*this)[y];
          unsigned char *d = xrgb;
          for (int x=0; x<ncolumns; x++) 
            {
              *d++ = p[x].r;
              *d++ = p[x].g;
              *d++ = p[x].b;
            }
          bs.writall((void*)(unsigned char*)xrgb, ncolumns * 3);
        }
    }
  else
    {
      for (int y=nrows-1; y>=0; y--) 
        {
          const GPixel *p = (*this)[y];
          unsigned char eol='\n';
          for (int x=0; x<ncolumns; )
            {
              head.format("%d %d %d  ", p[x].r, p[x].g, p[x].b);
              bs.writall((void*)(const char *)head, head.length());
              x += 1;
              if (x==ncolumns || (x&0x7)==0) 
                bs.write((void*)&eol, 1);          
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index