Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Move sample app, add corner radius and unfinished bevel.
Browse files Browse the repository at this point in the history
  • Loading branch information
SlaunchaMan committed Jun 12, 2012
1 parent 76e0b5a commit 6e78568
Show file tree
Hide file tree
Showing 19 changed files with 426 additions and 306 deletions.
3 changes: 0 additions & 3 deletions AmazeKit.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

181 changes: 181 additions & 0 deletions AmazeKit/AmazeKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions AmazeKit/AmazeKit/AKBevelImageEffect.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AKBevelImageEffect.h
// AmazeKit
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
//


#import "AKImageEffect.h"


@interface AKBevelImageEffect : AKImageEffect

// The color of the bevel.
@property (strong) UIColor *color;

// The maximum radius of the bevel.
@property (assign) CGFloat radius;

@end
69 changes: 69 additions & 0 deletions AmazeKit/AmazeKit/AKBevelImageEffect.m
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// AKBevelImageEffect.m
// AmazeKit
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
//


#import "AKBevelImageEffect.h"

#import "UIImage+AKPixelData.h"


@implementation AKBevelImageEffect

@synthesize color = _color;
@synthesize radius = _radius;

- (id)init
{
self = [super init];

if (self) {
_radius = 1.0f;
}

return self;
}

- (UIImage *)renderedImageFromSourceImage:(UIImage *)sourceImage
{
// Get the pixel data of the source image.
NSData *pixelData = [sourceImage AK_rawRGBA8888Data];

uint8_t *rawData = [pixelData bytes];

NSUInteger width = [sourceImage size].width;
NSUInteger height = [sourceImage size].height;

uint8_t *foo;

// Create a data buffer to write data into.

// For every pixel, if it’s transparent and the pixel below it is not, add to the overlay
// buffer below according to the radius.
for (NSUInteger x = 0; x < width; x++) {
for (NSUInteger y = 0; y < height - 1; y++) {
// Is the current pixel “lit”?
AKPixelData pixelData = AKGetPixelDataFromRGBA8888Data(rawData, width, height, x, y);

if (pixelData.alpha == 0.0f) {
AKPixelData pixelDataUnderneath = AKGetPixelDataFromRGBA8888Data(rawData, width, height, x, y + 1);

if (pixelDataUnderneath.alpha >= 0.01f) {

}

NSUInteger yToInspect = y - 1;

while (yToInspect >= 0) {
// distanceToUnlit++;
}
}
}
}
}

@end
38 changes: 38 additions & 0 deletions AmazeKit/AmazeKit/AKCornerRadiusImageEffect.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AKCornerRadiusImageEffect.h
// AmazeKit
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
//


#import "AKImageEffect.h"


typedef struct {
CGFloat topLeft;
CGFloat topRight;
CGFloat bottomLeft;
CGFloat bottomRight;
} AKCornerRadii;

static inline AKCornerRadii
AKCornerRadiiMake(CGFloat topLeft, CGFloat topRight, CGFloat bottomLeft, CGFloat bottomRight)
{
AKCornerRadii radii;

radii.topLeft = topLeft;
radii.topRight = topRight;
radii.bottomLeft = bottomLeft;
radii.bottomRight = bottomRight;

return radii;
}

@interface AKCornerRadiusImageEffect : AKImageEffect

// The corner radii can be set independently.
@property (assign) AKCornerRadii cornerRadii;

@end
72 changes: 72 additions & 0 deletions AmazeKit/AmazeKit/AKCornerRadiusImageEffect.m
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// AKCornerRadiusImageEffect.m
// AmazeKit
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
//


#import "AKCornerRadiusImageEffect.h"


@implementation AKCornerRadiusImageEffect

@synthesize cornerRadii = _cornerRadii;

- (UIImage *)renderedImageFromSourceImage:(UIImage *)sourceImage
{
CGFloat width = [sourceImage size].width;
CGFloat height = [sourceImage size].height;

// Create the mask image.
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

CGContextRef context = CGBitmapContextCreate(NULL,
width,
height,
8,
8 * width,
colorSpace,
kCGImageAlphaNone);

CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 1.0, 0.0);
CGContextAddRect(context, CGRectMake(0.0f, 0.0f, width, height));
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFill);

CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0f, height / 2.0f);
CGContextAddArcToPoint(context, 0.0f, 0.0f, width / 2.0f, 0.0f, [self cornerRadii].bottomLeft);
CGContextAddArcToPoint(context, width, 0.0f, width, height / 2.0f, [self cornerRadii].bottomRight);
CGContextAddArcToPoint(context, width, height, width / 2.0f, height, [self cornerRadii].topRight);
CGContextAddArcToPoint(context, 0.0f, height, 0.0f, height / 2.0f, [self cornerRadii].topLeft);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFill);

CGImageRef mask = CGBitmapContextCreateImage(context);

CGContextRelease(context);
context = NULL;

// Render the noise layer on top of the source image.
UIGraphicsBeginImageContextWithOptions([sourceImage size], NO, 0.0f);
context = UIGraphicsGetCurrentContext();

CGContextScaleCTM(context, 1.0f, -1.0f);
CGContextTranslateCTM(context, 0.0f, -height);

CGImageRef maskedOriginalImage = CGImageCreateWithMask([sourceImage CGImage], mask);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), maskedOriginalImage);

UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
context = NULL;

return renderedImage;
}

@end
2 changes: 2 additions & 0 deletions AmazeKit/AmazeKit/AmazeKit.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


// Image Effects // Image Effects
#import "AKImageEffect.h" #import "AKImageEffect.h"
#import "AKBevelImageEffect.h"
#import "AKColorImageEffect.h" #import "AKColorImageEffect.h"
#import "AKCornerRadiusImageEffect.h"
#import "AKGradientImageEffect.h" #import "AKGradientImageEffect.h"
#import "AKNoiseImageEffect.h" #import "AKNoiseImageEffect.h"


Expand Down
15 changes: 14 additions & 1 deletion AmazeKit/AmazeKit/UIImage+AKPixelData.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>




// Helper C functions
typedef struct {
CGFloat red;
CGFloat blue;
CGFloat green;
CGFloat alpha;
} AKPixelData;


AKPixelData AKGetPixelDataFromRGBA8888Data(uint8_t *rawData, NSUInteger width, NSUInteger height,
NSUInteger x, NSUInteger y);


@interface UIImage (AKPixelData) @interface UIImage (AKPixelData)


- (NSData *)AK_rawARGB8888Data; - (NSData *)AK_rawRGBA8888Data;


@end @end
21 changes: 20 additions & 1 deletion AmazeKit/AmazeKit/UIImage+AKPixelData.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@implementation UIImage (AKPixelData) @implementation UIImage (AKPixelData)


- (NSData *)AK_rawARGB8888Data - (NSData *)AK_rawRGBA8888Data
{ {
// First get the image into your data buffer // First get the image into your data buffer
CGImageRef imageRef = [self CGImage]; CGImageRef imageRef = [self CGImage];
Expand Down Expand Up @@ -48,3 +48,22 @@ - (NSData *)AK_rawARGB8888Data
} }


@end @end

AKPixelData AKGetPixelDataFromRGBA8888Data(uint8_t *rawData, NSUInteger width, NSUInteger height,
NSUInteger x, NSUInteger y)
{
int bytesPerPixel = 4; // ARGB8888
int bytesPerRow = bytesPerPixel * width;

int byteIndex = (bytesPerRow * y) + x * bytesPerPixel;

AKPixelData pixelData;

pixelData.red = ((CGFloat)rawData[byteIndex] / 255.0f);
pixelData.green = ((CGFloat)rawData[byteIndex + 1] / 255.0f);
pixelData.blue = ((CGFloat)rawData[byteIndex + 2] / 255.0f);
pixelData.alpha = ((CGFloat)rawData[byteIndex + 3] / 255.0f);

return pixelData;
}

Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
// //
// AKAppDelegate.h // AKAppDelegate.h
// SmapleApp // SampleApp
// //
// Created by Jeffrey Kelley on 6/12/12. // Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved. // Copyright (c) 2012 Detroit Labs. All rights reserved.
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
// //
// AKAppDelegate.m // AKAppDelegate.m
// SmapleApp // SampleApp
// //
// Created by Jeffrey Kelley on 6/12/12. // Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved. // Copyright (c) 2012 Detroit Labs. All rights reserved.
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ - (void)viewDidLoad
blue:255.0f / 255.0f blue:255.0f / 255.0f
alpha:1.0f]]; alpha:1.0f]];


// Corner Radius Effect
AKCornerRadiusImageEffect *cornerRadiusEffect = [[AKCornerRadiusImageEffect alloc] init];
[cornerRadiusEffect setCornerRadii:AKCornerRadiiMake(50.0f, 10.0f, 10.0f, 5.0f)];

[gradientEffect setColors:[NSArray arrayWithObjects:beginColor, endColor, nil]]; [gradientEffect setColors:[NSArray arrayWithObjects:beginColor, endColor, nil]];


[renderer setImageEffects:[NSArray arrayWithObjects: [renderer setImageEffects:[NSArray arrayWithObjects:
noiseEffect, noiseEffect,
gradientEffect, gradientEffect,
colorEffect, colorEffect,
cornerRadiusEffect,
nil]]; nil]];


UIImage *image = [renderer imageWithSize:[imageView frame].size UIImage *image = [renderer imageWithSize:[imageView frame].size
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
// //
// Prefix header for all source files of the 'SmapleApp' target in the 'SmapleApp' project // Prefix header for all source files of the 'SampleApp' target in the 'SampleApp' project
// //


#import <Availability.h> #import <Availability.h>
Expand Down
2 changes: 1 addition & 1 deletion SmapleApp/SmapleApp/main.m → AmazeKit/SampleApp/main.m
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
// //
// main.m // main.m
// SmapleApp // SampleApp
// //
// Created by Jeffrey Kelley on 6/12/12. // Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved. // Copyright (c) 2012 Detroit Labs. All rights reserved.
Expand Down
Loading

0 comments on commit 6e78568

Please sign in to comment.