File indexing completed on 2024-04-28 04:20:11
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_COMMAND_SIZE 0 0030 0031 0032 #include "commands/kpCommandSize.h" 0033 #include "layers/selections/kpAbstractSelection.h" 0034 0035 #include <QImage> 0036 #include <QPolygon> 0037 #include <QString> 0038 0039 0040 // public static 0041 kpCommandSize::SizeType kpCommandSize::PixmapSize (const QImage &image) 0042 { 0043 return kpCommandSize::PixmapSize (image.width (), image.height (), image.depth ()); 0044 } 0045 0046 // public static 0047 kpCommandSize::SizeType kpCommandSize::PixmapSize (const QImage *image) 0048 { 0049 return (image ? kpCommandSize::PixmapSize (*image) : 0); 0050 } 0051 0052 // public static 0053 kpCommandSize::SizeType kpCommandSize::PixmapSize (int width, int height, int depth) 0054 { 0055 // handle 15bpp 0056 int roundedDepth = (depth > 8 ? (depth + 7) / 8 * 8 : depth); 0057 kpCommandSize::SizeType ret = 0058 static_cast<kpCommandSize::SizeType> (width) * height * roundedDepth / 8; 0059 0060 #if DEBUG_KP_COMMAND_SIZE && 0 0061 qCDebug(kpLogCommands) << "kpCommandSize::PixmapSize() w=" << width 0062 << " h=" << height 0063 << " d=" << depth 0064 << " roundedDepth=" << roundedDepth 0065 << " ret=" << ret; 0066 #endif 0067 return ret; 0068 } 0069 0070 0071 // public static 0072 kpCommandSize::SizeType kpCommandSize::QImageSize (const QImage &image) 0073 { 0074 return kpCommandSize::QImageSize (image.width (), image.height (), image.depth ()); 0075 } 0076 0077 // public static 0078 kpCommandSize::SizeType kpCommandSize::QImageSize (const QImage *image) 0079 { 0080 return (image ? kpCommandSize::QImageSize (*image) : 0); 0081 } 0082 0083 // public static 0084 kpCommandSize::SizeType kpCommandSize::QImageSize (int width, int height, int depth) 0085 { 0086 // handle 15bpp 0087 int roundedDepth = (depth > 8 ? (depth + 7) / 8 * 8 : depth); 0088 kpCommandSize::SizeType ret = 0089 static_cast<kpCommandSize::SizeType> (width) * height * roundedDepth / 8; 0090 0091 #if DEBUG_KP_COMMAND_SIZE && 0 0092 qCDebug(kpLogCommands) << "kpCommandSize::QImageSize() w=" << width 0093 << " h=" << height 0094 << " d=" << depth 0095 << " roundedDepth=" << roundedDepth 0096 << " ret=" << ret; 0097 #endif 0098 0099 return ret; 0100 } 0101 0102 0103 // public static 0104 kpCommandSize::SizeType kpCommandSize::ImageSize (const kpImage &image) 0105 { 0106 return kpCommandSize::PixmapSize (image); 0107 } 0108 0109 // public static 0110 kpCommandSize::SizeType kpCommandSize::ImageSize (const kpImage *image) 0111 { 0112 return kpCommandSize::PixmapSize (image); 0113 } 0114 0115 0116 // public static 0117 kpCommandSize::SizeType kpCommandSize::SelectionSize (const kpAbstractSelection &sel) 0118 { 0119 return sel.size (); 0120 } 0121 0122 // public static 0123 kpCommandSize::SizeType kpCommandSize::SelectionSize (const kpAbstractSelection *sel) 0124 { 0125 return (sel ? sel->size () : 0); 0126 } 0127 0128 0129 // public static 0130 kpCommandSize::SizeType kpCommandSize::StringSize (const QString &string) 0131 { 0132 #if DEBUG_KP_COMMAND_SIZE && 1 0133 qCDebug(kpLogCommands) << "kpCommandSize::StringSize(" << string << ")" 0134 << " len=" << string.length () 0135 << " sizeof(QChar)=" << sizeof (QChar); 0136 #endif 0137 return static_cast<SizeType> (static_cast<unsigned int> (string.length ()) * sizeof (QChar)); 0138 } 0139 0140 0141 // public static 0142 kpCommandSize::SizeType kpCommandSize::PolygonSize (const QPolygon &points) 0143 { 0144 #if DEBUG_KP_COMMAND_SIZE && 1 0145 qCDebug(kpLogCommands) << "kpCommandSize::PolygonSize() points.size=" 0146 << points.size () 0147 << " sizeof(QPoint)=" << sizeof (QPoint); 0148 #endif 0149 0150 return static_cast<SizeType> (static_cast<unsigned int> (points.size ()) * sizeof (QPoint)); 0151 } 0152