index : hkutil

this commit

master

Utility classes and functions |

about summary refs log tree commit diff stats

log msg

author

committer

range

| Commit message (Expand) | Author | Age | Files | Lines
* | Added console progress meter | Kelly Rauchenberger | 2018-03-27 | 1 | -0/+61
* | Included missing <vector> for database.h | Kelly Rauchenberger | 2018-03-27 | 1 | -0/+1
* | Added read functionality to database | Kelly Rauchenberger | 2018-03-27 | 1 | -26/+203
* | Wrote write-only database class | Kelly Rauchenberger | 2018-03-27 | 2 | -0/+2670
* | Added string utils (uppercase, split, implode) | Kelly Rauchenberger | 2018-03-27 | 1 | -0/+87
* | Initial commit | Kelly Rauchenberger | 2018-03-27 | 1 | -0/+3

generated by cgit-pink 1.4.1 (git 2.36.1) at 2024-07-10 05:53:17 +0000

n44' href='#n44'>44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

//
// UIImage+ColorMasking.m
// Cartographic
//
// Created by Starla Insigna on 8/22/11.
// Copyright 2011 Four Island. All rights reserved.
//

#import "UIImage+ColorMasking.h"

@implementation UIImage (ColorMasking)

typedef enum {
ALPHA = 0,
BLUE = 1,
GREEN = 2,
RED = 3
} PIXELS;

- (UIImage *)opaqueMaskFromWhiteImage
{
CGSize size = [self size];
int width = size.width;
int height = size.height;

// the pixels will be painted to this array
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));

// clear the pixels so any transparency is preserved
memset(pixels, 0, width * height * sizeof(uint32_t));

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

// create a context with RGBA pixels
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);

// paint the bitmap to our context which will fill in the pixels array
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]);

for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x];

if ((rgbaPixel[RED] == 255) && (rgbaPixel[GREEN] == 255) && (rgbaPixel[BLUE] == 255) && (rgbaPixel[ALPHA] == 255))
{
rgbaPixel[RED] = 255;
rgbaPixel[GREEN] = 255;
rgbaPixel[BLUE] = 255;
rgbaPixel[ALPHA] = 255;
} else {
rgbaPixel[RED] = 0;
rgbaPixel[GREEN] = 0;
rgbaPixel[BLUE] = 0;
rgbaPixel[ALPHA] = 0;
}
}
}

// create a new CGImageRef from our context with the modified pixels
CGImageRef image = CGBitmapContextCreateImage(context);

// we're done with the context, color space, and pixels
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixels);

// make a new UIImage to return
UIImage *resultUIImage = [UIImage imageWithCGImage:image];

// we're done with image now too
CGImageRelease(image);

return resultUIImage;
}

@end

generated by cgit-pink 1.4.1 (git 2.36.1) at 2024-07-10 05:53:17 +0000