File indexing completed on 2024-05-05 04:21:07
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 #ifndef KP_FLOOD_FILL_H 0030 #define KP_FLOOD_FILL_H 0031 0032 0033 #include "kpImage.h" 0034 #include "commands/kpCommandSize.h" 0035 0036 0037 class kpColor; 0038 class kpFillLine; 0039 0040 0041 struct kpFloodFillPrivate; 0042 0043 class kpFloodFill 0044 { 0045 public: 0046 kpFloodFill (kpImage *image, int x, int y, 0047 const kpColor &color, 0048 int processedColorSimilarity); 0049 ~kpFloodFill (); 0050 0051 kpFloodFill(const kpFloodFill &) = delete; 0052 kpFloodFill &operator=(const kpFloodFill &) = delete; 0053 0054 // 0055 // Spits back constructor arguments. 0056 // 0057 0058 public: 0059 kpColor color () const; 0060 int processedColorSimilarity () const; 0061 0062 0063 public: 0064 // Used for calculating the size of a command in the command history. 0065 kpCommandSize::SizeType size () const; 0066 0067 0068 // 0069 // Step 1: Determines the colour that will be changed to color(). 0070 // 0071 // Very fast. 0072 // 0073 0074 public: 0075 void prepareColorToChange (); 0076 0077 // (may invoke prepareColorToChange()). 0078 kpColor colorToChange (); 0079 0080 0081 // 0082 // Step 2: Determines the scanlines / pixels that will be changed to color(). 0083 // 0084 // The slowest part of the whole fill operation. 0085 // 0086 // Before calling a Step 2 function, you don't have to (but you can) 0087 // call any of the functions in Step 1. 0088 // 0089 0090 private: 0091 kpColor pixelColor (int x, int y, bool *beenHere = nullptr) const; 0092 bool shouldGoTo (int x, int y) const; 0093 0094 // Finds the minimum x value at a certain line to be filled. 0095 int findMinX (int y, int x) const; 0096 0097 // Finds the maximum x value at a certain line to be filled. 0098 int findMaxX (int y, int x) const; 0099 0100 void addLine (int y, int x1, int x2); 0101 void findAndAddLines (const kpFillLine &fillLine, int dy); 0102 0103 public: 0104 // (may invoke Step 1's prepareColorToChange()) 0105 void prepare (); 0106 0107 // (may invoke prepare()) 0108 QRect boundingRect (); 0109 0110 0111 // 0112 // Step 3: Draws the lines identified in Step 2 in color(). 0113 // 0114 // Between the speeds of Step 2 and Step 1. 0115 // 0116 // Before calling a Step 3 function, you don't have to (but you can) 0117 // call any of the functions in Step 1 or 2. 0118 // 0119 0120 public: 0121 // (may invoke Step 2's prepare()) 0122 void fill (); 0123 0124 0125 private: 0126 kpFloodFillPrivate * const d; 0127 }; 0128 0129 0130 #endif // KP_FLOOD_FILL_H