~ubuntu-branches/ubuntu/edgy/djvulibre/edgy

« back to all changes in this revision

Viewing changes to libdjvu/GPixmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-07-03 11:38:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113823-un2te7742kk04c63
Tags: 3.5.17-1ubuntu1
* Sync with Debian
* debian/rules:
  - use dh_iconcache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
53
53
// 
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 $
56
56
 
57
57
#ifdef HAVE_CONFIG_H
58
58
# include "config.h"
463
463
GPixmap::init(ByteStream &bs)
464
464
{
465
465
  // Read header
466
 
  int raw = 0;
467
 
  char magic[2];
468
 
  magic[0] = magic[1] = 0;
469
 
  bs.readall((void*)magic, sizeof(magic));
470
 
  if (magic[0]=='P' && magic[1]=='3')
471
 
  {
472
 
    raw = 0;
473
 
  }else if (magic[0]=='P' && magic[1]=='6')
474
 
  {
475
 
    raw = 1;
476
 
  }else
477
 
  {
 
466
  bool raw = false;
 
467
  bool grey = false;
 
468
  int magic = bs.read16();
 
469
  switch (magic)
 
470
    {
 
471
    case ('P'<<8)+'2':
 
472
      grey = true;
 
473
      break;
 
474
    case ('P'<<8)+'3':
 
475
      break;
 
476
    case ('P'<<8)+'5':
 
477
      raw = grey = true;
 
478
    case ('P'<<8)+'6':
 
479
      raw = true;
 
480
      break;
 
481
    default:
478
482
#ifdef NEED_JPEG_DECODER
479
 
    bs.seek(0L);
480
 
    JPEGDecoder::decode(bs,*this);
481
 
    return;
482
 
#else // NEED_JPEG_DECODER
483
 
  
484
 
    G_THROW( ERR_MSG("GPixmap.unk_PPM") );
485
 
#endif // NEED_JPEG_DECODER
486
 
  }
 
483
      bs.seek(0L);
 
484
      JPEGDecoder::decode(bs,*this);
 
485
      return;
 
486
#else
 
487
      
 
488
      G_THROW( ERR_MSG("GPixmap.unk_PPM") );
 
489
#endif
 
490
    }
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
496
 
  if (raw)
497
 
  {
498
 
    GTArray<unsigned char> line(ncolumns*3);
499
 
    for (int y=nrows-1; y>=0; y--) 
500
 
      {
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)
506
 
          {
507
 
            p[x].r = rgb[0];
508
 
            p[x].g = rgb[1];
509
 
            p[x].b = rgb[2];
510
 
          }
511
 
      }
512
 
  }
 
500
  if (raw && grey)
 
501
    {
 
502
      GTArray<unsigned char> line(ncolumns);
 
503
      for (int y=nrows-1; y>=0; y--) 
 
504
        {
 
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];
 
511
        }
 
512
    }
 
513
  else if (raw)
 
514
    {
 
515
      GTArray<unsigned char> line(ncolumns*3);
 
516
      for (int y=nrows-1; y>=0; y--) 
 
517
        {
 
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)
 
523
            {
 
524
              p[x].r = rgb[0];
 
525
              p[x].g = rgb[1];
 
526
              p[x].b = rgb[2];
 
527
            }
 
528
        }
 
529
    }
513
530
  else
514
 
  {
515
 
    for (int y=nrows-1; y>=0; y--) 
516
531
    {
517
 
      GPixel *p = (*this)[y];
518
 
      for (int x=0; x<ncolumns; x++)
519
 
      {
520
 
        p[x].r = read_integer(lookahead, bs);
521
 
        p[x].g = read_integer(lookahead, bs);
522
 
        p[x].b = read_integer(lookahead, bs);
523
 
      }
 
532
      for (int y=nrows-1; y>=0; y--) 
 
533
        {
 
534
          GPixel *p = (*this)[y];
 
535
          for (int x=0; x<ncolumns; x++)
 
536
            if (grey)
 
537
              {
 
538
                p[x].g = p[x].b = p[x].r = read_integer(lookahead, bs);
 
539
              }
 
540
            else
 
541
              {
 
542
                p[x].r = read_integer(lookahead, bs);
 
543
                p[x].g = read_integer(lookahead, bs);
 
544
                p[x].b = read_integer(lookahead, bs);
 
545
              }
 
546
        }
524
547
    }
525
 
  }
526
548
  // Process small values of maxval
527
549
  if (maxval>0 && maxval<255)
528
 
  {
529
 
    char table[256];
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++)
533
550
    {
534
 
      GPixel *p = (*this)[y];
535
 
      for (int x=0; x<ncolumns; x++)
536
 
      {
537
 
        p[x].r = table[p[x].r];
538
 
        p[x].g = table[p[x].g];
539
 
        p[x].b = table[p[x].b];
540
 
      }
 
551
      char table[256];
 
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++)
 
555
        {
 
556
          GPixel *p = (*this)[y];
 
557
          for (int x=0; x<ncolumns; x++)
 
558
            {
 
559
              p[x].r = table[p[x].r];
 
560
              p[x].g = table[p[x].g];
 
561
              p[x].b = table[p[x].b];
 
562
            }
 
563
        }
541
564
    }
542
 
  }
543
565
}
544
566
 
545
567
 
1604
1626
GP<GPixmap> GPixmap::rotate(int count)
1605
1627
{
1606
1628
  GP<GPixmap> newpixmap(this);
1607
 
  if((count %= 4))
 
1629
  count = count & 3;
 
1630
  if(count)
1608
1631
  {
1609
1632
    if( count&0x01)
1610
1633
      newpixmap = new GPixmap(ncolumns, nrows);
1616
1639
    GMonitorLock lock(&pixmap_monitor());
1617
1640
    switch(count)
1618
1641
    {
1619
 
    case 1: //// rotate 90 counter clockwise
 
1642
    case 3: //// rotate 90 counter clockwise
1620
1643
        {
1621
1644
            int lastrow = dpixmap.rows()-1;
1622
1645
 
1646
1669
            }
1647
1670
        }
1648
1671
        break;
1649
 
    case 3: //// rotate 270 counter clockwise
 
1672
    case 1: //// rotate 270 counter clockwise
1650
1673
        {
1651
1674
            int lastcolumn = dpixmap.columns()-1;
1652
1675