KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example.cc 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * This file is part of the KDE project
  3. *
  4. * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include <stdlib.h>
  20. #include <vector>
  21. #include <tqpoint.h>
  22. #include <tdelocale.h>
  23. #include <kiconloader.h>
  24. #include <kinstance.h>
  25. #include <tdemessagebox.h>
  26. #include <kstandarddirs.h>
  27. #include <tdetempfile.h>
  28. #include <kdebug.h>
  29. #include <kgenericfactory.h>
  30. #include <kis_image.h>
  31. #include <kis_iterators_pixel.h>
  32. #include <kis_layer.h>
  33. #include <kis_filter_registry.h>
  34. #include <kis_global.h>
  35. #include <kis_types.h>
  36. // #include <tdemessagebox.h>
  37. #include "example.h"
  38. typedef KGenericFactory<ChalkExample> ChalkExampleFactory;
  39. K_EXPORT_COMPONENT_FACTORY( chalkexample, ChalkExampleFactory( "chalk" ) )
  40. ChalkExample::ChalkExample(TQObject *parent, const char *name, const TQStringList &)
  41. : KParts::Plugin(parent, name)
  42. {
  43. setInstance(ChalkExampleFactory::instance());
  44. if (parent->inherits("KisFilterRegistry")) {
  45. KisFilterRegistry * manager = dynamic_cast<KisFilterRegistry *>(parent);
  46. manager->add(new KisFilterInvert());
  47. }
  48. }
  49. ChalkExample::~ChalkExample()
  50. {
  51. }
  52. KisFilterInvert::KisFilterInvert() : KisFilter(id(), "adjust", i18n("&Invert"))
  53. {
  54. }
  55. void KisFilterInvert::process(KisPaintDeviceSP src, KisPaintDeviceSP dst, KisFilterConfiguration* /*config*/, const TQRect& rect)
  56. {
  57. Q_ASSERT(src != 0);
  58. Q_ASSERT(dst != 0);
  59. KisRectIteratorPixel dstIt = dst->createRectIterator(rect.x(), rect.y(), rect.width(), rect.height(), true );
  60. KisRectIteratorPixel srcIt = src->createRectIterator(rect.x(), rect.y(), rect.width(), rect.height(), false);
  61. int pixelsProcessed = 0;
  62. setProgressTotalSteps(rect.width() * rect.height());
  63. KisColorSpace * cs = src->colorSpace();
  64. TQ_INT32 psize = cs->pixelSize();
  65. while( ! srcIt.isDone() )
  66. {
  67. if(srcIt.isSelected())
  68. {
  69. if (src!=dst)
  70. memcpy(dstIt.rawData(), srcIt.oldRawData(), psize);
  71. cs->invertColor( dstIt.rawData(), 1);
  72. }
  73. setProgress(++pixelsProcessed);
  74. ++srcIt;
  75. ++dstIt;
  76. }
  77. setProgressDone(); // Must be called even if you don't really support progression
  78. }