51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
54
// $Id: GPixmap.cpp,v 1.12 2004/08/06 15:11:29 leonb Exp $
55
// $Name: debian_version_3_5_16-1 $
54
// $Id: GPixmap.cpp,v 1.14 2006/04/17 20:09:27 leonb Exp $
55
// $Name: debian_version_3_5_17-1 $
57
57
#ifdef HAVE_CONFIG_H
58
58
# include "config.h"
463
463
GPixmap::init(ByteStream &bs)
468
magic[0] = magic[1] = 0;
469
bs.readall((void*)magic, sizeof(magic));
470
if (magic[0]=='P' && magic[1]=='3')
473
}else if (magic[0]=='P' && magic[1]=='6')
468
int magic = bs.read16();
478
482
#ifdef NEED_JPEG_DECODER
480
JPEGDecoder::decode(bs,*this);
482
#else // NEED_JPEG_DECODER
484
G_THROW( ERR_MSG("GPixmap.unk_PPM") );
485
#endif // NEED_JPEG_DECODER
484
JPEGDecoder::decode(bs,*this);
488
G_THROW( ERR_MSG("GPixmap.unk_PPM") );
487
491
// Read image size
488
492
char lookahead = '\n';
489
493
int acolumns = read_integer(lookahead, bs);
493
497
G_THROW("Cannot read PPM with depth greater than 24 bits.");
494
498
init(arows, acolumns, 0);
495
499
// Read image data
498
GTArray<unsigned char> line(ncolumns*3);
499
for (int y=nrows-1; y>=0; y--)
501
GPixel *p = (*this)[y];
502
unsigned char *rgb = &line[0];
503
if ( bs.readall((void*)rgb, ncolumns*3) < (size_t)(ncolumns*3))
504
G_THROW( ByteStream::EndOfFile );
505
for (int x=0; x<ncolumns; x+=1, rgb+=3)
502
GTArray<unsigned char> line(ncolumns);
503
for (int y=nrows-1; y>=0; y--)
505
GPixel *p = (*this)[y];
506
unsigned char *g = &line[0];
507
if ( bs.readall((void*)g, ncolumns) < (size_t)(ncolumns))
508
G_THROW( ByteStream::EndOfFile );
509
for (int x=0; x<ncolumns; x+=1, g+=1)
510
p[x].r = p[x].g = p[x].b = g[0];
515
GTArray<unsigned char> line(ncolumns*3);
516
for (int y=nrows-1; y>=0; y--)
518
GPixel *p = (*this)[y];
519
unsigned char *rgb = &line[0];
520
if ( bs.readall((void*)rgb, ncolumns*3) < (size_t)(ncolumns*3))
521
G_THROW( ByteStream::EndOfFile );
522
for (int x=0; x<ncolumns; x+=1, rgb+=3)
515
for (int y=nrows-1; y>=0; y--)
517
GPixel *p = (*this)[y];
518
for (int x=0; x<ncolumns; x++)
520
p[x].r = read_integer(lookahead, bs);
521
p[x].g = read_integer(lookahead, bs);
522
p[x].b = read_integer(lookahead, bs);
532
for (int y=nrows-1; y>=0; y--)
534
GPixel *p = (*this)[y];
535
for (int x=0; x<ncolumns; x++)
538
p[x].g = p[x].b = p[x].r = read_integer(lookahead, bs);
542
p[x].r = read_integer(lookahead, bs);
543
p[x].g = read_integer(lookahead, bs);
544
p[x].b = read_integer(lookahead, bs);
526
548
// Process small values of maxval
527
549
if (maxval>0 && maxval<255)
530
for (int i=0; i<256; i++)
531
table[i] = (i<maxval ? (255*i + maxval/2) / maxval : 255);
532
for (int y=0; y<nrows; y++)
534
GPixel *p = (*this)[y];
535
for (int x=0; x<ncolumns; x++)
537
p[x].r = table[p[x].r];
538
p[x].g = table[p[x].g];
539
p[x].b = table[p[x].b];
552
for (int i=0; i<256; i++)
553
table[i] = (i<maxval ? (255*i + maxval/2) / maxval : 255);
554
for (int y=0; y<nrows; y++)
556
GPixel *p = (*this)[y];
557
for (int x=0; x<ncolumns; x++)
559
p[x].r = table[p[x].r];
560
p[x].g = table[p[x].g];
561
p[x].b = table[p[x].b];