~johbjo/qpdfview/invertlight

« back to all changes in this revision

Viewing changes to sources/rendertask.cpp

  • Committer: Johan Björklund
  • Date: 2020-12-26 10:05:57 UTC
  • Revision ID: johbjo09@gmail.com-20201226100557-owt2hsu4xufn2rvo
Invert light 

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "rendertask.h"
23
23
 
 
24
#include <cmath>
24
25
#include <QApplication>
25
26
#include <qmath.h>
26
27
#include <QPainter>
155
156
                  static_cast< qreal >(bottom - top) / height);
156
157
}
157
158
 
 
159
void invertLight(QImage& image)
 
160
{
 
161
    QRgb* const begin = reinterpret_cast< QRgb* >(image.bits());
 
162
    QRgb* const end = reinterpret_cast< QRgb* >(image.bits() + image.byteCount());
 
163
 
 
164
    for(QRgb* pointer = begin; pointer != end; ++pointer)
 
165
    {
 
166
        const int alpha = qAlpha(*pointer);     
 
167
        int r = qRed(*pointer);
 
168
        int g = qGreen(*pointer);
 
169
        int b = qBlue(*pointer);
 
170
        int d = (int) round((384- r - g - b) / 1.5);
 
171
        r = r + d;
 
172
        g = g + d;
 
173
        b = b + d;
 
174
        r = (r > 255) ? 255 : (r < 0 ? 0 : r);
 
175
        g = (g > 255) ? 255 : (g < 0 ? 0 : g);
 
176
        b = (b > 255) ? 255 : (b < 0 ? 0 : b);
 
177
        *pointer = qRgba(r, g, b, alpha);
 
178
    }
 
179
}
 
180
 
158
181
void convertToGrayscale(QImage& image)
159
182
{
160
183
    QRgb* const begin = reinterpret_cast< QRgb* >(image.bits());
482
505
        convertToGrayscale(image);
483
506
    }
484
507
 
 
508
    if(m_renderParam.invertLight())
 
509
    {
 
510
        CANCELLATION_POINT
 
511
 
 
512
        invertLight(image);
 
513
    }
 
514
 
485
515
    if(m_renderParam.invertColors())
486
516
    {
487
517
        CANCELLATION_POINT