~ubuntu-branches/ubuntu/hardy/libavg/hardy

« back to all changes in this revision

Viewing changes to src/graphics/Filtergrayscale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-02 20:07:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071002200726-yl1zq2ba1catr0z3
Tags: 0.7.0-2
* Remove the last patch because it is not needed anymore.
* Enable 'make check' during the build process.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
}
40
40
 
41
 
BitmapPtr FilterGrayscale::apply(BitmapPtr pBmpSrc) const
 
41
BitmapPtr FilterGrayscale::apply(BitmapPtr pBmpSrc) 
42
42
{
43
43
    PixelFormat PF = pBmpSrc->getPixelFormat();
44
44
    if (PF == I8) {
48
48
             pBmpSrc->getName()));
49
49
    unsigned char * pSrcLine = pBmpSrc->getPixels();
50
50
    unsigned char * pDestLine = pBmpDest->getPixels();
51
 
    for (int y = 0; y<pBmpDest->getSize().y; ++y) {
 
51
    IntPoint size = pBmpDest->getSize();
 
52
    int bpp = pBmpSrc->getBytesPerPixel();
 
53
    for (int y = 0; y<size.y; ++y) {
52
54
        unsigned char * pSrcPixel = pSrcLine;
53
55
        unsigned char * pDstPixel = pDestLine;
54
 
        for (int x = 0; x < pBmpDest->getSize().x; ++x) {
 
56
        for (int x = 0; x < size.x; ++x) {
55
57
            // For the coefficients used, see http://www.inforamp.net/~poynton/
56
58
            // Appoximations curtesy of libpng :-).
57
59
            if (PF == R8G8B8A8 || PF == R8G8B8X8 || PF == R8G8B8) {
58
60
                *pDstPixel = (unsigned char)((pSrcPixel[REDPOS]*54+
59
61
                        pSrcPixel[GREENPOS]*183+
60
62
                        pSrcPixel[BLUEPOS]*19)/256);
61
 
                pSrcPixel += pBmpSrc->getBytesPerPixel();
 
63
                pSrcPixel += bpp;
62
64
                ++pDstPixel;
63
65
            } else {
64
66
                *pDstPixel = (unsigned char)((pSrcPixel[BLUEPOS]*54+
65
67
                        pSrcPixel[GREENPOS]*183+
66
68
                        pSrcPixel[REDPOS]*19)/256);
67
 
                pSrcPixel += pBmpSrc->getBytesPerPixel();
 
69
                pSrcPixel += bpp;
68
70
                ++pDstPixel;
69
71
            }
70
72
        }