1 /* 2 NSBitmapImageRep_PPUtilities.h 3 4 Copyright 2013-2018 Josh Freeman 5 http://www.twilightedge.com 6 7 This file is part of PikoPixel for Mac OS X and GNUstep. 8 PikoPixel is a graphical application for drawing & editing pixel-art images. 9 10 PikoPixel is free software: you can redistribute it and/or modify it under 11 the terms of the GNU Affero General Public License as published by the 12 Free Software Foundation, either version 3 of the License, or (at your 13 option) any later version approved for PikoPixel by its copyright holder (or 14 an authorized proxy). 15 16 PikoPixel is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 19 details. 20 21 You should have received a copy of the GNU Affero General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 #import <Cocoa/Cocoa.h> 26 #import "NSImageRep_PPUtilities.h" 27 #import "PPBitmapPixelTypes.h" 28 #import "PPGridType.h" 29 30 31 @interface NSBitmapImageRep (PPUtilities) 32 33 - (bool) ppIsEqualToBitmap: (NSBitmapImageRep *) comparisonBitmap; 34 35 - (bool) ppImportedBitmapHasAnimationFrames; 36 37 - (NSData *) ppCompressedTIFFData; 38 - (NSData *) ppCompressedTIFFDataFromBounds: (NSRect) bounds; 39 40 - (NSData *) ppCompressedPNGData; 41 42 - (void) ppSetAsCurrentGraphicsContext; 43 - (void) ppRestoreGraphicsContext; 44 45 - (void) ppClearBitmap; 46 - (void) ppClearBitmapInBounds: (NSRect) bounds; 47 48 - (void) ppCopyFromBitmap: (NSBitmapImageRep *) sourceBitmap 49 toPoint: (NSPoint) targetPoint; 50 51 - (void) ppCopyFromBitmap: (NSBitmapImageRep *) sourceBitmap 52 inRect: (NSRect) sourceRect 53 toPoint: (NSPoint) targetPoint; 54 55 - (void) ppCenteredCopyFromBitmap: (NSBitmapImageRep *) sourceBitmap; 56 57 - (NSBitmapImageRep *) ppBitmapCroppedToBounds: (NSRect) croppingBounds; 58 59 // ppShallowDuplicateFromBounds: returns an autoreleased copy that uses the same bitmapData 60 // pointer as the original (depending on croppingBounds, it may be offset). 61 // It's faster than ppBitmapCroppedToBounds:, which allocates a new buffer and copies the 62 // bitmapData. It should generally be used where the copy is just for reading, as writing to 63 // the copy's bitmapData will overwrite the original's. The copy should not outlive the 64 // original, as the copy's bitmapData pointer will become invalid when the original is 65 // deallocated. 66 - (NSBitmapImageRep *) ppShallowDuplicateFromBounds: (NSRect) croppingBounds; 67 68 - (NSBitmapImageRep *) ppBitmapResizedToSize: (NSSize) newSize shouldScale: (bool) shouldScale; 69 70 - (NSBitmapImageRep *) ppBitmapMirroredHorizontally; 71 - (NSBitmapImageRep *) ppBitmapMirroredVertically; 72 73 - (NSBitmapImageRep *) ppBitmapRotated90Clockwise; 74 - (NSBitmapImageRep *) ppBitmapRotated90Counterclockwise; 75 - (NSBitmapImageRep *) ppBitmapRotated180; 76 77 @end 78 79 @interface NSBitmapImageRep (PPUtilities_ImageBitmaps) 80 81 + (NSBitmapImageRep *) ppImageBitmapOfSize: (NSSize) size; 82 83 + (NSBitmapImageRep *) ppImageBitmapWithImportedData: (NSData *) importedData; 84 85 + (NSBitmapImageRep *) ppImageBitmapFromImageResource: (NSString *) imageName; 86 87 - (bool) ppIsImageBitmap; 88 - (bool) ppIsImageBitmapAndSameSizeAsMaskBitmap: (NSBitmapImageRep *) maskBitmap; 89 90 - (NSColor *) ppImageColorAtPoint: (NSPoint) point; 91 92 - (bool) ppImageBitmapHasTransparentPixels; 93 94 - (void) ppMaskedFillUsingMask: (NSBitmapImageRep *) maskBitmap 95 inBounds: (NSRect) fillBounds 96 fillPixelValue: (PPImageBitmapPixel) fillPixelValue; 97 98 - (void) ppMaskedEraseUsingMask: (NSBitmapImageRep *) maskBitmap; 99 100 - (void) ppMaskedEraseUsingMask: (NSBitmapImageRep *) maskBitmap 101 inBounds: (NSRect) eraseBounds; 102 103 - (void) ppMaskedCopyFromImageBitmap: (NSBitmapImageRep *) sourceBitmap 104 usingMask: (NSBitmapImageRep *) maskBitmap; 105 106 - (void) ppMaskedCopyFromImageBitmap: (NSBitmapImageRep *) sourceBitmap 107 usingMask: (NSBitmapImageRep *) maskBitmap 108 inBounds: (NSRect) copyBounds; 109 110 - (void) ppMaskedCopyFromImageBitmap:(NSBitmapImageRep *) sourceBitmap 111 usingMask: (NSBitmapImageRep *) maskBitmap 112 toPoint: (NSPoint) targetPoint; 113 114 - (void) ppScaledCopyFromImageBitmap: (NSBitmapImageRep *) sourceBitmap 115 inRect: (NSRect) sourceRect 116 toPoint: (NSPoint) destinationPoint 117 scalingFactor: (unsigned) scalingFactor; 118 119 - (void) ppScaledCopyFromImageBitmap: (NSBitmapImageRep *) sourceBitmap 120 inRect: (NSRect) sourceRect 121 toPoint: (NSPoint) destinationPoint 122 scalingFactor: (unsigned) scalingFactor 123 gridType: (PPGridType) gridType 124 gridPixelValue: (PPImageBitmapPixel) gridPixelValue; 125 126 - (NSBitmapImageRep *) ppImageBitmapWithMaxDimension: (float) maxDimension; 127 128 - (NSBitmapImageRep *) ppImageBitmapCompositedWithBackgroundColor: (NSColor *) backgroundColor 129 andBackgroundImage: (NSImage *) backgroundImage 130 backgroundImageInterpolation: 131 (NSImageInterpolation) backgroundImageInterpolation; 132 133 - (NSBitmapImageRep *) ppImageBitmapDissolvedToOpacity: (float) opacity; 134 - (NSBitmapImageRep *) ppImageBitmapMaskedWithMask: (NSBitmapImageRep *) maskBitmap; 135 136 - (NSBitmapImageRep *) ppImageBitmapScaledByFactor: (unsigned) scalingFactor 137 shouldDrawGrid: (bool) shouldDrawGrid 138 gridType: (PPGridType) gridType 139 gridColor: (NSColor *) gridColor; 140 141 - (NSBitmapImageRep *) ppMaskBitmapForVisiblePixelsInImageBitmap; 142 143 - (void) ppDrawImageGuidelinesInBounds: (NSRect) drawBounds 144 topLeftPhase: (NSPoint) topLeftPhase 145 unscaledSpacingSize: (NSSize) unscaledSpacingSize 146 scalingFactor: (unsigned) scalingFactor 147 guidelinePixelValue: (PPImageBitmapPixel) guidelinePixelValue; 148 149 @end 150 151 @interface NSBitmapImageRep (PPUtilities_LinearRGB16Bitmaps) 152 153 + (NSBitmapImageRep *) ppLinearRGB16BitmapOfSize: (NSSize) size; 154 155 - (NSBitmapImageRep *) ppLinearRGB16BitmapFromImageBitmap; 156 - (NSBitmapImageRep *) ppImageBitmapFromLinearRGB16Bitmap; 157 158 - (bool) ppIsLinearRGB16Bitmap; 159 160 - (void) ppLinearCopyFromImageBitmap: (NSBitmapImageRep *) sourceBitmap 161 inBounds: (NSRect) bounds; 162 163 - (void) ppLinearCopyToImageBitmap: (NSBitmapImageRep *) destinationBitmap 164 inBounds: (NSRect) bounds; 165 166 - (void) ppLinearBlendFromLinearBitmapUnderneath: (NSBitmapImageRep *) sourceBitmap 167 sourceOpacity: (float) sourceOpacity 168 inBounds: (NSRect) blendingBounds; 169 170 - (void) ppLinearCopyFromLinearBitmap: (NSBitmapImageRep *) sourceBitmap 171 opacity: (float) opacity 172 inBounds: (NSRect) copyBounds; 173 174 @end 175 176 @interface NSBitmapImageRep (PPUtilities_MaskBitmaps) 177 178 + (NSBitmapImageRep *) ppMaskBitmapOfSize: (NSSize) size; 179 180 - (bool) ppIsMaskBitmap; 181 182 - (NSRect) ppMaskBounds; 183 - (NSRect) ppMaskBoundsInRect: (NSRect) bounds; 184 185 - (bool) ppMaskIsNotEmpty; 186 - (bool) ppMaskCoversAllPixels; 187 - (bool) ppMaskCoversPoint: (NSPoint) point; 188 189 - (void) ppMaskPixelsInBounds: (NSRect) bounds; 190 191 - (void) ppIntersectMaskWithMaskBitmap: (NSBitmapImageRep *) maskBitmap; 192 193 - (void) ppIntersectMaskWithMaskBitmap: (NSBitmapImageRep *) maskBitmap 194 inBounds: (NSRect) intersectBounds; 195 196 - (void) ppSubtractMaskBitmap: (NSBitmapImageRep *) maskBitmap; 197 198 - (void) ppSubtractMaskBitmap: (NSBitmapImageRep *) maskBitmap 199 inBounds: (NSRect) subtractBounds; 200 201 - (void) ppMergeMaskWithMaskBitmap: (NSBitmapImageRep *) maskBitmap; 202 203 - (void) ppMergeMaskWithMaskBitmap: (NSBitmapImageRep *) maskBitmap 204 inBounds: (NSRect) mergeBounds; 205 206 - (void) ppInvertMaskBitmap; 207 208 - (void) ppCloseHolesInMaskBitmap; 209 210 - (void) ppThresholdMaskBitmapPixelValues; 211 212 - (void) ppThresholdMaskBitmapPixelValuesInBounds: (NSRect) bounds; 213 214 @end 215 216 @interface NSBitmapImageRep (PPUtilities_PatternBitmaps) 217 218 + (NSBitmapImageRep *) ppCheckerboardPatternBitmapWithBoxDimension: (float) boxDimension 219 color1: (NSColor *) color1 220 color2: (NSColor *) color2; 221 222 + (NSBitmapImageRep *) ppDiagonalCheckerboardPatternBitmapWithBoxDimension: 223 (float) boxDimension 224 color1: (NSColor *) color1 225 color2: (NSColor *) color2; 226 227 + (NSBitmapImageRep *) ppIsometricCheckerboardPatternBitmapWithBoxDimension: 228 (float) boxDimension 229 color1: (NSColor *) color1 230 color2: (NSColor *) color2; 231 232 + (NSBitmapImageRep *) ppDiagonalLinePatternBitmapWithLineWidth: (float) lineWidth 233 color1: (NSColor *) color1 234 color2: (NSColor *) color2; 235 236 + (NSBitmapImageRep *) ppIsometricLinePatternBitmapWithLineWidth: (float) lineWidth 237 color1: (NSColor *) color1 238 color2: (NSColor *) color2; 239 240 + (NSBitmapImageRep *) ppHorizontalGradientPatternBitmapWithWidth: (unsigned) width 241 leftColor: (NSColor *) leftColor 242 rightColor: (NSColor *) rightColor; 243 244 + (NSBitmapImageRep *) ppVerticalGradientPatternBitmapWithHeight: (unsigned) height 245 topColor: (NSColor *) topColor 246 bottomColor: (NSColor *) bottomColor; 247 248 + (NSBitmapImageRep *) ppCenteredVerticalGradientPatternBitmapWithHeight: (unsigned) height 249 innerColor: (NSColor *) innerColor 250 outerColor: (NSColor *) outerColor; 251 252 + (NSBitmapImageRep *) ppFillOverlayPatternBitmapWithSize: (float) patternSize 253 fillColor: (NSColor *) fillColor; 254 255 @end 256 257 @interface NSBitmapImageRep (PPUtilities_ColorMasking) 258 259 - (void) ppMaskNeighboringPixelsMatchingColorAtPoint: (NSPoint) point 260 inImageBitmap: (NSBitmapImageRep *) sourceBitmap 261 colorMatchTolerance: (unsigned) colorMatchTolerance 262 selectionMask: (NSBitmapImageRep *) selectionMask 263 selectionMaskBounds: (NSRect) selectionMaskBounds 264 matchDiagonally: (bool) matchDiagonally; 265 266 - (void) ppMaskAllPixelsMatchingColorAtPoint: (NSPoint) point 267 inImageBitmap: (NSBitmapImageRep *) sourceBitmap 268 colorMatchTolerance: (unsigned) colorMatchTolerance 269 selectionMask: (NSBitmapImageRep *) selectionMask 270 selectionMaskBounds: (NSRect) selectionMaskBounds; 271 272 - (void) ppMaskVisiblePixelsInImageBitmap: (NSBitmapImageRep *) sourceBitmap 273 selectionMask: (NSBitmapImageRep *) selectionMask; 274 275 @end 276