Permalink
Browse files

Move sample app, add corner radius and unfinished bevel.

  • Loading branch information...
1 parent 76e0b5a commit 6e78568f9c6bc1395e6fdc81c9114c3d470ea623 @SlaunchaMan SlaunchaMan committed Jun 12, 2012

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -9,7 +9,9 @@
// Image Effects
#import "AKImageEffect.h"
+#import "AKBevelImageEffect.h"
#import "AKColorImageEffect.h"
+#import "AKCornerRadiusImageEffect.h"
#import "AKGradientImageEffect.h"
#import "AKNoiseImageEffect.h"
@@ -10,8 +10,21 @@
#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)
-- (NSData *)AK_rawARGB8888Data;
+- (NSData *)AK_rawRGBA8888Data;
@end
@@ -12,7 +12,7 @@
@implementation UIImage (AKPixelData)
-- (NSData *)AK_rawARGB8888Data
+- (NSData *)AK_rawRGBA8888Data
{
// First get the image into your data buffer
CGImageRef imageRef = [self CGImage];
@@ -48,3 +48,22 @@ - (NSData *)AK_rawARGB8888Data
}
@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;
+}
+
@@ -1,6 +1,6 @@
//
// AKAppDelegate.h
-// SmapleApp
+// SampleApp
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
@@ -1,6 +1,6 @@
//
// AKAppDelegate.m
-// SmapleApp
+// SampleApp
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
@@ -52,12 +52,17 @@ - (void)viewDidLoad
blue:255.0f / 255.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]];
[renderer setImageEffects:[NSArray arrayWithObjects:
noiseEffect,
gradientEffect,
colorEffect,
+ cornerRadiusEffect,
nil]];
UIImage *image = [renderer imageWithSize:[imageView frame].size
@@ -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>
@@ -1,6 +1,6 @@
//
// main.m
-// SmapleApp
+// SampleApp
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2012 Detroit Labs. All rights reserved.
Oops, something went wrong.

0 comments on commit 6e78568

Please sign in to comment.