File indexing completed on 2024-05-19 04:22:56
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #define DEBUG_KP_EFFECT_INVERT 0 0030 0031 0032 #include "kpEffectInvert.h" 0033 0034 #include <QImage> 0035 0036 #include "kpLogCategories.h" 0037 0038 #include "pixmapfx/kpPixmapFX.h" 0039 0040 0041 // public static 0042 void kpEffectInvert::applyEffect (QImage *destImagePtr, int channels) 0043 { 0044 if (channels == kpEffectInvert::RGB) 0045 { 0046 destImagePtr->invertPixels (); 0047 return; 0048 } 0049 0050 QRgb mask = qRgba ((channels & Red) ? 0xFF : 0, 0051 (channels & Green) ? 0xFF : 0, 0052 (channels & Blue) ? 0xFF : 0, 0053 0/*don't invert alpha*/); 0054 #if DEBUG_KP_EFFECT_INVERT 0055 qCDebug(kpLogImagelib) << "kpEffectInvert::applyEffect(channels=" << channels 0056 << ") mask=" << (int *) mask; 0057 #endif 0058 0059 if (destImagePtr->depth () > 8) 0060 { 0061 // Above version works for Qt 3.2 at least. 0062 // But this version will always work (slower, though) and supports 0063 // inverting particular channels. 0064 for (int y = 0; y < destImagePtr->height (); y++) 0065 { 0066 for (int x = 0; x < destImagePtr->width (); x++) 0067 { 0068 destImagePtr->setPixel (x, y, destImagePtr->pixel (x, y) ^ mask); 0069 } 0070 } 0071 } 0072 else 0073 { 0074 for (int i = 0; i < destImagePtr->colorCount (); i++) 0075 { 0076 destImagePtr->setColor (i, destImagePtr->color (i) ^ mask); 0077 } 0078 } 0079 } 0080 0081 // public static 0082 QImage kpEffectInvert::applyEffect (const QImage &img, int channels) 0083 { 0084 QImage retImage = img; 0085 applyEffect (&retImage, channels); 0086 return retImage; 0087 } 0088 0089