File indexing completed on 2024-07-21 12:12:46

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
0003     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
0004     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
0005     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 #include "image.h"
0023 #include "object_binding.h"
0024 
0025 #include <QDebug>
0026 #include <QImage>
0027 #include <QPoint>
0028 #include <QSize>
0029 
0030 using namespace KJSEmbed;
0031 
0032 const KJS::ClassInfo ImageBinding::info = { "QImage", &VariantBinding::info, nullptr, nullptr };
0033 ImageBinding::ImageBinding(KJS::ExecState *exec, const QImage &value)
0034     : VariantBinding(exec, value)
0035 {
0036     StaticBinding::publish(exec, this, VariantFactory::methods());
0037     StaticBinding::publish(exec, this, Image::methods());
0038 }
0039 
0040 namespace ImageNS
0041 {
0042 START_VARIANT_METHOD(callallGray, QImage)
0043 bool cppValue = value.allGray();
0044 result = KJS::jsBoolean(cppValue);
0045 END_VARIANT_METHOD
0046 
0047 START_VARIANT_METHOD(callalphaChannel, QImage)
0048 QImage cppValue = value.alphaChannel();
0049 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0050 END_VARIANT_METHOD
0051 
0052 START_VARIANT_METHOD(callcopy, QImage)
0053 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0054 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0055 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0056 int arg3 = KJSEmbed::extractInt(exec, args, 3);
0057 QImage cppValue = value.copy(arg0, arg1, arg2, arg3);
0058 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0059 END_VARIANT_METHOD
0060 
0061 START_VARIANT_METHOD(callcreateAlphaMask, QImage)
0062 Qt::ImageConversionFlags arg0 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 0);
0063 QImage cppValue = value.createAlphaMask(arg0);
0064 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0065 END_VARIANT_METHOD
0066 
0067 START_VARIANT_METHOD(callcreateHeuristicMask, QImage)
0068 bool arg0 = KJSEmbed::extractBool(exec, args, 0);
0069 QImage cppValue = value.createHeuristicMask(arg0);
0070 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0071 END_VARIANT_METHOD
0072 
0073 START_VARIANT_METHOD(calldepth, QImage)
0074 int cppValue = value.depth();
0075 result = KJS::jsNumber(cppValue);
0076 END_VARIANT_METHOD
0077 
0078 START_VARIANT_METHOD(calldevType, QImage)
0079 int cppValue = value.devType();
0080 result = KJS::jsNumber(cppValue);
0081 END_VARIANT_METHOD
0082 
0083 START_VARIANT_METHOD(calldotsPerMeterX, QImage)
0084 int cppValue = value.dotsPerMeterX();
0085 result = KJS::jsNumber(cppValue);
0086 END_VARIANT_METHOD
0087 
0088 START_VARIANT_METHOD(calldotsPerMeterY, QImage)
0089 int cppValue = value.dotsPerMeterY();
0090 result = KJS::jsNumber(cppValue);
0091 END_VARIANT_METHOD
0092 
0093 START_VARIANT_METHOD(callfill, QImage)
0094 uint arg0 = KJSEmbed::extractVariant<uint>(exec, args, 0);
0095 value.fill(arg0);
0096 END_VARIANT_METHOD
0097 
0098 START_VARIANT_METHOD(callhasAlphaChannel, QImage)
0099 bool cppValue = value.hasAlphaChannel();
0100 result = KJS::jsBoolean(cppValue);
0101 END_VARIANT_METHOD
0102 
0103 START_VARIANT_METHOD(callheight, QImage)
0104 int cppValue = value.height();
0105 result = KJS::jsNumber(cppValue);
0106 END_VARIANT_METHOD
0107 
0108 START_VARIANT_METHOD(callinvertPixels, QImage)
0109 QImage::InvertMode arg0 = (QImage::InvertMode)KJSEmbed::extractInt(exec, args, 0);
0110 value.invertPixels(arg0);
0111 END_VARIANT_METHOD
0112 
0113 START_VARIANT_METHOD(callisGrayscale, QImage)
0114 bool cppValue = value.isGrayscale();
0115 result = KJS::jsBoolean(cppValue);
0116 END_VARIANT_METHOD
0117 
0118 START_VARIANT_METHOD(callisNull, QImage)
0119 bool cppValue = value.isNull();
0120 result = KJS::jsBoolean(cppValue);
0121 END_VARIANT_METHOD
0122 
0123 START_VARIANT_METHOD(callload, QImage)
0124 QString arg0 = KJSEmbed::extractQString(exec, args, 0);
0125 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1();
0126 bool cppValue = value.load(arg0, arg1);
0127 result = KJS::jsBoolean(cppValue);
0128 END_VARIANT_METHOD
0129 
0130 START_VARIANT_METHOD(callmirrored, QImage)
0131 bool arg0 = KJSEmbed::extractBool(exec, args, 0);
0132 bool arg1 = KJSEmbed::extractBool(exec, args, 1);
0133 QImage cppValue = value.mirrored(arg0, arg1);
0134 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0135 END_VARIANT_METHOD
0136 
0137 START_VARIANT_METHOD(callnumBytes, QImage)
0138 int cppValue = value.byteCount();
0139 result = KJS::jsNumber(cppValue);
0140 END_VARIANT_METHOD
0141 
0142 START_VARIANT_METHOD(callnumColors, QImage)
0143 int cppValue = value.colorCount();
0144 result = KJS::jsNumber(cppValue);
0145 END_VARIANT_METHOD
0146 
0147 START_VARIANT_METHOD(calloffset, QImage)
0148 QPoint cppValue = value.offset();
0149 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0150 END_VARIANT_METHOD
0151 
0152 START_VARIANT_METHOD(callpixel, QImage)
0153 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0154 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0155 QRgb cppValue = value.pixel(arg0, arg1);
0156 result = KJS::jsNumber(cppValue);
0157 END_VARIANT_METHOD
0158 
0159 START_VARIANT_METHOD(callpixelIndex, QImage)
0160 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0161 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0162 int cppValue = value.pixelIndex(arg0, arg1);
0163 result = KJS::jsNumber(cppValue);
0164 END_VARIANT_METHOD
0165 
0166 START_VARIANT_METHOD(callrect, QImage)
0167 QRect cppValue = value.rect();
0168 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0169 END_VARIANT_METHOD
0170 
0171 START_VARIANT_METHOD(callrgbSwapped, QImage)
0172 QImage cppValue = value.rgbSwapped();
0173 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0174 END_VARIANT_METHOD
0175 
0176 START_VARIANT_METHOD(callsave, QImage)
0177 QString arg0 = KJSEmbed::extractQString(exec, args, 0);
0178 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1();
0179 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0180 bool cppValue = value.save(arg0, arg1, arg2);
0181 result = KJS::jsBoolean(cppValue);
0182 END_VARIANT_METHOD
0183 
0184 START_VARIANT_METHOD(callscaled, QImage)
0185 if (args.size() == 3)
0186 {
0187     QSize arg0 = KJSEmbed::extractVariant<QSize>(exec, args, 0);
0188     Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 1);
0189     Qt::TransformationMode arg2 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 2);
0190     QImage cppValue = value.scaled(arg0, arg1, arg2);
0191     result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0192 } else if (args.size() == 4)
0193 {
0194     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0195     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0196     Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 2);
0197     Qt::TransformationMode arg3 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 3);
0198     QImage cppValue = value.scaled(arg0, arg1, arg2, arg3);
0199     result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0200 }
0201 END_VARIANT_METHOD
0202 
0203 START_VARIANT_METHOD(callscaledToHeight, QImage)
0204 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0205 Qt::TransformationMode arg1 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 1);
0206 QImage cppValue = value.scaledToHeight(arg0, arg1);
0207 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0208 END_VARIANT_METHOD
0209 
0210 START_VARIANT_METHOD(callscaledToWidth, QImage)
0211 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0212 Qt::TransformationMode arg1 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 1);
0213 QImage cppValue = value.scaledToWidth(arg0, arg1);
0214 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
0215 END_VARIANT_METHOD
0216 
0217 START_VARIANT_METHOD(callserialNumber, QImage)
0218 int cppValue = value.serialNumber();
0219 result = KJS::jsNumber(cppValue);
0220 END_VARIANT_METHOD
0221 
0222 START_VARIANT_METHOD(callsetAlphaChannel, QImage)
0223 QImage arg0 = KJSEmbed::extractVariant<QImage>(exec, args, 0);
0224 value.setAlphaChannel(arg0);
0225 END_VARIANT_METHOD
0226 
0227 START_VARIANT_METHOD(callsetColor, QImage)
0228 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0229 QRgb arg1 = (QRgb)KJSEmbed::extractInt(exec, args, 1);
0230 value.setColor(arg0, arg1);
0231 END_VARIANT_METHOD
0232 
0233 START_VARIANT_METHOD(callsetDotsPerMeterX, QImage)
0234 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0235 value.setDotsPerMeterX(arg0);
0236 END_VARIANT_METHOD
0237 
0238 START_VARIANT_METHOD(callsetDotsPerMeterY, QImage)
0239 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0240 value.setDotsPerMeterY(arg0);
0241 END_VARIANT_METHOD
0242 
0243 START_VARIANT_METHOD(callsetNumColors, QImage)
0244 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0245 value.setColorCount(arg0);
0246 END_VARIANT_METHOD
0247 
0248 START_VARIANT_METHOD(callsetOffset, QImage)
0249 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0250 value.setOffset(arg0);
0251 END_VARIANT_METHOD
0252 
0253 START_VARIANT_METHOD(callsetPixel, QImage)
0254 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0255 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0256 uint arg2 = KJSEmbed::extractVariant<uint>(exec, args, 2);
0257 value.setPixel(arg0, arg1, arg2);
0258 END_VARIANT_METHOD
0259 
0260 START_VARIANT_METHOD(callsize, QImage)
0261 QSize cppValue = value.size();
0262 result = KJSEmbed::createVariant(exec, "QSize", cppValue);
0263 END_VARIANT_METHOD
0264 
0265 START_VARIANT_METHOD(callvalid, QImage)
0266 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0267 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0268 bool cppValue = value.valid(arg0, arg1);
0269 result = KJS::jsBoolean(cppValue);
0270 END_VARIANT_METHOD
0271 
0272 START_VARIANT_METHOD(callwidth, QImage)
0273 int cppValue = value.width();
0274 result = KJS::jsNumber(cppValue);
0275 END_VARIANT_METHOD
0276 
0277 }
0278 
0279 START_METHOD_LUT(Image)
0280 {"allGray", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callallGray},
0281 {"alphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callalphaChannel},
0282 {"copy", 4, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcopy},
0283 {"createAlphaMask", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcreateAlphaMask},
0284 {"createHeuristicMask", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcreateHeuristicMask},
0285 {"depth", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldepth},
0286 {"dotsPerMeterX", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldotsPerMeterX},
0287 {"dotsPerMeterY", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldotsPerMeterY},
0288 {"fill", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callfill},
0289 {"hasAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callhasAlphaChannel},
0290 {"height", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callheight},
0291 {"invertPixels", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callinvertPixels},
0292 {"isGrayscale", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callisGrayscale},
0293 {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callisNull},
0294 {"load", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callload},
0295 {"mirrored", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callmirrored},
0296 {"numBytes", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callnumBytes},
0297 {"numColors", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callnumColors},
0298 {"offset", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calloffset},
0299 {"pixel", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callpixel},
0300 {"pixelIndex", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callpixelIndex},
0301 {"rect", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callrect},
0302 {"rgbSwapped", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callrgbSwapped},
0303 {"save", 2, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsave},
0304 {"scaled", 3, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaled},
0305 {"scaledToHeight", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaledToHeight},
0306 {"scaledToWidth", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaledToWidth},
0307 {"serialNumber", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callserialNumber},
0308 {"setAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetAlphaChannel},
0309 {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetColor},
0310 {"setDotsPerMeterX", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetDotsPerMeterX},
0311 {"setDotsPerMeterY", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetDotsPerMeterY},
0312 {"setNumColors", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetNumColors},
0313 {"setOffset", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetOffset},
0314 {"setPixel", 2, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetPixel},
0315 {"size", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsize},
0316 {"valid", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callvalid},
0317 {"width", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callwidth}
0318 END_METHOD_LUT
0319 
0320 NO_ENUMS(Image)
0321 NO_STATICS(Image)
0322 
0323 START_CTOR(Image, QImage, 0)
0324 if (args.size() == 0)
0325 {
0326     return new KJSEmbed::ImageBinding(exec, QImage());
0327 }
0328 if (args.size() == 1)
0329 {
0330     return new KJSEmbed::ImageBinding(exec, QImage(KJSEmbed::extractQString(exec, args, 0)));
0331 } else if (args.size() == 2)
0332 {
0333     return new KJSEmbed::ImageBinding(exec,
0334                                       QImage(KJSEmbed::extractVariant<QSize>(exec, args, 0),
0335                                               (QImage::Format)KJSEmbed::extractInt(exec, args, 1)));
0336 } else if (args.size() == 3)
0337 {
0338     return new KJSEmbed::ImageBinding(exec,
0339                                       QImage(KJSEmbed::extractInt(exec, args, 0),
0340                                               KJSEmbed::extractInt(exec, args, 1),
0341                                               (QImage::Format)KJSEmbed::extractInt(exec, args, 2)));
0342 }
0343 return new KJSEmbed::ImageBinding(exec, QImage());
0344 END_CTOR
0345