GithubHelp home page GithubHelp logo

v-silin / syimagecolortools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dvkch/syimagecolortools

0.0 2.0 0.0 19 KB

It's always a hassle to get pixel information of an UIImage. Let's remedy that!

License: Other

Objective-C 96.57% Ruby 3.43%

syimagecolortools's Introduction

SYImageColorTools

It's always a hassle to get pixel information of an UIImage. Let's remedy that!

Use pod SYImageColorTools/GPUImage to enjoy the same methods with data coming from GPUImageFramebuffer objects.

###SYImageColorGetter

Pretty straightforward class, to access pixels of an image. Its only goal is to keep the image data in memory so that if you have multiple pixels to get you reduce the buffer allocation overhead.

@interface SYImageColorGetter : NSObject

- (instancetype)initWithImage:(UIImage *)image;

- (UIColor *)getColorAtPoint:(CGPoint)point;
- (CGFloat)getRedAtPoint:(CGPoint)point;
- (CGFloat)getGreenAtPoint:(CGPoint)point;
- (CGFloat)getBlueAtPoint:(CGPoint)point;
- (CGFloat)getAlphaAtPoint:(CGPoint)point;

@end

###SYImageColorTools

Allows getting pixels value from a buffer, created from an OpenGL texture (when using GPUImage for instance) or an UIImage

It defines multiple types:

  • SYPixel: struct containing r, g, b and a data for a pixel
  • SYImageInfo: struct containing the required information about the buffer to understand it; used by SYImageGetPixelValue and SYImageDetermineEdgeInsetsToTrimTransparentPixels

Here is the header:

typedef struct {
    CGFloat r;
    CGFloat g;
    CGFloat b;
    CGFloat a;
} SYPixel;

typedef struct {
    NSUInteger width;
    NSUInteger height;
    NSUInteger bytesPerRow;
    BOOL alphaOnly;
    BOOL alphaFirst;
    BOOL alphaPremultiplied;
    BOOL bigEndian;
} SYImageInfo;

// Create a basic SYImageInfo struct for a GPUImage based buffer 
SYImageInfo SYImageInfoCreateForOpenGLTexture(NSUInteger w, NSUInteger h);

// Get pixel value in a given buffer, understandable with the SYImageInfo parameter
SYPixel SYImageGetPixelValue(const uint8_t *data, SYImageInfo info, NSUInteger x, NSUInteger y, BOOL onlyAlpha);

// Returns the number of lines and columns to remove from the image on each side to remove all completely transparent lines
UIEdgeInsets SYImageDetermineEdgeInsetsToTrimTransparentPixels(const uint8_t *data, SYImageInfo imageInfo, CGFloat maxAlpha);

###UIColor+SYImageColorTools

Simple category to create a UIColor from a SYPixel struct

@interface UIColor (SYImageColorTools)

+ (UIColor *)colorWithSYPixel:(SYPixel)pixel;

@end

###UIImage+SYImageColorTools

Category bringing higher level methods for SYImageColorTools functions

@interface UIImage (SYImageColorTools)

- (SYImageInfo)imageInfo;
- (UIColor *)colorAtPoint:(CGPoint)pixelPoint;
- (UIImage *)imageByTrimmingTransparentPixels;

@end

#SYImageColorTools/GPUImage

Additions to GPUImage to work with SYImageColorTools allowing you to read data from then OpenGL buffer of a filter.

###GPUImageFramebuffer+SYImageColorTools

Helps using SYImageColorTools with GPUImageFramebuffer by obtaining a buffer and the appriopriate image info.

typedef void(^SYImageBytesBlock)(GLubyte *bytes, SYImageInfo info);

@interface GPUImageFramebuffer (SYImageColorTools)

- (void)getBytes:(SYImageBytesBlock)block;

@end

###SYGPUImageFilterWhiteSpaceTrimmer

GPUImage filter that will compute the crop region each time it has the chance, and give you access to those values. The computation is done on the CPU since I wouldn't know how to it and the crop on the GPU. The crop isn't done at all, you will need to use the lastComputedCropRegion property to crop it yourself. Sorry ¯\(ツ)

@interface SYGPUImageFilterWhiteSpaceTrimmer : GPUImageFilter

@property (nonatomic, assign) CGFloat maxAlpha;
@property (nonatomic, assign) CGRect lastComputedCropRegion;
@property (nonatomic, assign) CGRect lastComputedCropRegionNormalized;
@property (nonatomic, assign) BOOL cropRegionDefined;

@end

syimagecolortools's People

Contributors

dvkch avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.