├── Classes ├── CustomImagePicker.h ├── CustomImagePicker.m ├── CustomImagePickerAppDelegate.h ├── CustomImagePickerAppDelegate.m ├── CustomImagePickerViewController.h ├── CustomImagePickerViewController.mm ├── UIImageExtras.h ├── UIImageExtras.m └── imageFilter │ ├── AutoAdjustFilter.h │ ├── AutoLevelFilter.h │ ├── BannerFilter.h │ ├── BigBrotherFilter.h │ ├── BlackWhiteFilter.h │ ├── BlindFilter.h │ ├── BlockPrintFilter.h │ ├── BrickFilter.h │ ├── BrightContrastFilter.h │ ├── CleanGlassFilter.h │ ├── ColorQuantizeFilter.h │ ├── ColorToneFilter.h │ ├── ComicFilter.h │ ├── ConvolutionFilter.h │ ├── Distort │ ├── BilinearDistort.h │ ├── BulgeFilter.h │ ├── RippleFilter.h │ ├── TwistFilter.h │ └── WaveFilter.h │ ├── EdgeFilter.h │ ├── FeatherFilter.h │ ├── FillPatternFilter.h │ ├── FilmFilter.h │ ├── FocusFilter.h │ ├── GaussianBlurFilter.h │ ├── GradientFilter.h │ ├── GradientMapFilter.h │ ├── HistogramEqualFilter.h │ ├── HslColor.h │ ├── HslModifyFilter.h │ ├── IImageFilter.h │ ├── IllusionFilter.h │ ├── Image.h │ ├── ImageBlender.h │ ├── InvertFilter.h │ ├── LensFlareFilter.h │ ├── LightFilter.h │ ├── LomoFilter.h │ ├── MirrorFilter.h │ ├── MistFilter.h │ ├── MonitorFilter.h │ ├── MosaicFilter.h │ ├── NeonFilter.h │ ├── NightVisionFilter.h │ ├── NoiseFilter.h │ ├── OilPaintFilter.h │ ├── OldPhotoFilter.h │ ├── PaintBorderFilter.h │ ├── ParamEdgeDetectFilter.h │ ├── PixelateFilter.h │ ├── PosterizeFilter.h │ ├── RadialDistortionFilter.h │ ├── RainBowFilter.h │ ├── RaiseFrameFilter.h │ ├── RectMatrixFilter.h │ ├── ReflectionFilter.h │ ├── ReliefFilter.h │ ├── SaturationModifyFilter.h │ ├── SceneFilter.h │ ├── SepiaFilter.h │ ├── SharpFilter.h │ ├── ShiftFilter.h │ ├── SmashColorFilter.h │ ├── SoftGlowFilter.h │ ├── SupernovaFilter.h │ ├── Textures │ ├── CloudsTexture.h │ ├── ITextureGenerator.h │ ├── LabyrinthTexture.h │ ├── MarbleTexture.h │ ├── PerlinNoise.h │ ├── TextileTexture.h │ ├── TexturerFilter.h │ └── WoodTexture.h │ ├── ThreeDGridFilter.h │ ├── ThresholdFilter.h │ ├── TileReflectionFilter.h │ ├── TintFilter.h │ ├── VideoFilter.h │ ├── VignetteFilter.h │ ├── VintageFilter.h │ ├── WaterWaveFilter.h │ ├── XRadiationFilter.h │ ├── YCBCrLinearFilter.h │ └── ZoomBlurFilter.h ├── CustomImagePicker-Info.plist ├── CustomImagePicker.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── daizhenjun.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── rwenderlich.pbxuser ├── rwenderlich.perspectivev3 └── xcuserdata │ └── daizhenjun.xcuserdatad │ ├── xcdebugger │ └── Breakpoints.xcbkptlist │ └── xcschemes │ ├── CustomImagePicker.xcscheme │ └── xcschememanagement.plist ├── CustomImagePickerViewController.xib ├── CustomImagePicker_Prefix.pch ├── Koala.jpg ├── MainWindow.xib ├── README.md ├── icon ├── autoadjust_filter.jpg ├── banner_filter1.jpg ├── banner_filter2.jpg ├── bigbrother_filter.jpg ├── blackwhite_filter.jpg ├── blind_filter1.jpg ├── blind_filter2.jpg ├── blockprint_filter.jpg ├── brick_filter.jpg ├── brightcontrast_filter.jpg ├── bulge_filter.jpg ├── camera.png ├── colorquantize_filter.jpg ├── colortone_filter.jpg ├── colortone_filter2.jpg ├── colortone_filter3.jpg ├── colortone_filter4.jpg ├── edge_filter.jpg ├── feather_filter.jpg ├── fillpattern_filter.jpg ├── fillpattern_filter1.jpg ├── gamma_filter.jpg ├── gaussianblur_filter.jpg ├── hslmodify_filter.jpg ├── hslmodify_filter0.jpg ├── hslmodify_filter1.jpg ├── hslmodify_filter2.jpg ├── hslmodify_filter3.jpg ├── hslmodify_filter4.jpg ├── hslmodify_filter5.jpg ├── hslmodify_filter6.jpg ├── hslmodify_filter7.jpg ├── illusion_filter.jpg ├── invert_filter.jpg ├── lensflare_filter.jpg ├── light_filter.jpg ├── mirror_filter1.jpg ├── mirror_filter2.jpg ├── mist_filter.jpg ├── monitor_filter.jpg ├── mosaic_filter.jpg ├── neon_filter.jpg ├── nightvision_filter.jpg ├── noisefilter.jpg ├── oilpaint_filter.jpg ├── oldphoto_filter.jpg ├── pixelate_filter.jpg ├── posterize_filter.jpg ├── radialdistortion_filter.jpg ├── rainbow_filter.jpg ├── raiseframe_filter.jpg ├── rectmatrix_filter.jpg ├── reflection1_filter.jpg ├── reflection2_filter.jpg ├── relief_filter.jpg ├── ripple_filter.jpg ├── saturationmodify_filter.jpg ├── save.png ├── search.png ├── sepia_filter.jpg ├── sharp_filter.jpg ├── shift_filter.jpg ├── smashcolor_filter.jpg ├── softglow_filter.jpg ├── supernova_filter.jpg ├── texture1.png ├── texture2.png ├── texturer_filter.jpg ├── texturer_filter1.jpg ├── texturer_filter2.jpg ├── texturer_filter3.jpg ├── texturer_filter4.jpg ├── threedgrid_filter.jpg ├── threshold_filter.jpg ├── tilereflection_filter.jpg ├── tilereflection_filter1.jpg ├── tilereflection_filter2.jpg ├── tint_filter.jpg ├── twist_filter.jpg ├── video_filter1.jpg ├── video_filter2.jpg ├── video_filter3.jpg ├── video_filter4.jpg ├── vignette_filter.jpg ├── vintage_filter.jpg ├── waterwave_filter.jpg ├── wave_filter.jpg ├── xradiation_filter.jpg ├── ycb_crlinear_filter.jpg ├── ycb_crlinear_filter2.jpg └── zoomblur_filter.jpg ├── logo1.png ├── logo2.png └── main.m /Classes/CustomImagePicker.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomImagePicker.h 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright 2010 Ray Wenderlich. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomImagePicker : UIViewController { 12 | 13 | } 14 | 15 | @property (nonatomic, retain) NSMutableArray *images; 16 | @property (nonatomic, retain) NSMutableArray *thumbs; 17 | //@property (nonatomic, retain) UIImage *selectedImage; 18 | @property (nonatomic) NSInteger filterName; 19 | 20 | 21 | - (IBAction)buttonClicked:(id)sender; 22 | - (IBAction)cancel:(id)sender; 23 | - (void)addImage:(UIImage *)image; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Classes/CustomImagePicker.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomImagePicker.m 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright 2010 Ray Wenderlich. All rights reserved. 7 | // 8 | 9 | #import "CustomImagePicker.h" 10 | #import "CustomImagePickerAppDelegate.h" 11 | #import "UIImageExtras.h" 12 | 13 | @implementation CustomImagePicker 14 | @synthesize images = _images; 15 | @synthesize thumbs = _thumbs; 16 | @synthesize filterName = _filterName; 17 | 18 | - (id) init { 19 | if ((self = [super init])) { 20 | _images = [[NSMutableArray alloc] init]; 21 | _thumbs = [[NSMutableArray alloc] init]; 22 | _filterName = -1; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)addImage:(UIImage *)image { 28 | [_images addObject:image]; 29 | [_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(64, 64)]]; 30 | } 31 | 32 | - (void)viewDidLoad { 33 | 34 | // Create view 35 | UIScrollView *view = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 36 | 37 | int row = 0; 38 | int column = 0; 39 | for(int i = 0; i < _thumbs.count; ++i) { 40 | 41 | UIImage *thumb = [_thumbs objectAtIndex:i]; 42 | UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; 43 | button.frame = CGRectMake(column*100+24, row*80+10, 64, 64); 44 | [button setImage:thumb forState:UIControlStateNormal]; 45 | [button addTarget:self 46 | action:@selector(buttonClicked:) 47 | forControlEvents:UIControlEventTouchUpInside]; 48 | button.tag = i; 49 | [view addSubview:button]; 50 | 51 | if (column == 2) { 52 | column = 0; 53 | row++; 54 | } else { 55 | column++; 56 | } 57 | 58 | } 59 | 60 | [view setContentSize:CGSizeMake(320, (row+1) * 80 + 10)]; 61 | 62 | self.view = view; 63 | [view release]; 64 | 65 | // Create cancel button 66 | UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] 67 | initWithTitle:@"取消" 68 | style:UIBarButtonItemStylePlain 69 | target:self 70 | action:@selector(cancel:)]; 71 | self.navigationItem.leftBarButtonItem = cancelButton; 72 | [cancelButton release]; 73 | 74 | [super viewDidLoad]; 75 | } 76 | 77 | 78 | - (IBAction)buttonClicked:(id)sender { 79 | UIButton *button = (UIButton *)sender; 80 | //self.selectedImage = [_images objectAtIndex:button.tag]; 81 | self.filterName = button.tag;//@"INVERT"; 82 | CustomImagePickerAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 83 | [delegate.navController popViewControllerAnimated:YES]; 84 | } 85 | 86 | - (IBAction)cancel:(id)sender { 87 | self.filterName = -1; 88 | CustomImagePickerAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 89 | [delegate.navController popViewControllerAnimated:YES]; 90 | } 91 | 92 | - (void)didReceiveMemoryWarning { 93 | [super didReceiveMemoryWarning]; 94 | } 95 | 96 | - (void)viewDidUnload { 97 | } 98 | 99 | - (void)dealloc { 100 | self.images = nil; 101 | self.thumbs = nil; 102 | //self.selectedImage = nil; 103 | //self.filterName = nil; 104 | [super dealloc]; 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /Classes/CustomImagePickerAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomImagePickerAppDelegate.h 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright Ray Wenderlich 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CustomImagePickerViewController; 12 | 13 | @interface CustomImagePickerAppDelegate : NSObject { 14 | UIWindow *window; 15 | UINavigationController *navController; 16 | } 17 | 18 | @property (nonatomic, retain) IBOutlet UIWindow *window; 19 | @property (nonatomic, retain) IBOutlet UINavigationController *navController; 20 | 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /Classes/CustomImagePickerAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomImagePickerAppDelegate.m 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright Ray Wenderlich 2010. All rights reserved. 7 | // 8 | 9 | #import "CustomImagePickerAppDelegate.h" 10 | #import "CustomImagePickerViewController.h" 11 | 12 | @implementation CustomImagePickerAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize navController; 16 | 17 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 18 | 19 | // Override point for customization after app launch 20 | [window addSubview:navController.view]; 21 | [window makeKeyAndVisible]; 22 | } 23 | 24 | 25 | - (void)dealloc { 26 | [navController release]; 27 | [window release]; 28 | [super dealloc]; 29 | } 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Classes/CustomImagePickerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomImagePickerViewController.h 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright Ray Wenderlich 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CustomImagePicker; 12 | 13 | @interface CustomImagePickerViewController : UIViewController { 14 | UIImageView *_imageView; 15 | CustomImagePicker *_imagePicker; 16 | } 17 | 18 | @property (nonatomic, retain) IBOutlet UIImageView *imageView; 19 | @property (nonatomic, retain) CustomImagePicker *imagePicker; 20 | 21 | - (IBAction)chooseCustomImageTapped:(id)sender; 22 | 23 | @end 24 | 25 | -------------------------------------------------------------------------------- /Classes/UIImageExtras.h: -------------------------------------------------------------------------------- 1 | // From cscade on iphonedevbook.com forums 2 | // And Bjorn Sallarp on blog.sallarp.com 3 | 4 | @interface UIImage (Extras) 5 | 6 | - (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /Classes/UIImageExtras.m: -------------------------------------------------------------------------------- 1 | #import "UIImageExtras.h" 2 | 3 | @implementation UIImage (Extras) 4 | 5 | - (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize 6 | { 7 | UIImage *sourceImage = self; 8 | UIImage *newImage = nil; 9 | CGSize imageSize = sourceImage.size; 10 | CGFloat width = imageSize.width; 11 | CGFloat height = imageSize.height; 12 | CGFloat targetWidth = targetSize.width; 13 | CGFloat targetHeight = targetSize.height; 14 | CGFloat scaleFactor = 0.0; 15 | CGFloat scaledWidth = targetWidth; 16 | CGFloat scaledHeight = targetHeight; 17 | CGPoint thumbnailPoint = CGPointMake(0.0,0.0); 18 | 19 | if (CGSizeEqualToSize(imageSize, targetSize) == NO) 20 | { 21 | CGFloat widthFactor = targetWidth / width; 22 | CGFloat heightFactor = targetHeight / height; 23 | 24 | if (widthFactor > heightFactor) 25 | scaleFactor = widthFactor; // scale to fit height 26 | else 27 | scaleFactor = heightFactor; // scale to fit width 28 | scaledWidth = width * scaleFactor; 29 | scaledHeight = height * scaleFactor; 30 | 31 | // center the image 32 | if (widthFactor > heightFactor) 33 | { 34 | thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; 35 | } 36 | else 37 | if (widthFactor < heightFactor) 38 | { 39 | thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; 40 | } 41 | } 42 | 43 | UIGraphicsBeginImageContext(targetSize); // this will crop 44 | 45 | CGRect thumbnailRect = CGRectZero; 46 | thumbnailRect.origin = thumbnailPoint; 47 | thumbnailRect.size.width = scaledWidth; 48 | thumbnailRect.size.height = scaledHeight; 49 | 50 | [sourceImage drawInRect:thumbnailRect]; 51 | 52 | newImage = UIGraphicsGetImageFromCurrentImageContext(); 53 | if(newImage == nil) 54 | NSLog(@"could not scale image"); 55 | 56 | //pop the context to get back to the default 57 | UIGraphicsEndImageContext(); 58 | return newImage; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Classes/imageFilter/AutoAdjustFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(AutoAdjustFilter_H) 20 | #define AutoAdjustFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class AutoAdjustFilter : public IImageFilter{ 28 | public: 29 | virtual Image process(Image image) { 30 | HistogramEqualFilter hee = new HistogramEqualFilter(); 31 | hee.ContrastIntensity = 0.5f; 32 | image = hee.process(image); 33 | 34 | AutoLevelFilter ale = new AutoLevelFilter(); 35 | ale.Intensity = 0.5f; 36 | return ale.process(image); 37 | } 38 | }; 39 | 40 | }// namespace HaoRan 41 | 42 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/AutoLevelFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/AutoLevelFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/BannerFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/BannerFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/BigBrotherFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(BigBrotherFilter_H) 20 | #define BigBrotherFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | #include 25 | 26 | using namespace std; 27 | 28 | namespace HaoRan_ImageFilter{ 29 | 30 | class BigBrotherFilter : public IImageFilter{ 31 | 32 | private: 33 | int DOT_AREA; 34 | 35 | void drawTone(int a_x, int a_y, Image imageIn, int arrDither[]){ 36 | int l_grayIntensity; 37 | int l_x; 38 | int l_y; 39 | 40 | for(int x=0; x arrDither[x]){ 48 | imageIn.setPixelColor(a_x+l_x, a_y+l_y, 0,0,0); 49 | } 50 | else{ 51 | imageIn.setPixelColor(a_x+l_x, a_y+l_y, 255,255,255); 52 | } 53 | } 54 | } 55 | } 56 | 57 | public: 58 | 59 | BigBrotherFilter() : DOT_AREA(10){ }; 60 | 61 | virtual Image process(Image imageIn) 62 | { 63 | int arrDither[] = { 64 | 167,200,230,216,181, 65 | 94,72,193,242,232, 66 | 36,52,222,167,200, 67 | 181,126,210,94,72, 68 | 232,153,111,36,52, 69 | 167,200,230,216,181, 70 | 94,72,193,242,232, 71 | 36,52,222,167,200, 72 | 181,126,210,94,72, 73 | 232,153,111,36,52, 74 | 167,200,230,216,181, 75 | 94,72,193,242,232, 76 | 36,52,222,167,200, 77 | 181,126,210,94,72, 78 | 232,153,111,36,52, 79 | 167,200,230,216,181, 80 | 94,72,193,242,232, 81 | 36,52,222,167,200, 82 | 181,126,210,94,72, 83 | 232,153,111,36,52 84 | }; 85 | 86 | for (int x = 0; x < imageIn.getWidth(); x+=DOT_AREA) { 87 | for (int y = 0; y < imageIn.getHeight(); y+=DOT_AREA) { 88 | drawTone(x,y,imageIn, arrDither); 89 | } 90 | } 91 | #ifndef WIN32 //only for apple ios 92 | imageIn.copyPixelsFromBuffer(); 93 | #endif 94 | return imageIn; 95 | } 96 | }; 97 | 98 | }// namespace HaoRan 99 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/BlackWhiteFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(BlackWhiteFilter_H) 20 | #define BlackWhiteFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class BlackWhiteFilter : public IImageFilter{ 27 | public: 28 | BlackWhiteFilter(){}; 29 | virtual Image process(Image imageIn) 30 | { 31 | int r,g,b,corfinal; 32 | for (int x = 0; x < imageIn.getWidth(); x++) { 33 | for (int y = 0; y < imageIn.getHeight(); y++) { 34 | r = imageIn.getRComponent(x, y); 35 | g = imageIn.getGComponent(x, y); 36 | b = imageIn.getBComponent(x, y); 37 | corfinal = (int)((r*0.3)+(b*0.59)+(g*0.11)); 38 | imageIn.setPixelColor(x,y,corfinal,corfinal,corfinal); 39 | } 40 | } 41 | #ifndef WIN32 //only for apple ios 42 | imageIn.copyPixelsFromBuffer(); 43 | #endif 44 | return imageIn; 45 | 46 | } 47 | }; 48 | 49 | }// namespace HaoRan 50 | 51 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/BlindFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(BlindFilter_H) 20 | #define BlindFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class BlindFilter : public IImageFilter{ 28 | 29 | private: 30 | bool _direct;//horizontal: true, vertical: false 31 | int _color; 32 | int _opacity; 33 | int _width; 34 | 35 | public: 36 | 37 | 38 | BlindFilter(bool direct, int width, int opacity, int blindColor) 39 | { 40 | _direct = direct ; 41 | _width = (width >= 2) ? width : 2; 42 | _opacity = FClamp (opacity, 1, 100); 43 | _color = blindColor; 44 | }; 45 | 46 | 47 | virtual Image process(Image imageIn) 48 | { 49 | int r, g, b, a; 50 | for(int x = 0 ; x < (imageIn.getWidth() - 1) ; x++){ 51 | for(int y = 0 ; y < (imageIn.getHeight() - 1) ; y++){ 52 | r = imageIn.getRComponent(x, y); 53 | g = imageIn.getGComponent(x, y); 54 | b = imageIn.getBComponent(x, y); 55 | int nMod = 0 ; 56 | if (_direct) // horizontal direction 57 | nMod = y % _width ; 58 | else if (_direct == false) // vertical direction 59 | nMod = x % _width ; 60 | 61 | double fDelta = 255.0 * (_opacity/100.0) / (_width-1.0); 62 | a = FClamp0255(nMod * fDelta) ; 63 | Color color(_color); 64 | if (_color == 0xFF) 65 | { 66 | imageIn.setPixelColor(x, y, color.R, color.G, color.B); 67 | continue ; 68 | } 69 | if (a == 0) 70 | continue ; 71 | 72 | int t = 0xFF - a ; 73 | imageIn.setPixelColor(x, y, (color.R * a + r * t) / 0xFF, (color.G * a + g * t) / 0xFF, (color.B * a + b * t) / 0xFF); 74 | } 75 | } 76 | #ifndef WIN32 //only for apple ios 77 | imageIn.copyPixelsFromBuffer(); 78 | #endif 79 | return imageIn; 80 | } 81 | }; 82 | 83 | }// namespace HaoRan 84 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/BlockPrintFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #include "ParamEdgeDetectFilter.h" 20 | #include "ImageBlender.h" 21 | 22 | #if !defined(BlockPrintFilter_H) 23 | #define BlockPrintFilter_H 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class BlockPrintFilter : public IImageFilter{ 28 | public: 29 | BlockPrintFilter(){}; 30 | virtual Image process(Image imageIn) 31 | { 32 | ParamEdgeDetectFilter pde; 33 | pde.K00 = 1; 34 | pde.K01 = 2; 35 | pde.K02 = 1; 36 | pde.Threshold = 0.25f; 37 | pde.DoGrayConversion = false; 38 | ImageBlender ib; 39 | ib.Mode = ::Multiply; 40 | return ib.Blend(imageIn.clone(), pde.process(imageIn)); 41 | } 42 | }; 43 | 44 | }// namespace HaoRan 45 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/BrickFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | 20 | #if !defined(BrickFilter_H) 21 | #define BrickFilter_H 22 | 23 | #include "IImageFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class BrickFilter : public IImageFilter{ 28 | public: 29 | int ThreshHold; 30 | 31 | BrickFilter(): ThreshHold(128){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int width = imageIn.getWidth(); 36 | int height = imageIn.getHeight(); 37 | Image clone = imageIn.clone(); 38 | int r = 0, g = 0, b = 0, avg = 0; 39 | for (int x = 0; x < width; x++) { 40 | for (int y = 0; y < height; y++) { 41 | r = clone.getRComponent(x, y); 42 | g = clone.getGComponent(x, y); 43 | b = clone.getBComponent(x, y); 44 | avg = (r + g + b) / 3; 45 | avg = avg >= ThreshHold ? 255 : 0; 46 | imageIn.setPixelColor(x, y, avg, avg, avg); 47 | } 48 | } 49 | #ifndef WIN32 //only for apple ios 50 | imageIn.copyPixelsFromBuffer(); 51 | #endif 52 | return imageIn; 53 | } 54 | }; 55 | 56 | }// namespace HaoRan 57 | 58 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/BrightContrastFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(BrightContrastFilter_H) 19 | #define BrightContrastFilter_H 20 | 21 | #include "IImageFilter.h" 22 | 23 | namespace HaoRan_ImageFilter{ 24 | 25 | class BrightContrastFilter : public IImageFilter{ 26 | 27 | public: 28 | /// The brightness factor. 29 | /// Should be in the range [-1, 1]. 30 | float BrightnessFactor; 31 | 32 | /// The contrast factor. 33 | /// Should be in the range [-1, 1]. 34 | float ContrastFactor; 35 | 36 | BrightContrastFilter():BrightnessFactor(0.25f), ContrastFactor(0){}; 37 | 38 | //@Override 39 | virtual Image process(Image imageIn) 40 | { 41 | int r, g, b; 42 | // Convert to integer factors 43 | int bfi = (int)(BrightnessFactor * 255); 44 | float cf = 1 + ContrastFactor; 45 | cf *= cf; 46 | int cfi = (int)(cf * 32768) + 1; 47 | for (int x = 0; x < imageIn.getWidth(); x++) 48 | { 49 | for (int y = 0; y < imageIn.getHeight(); y++) 50 | { 51 | r = imageIn.getRComponent(x, y); 52 | g = imageIn.getGComponent(x, y); 53 | b = imageIn.getBComponent(x, y); 54 | // Modify brightness (addition) 55 | if (bfi != 0) 56 | { 57 | // Add brightness 58 | int ri = r + bfi; 59 | int gi = g + bfi; 60 | int bi = b + bfi; 61 | // Clamp to byte boundaries 62 | r = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri)); 63 | g = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi)); 64 | b = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi)); 65 | } 66 | // Modifiy contrast (multiplication) 67 | if (cfi != 32769) 68 | { 69 | // Transform to range [-128, 127] 70 | int ri = r - 128; 71 | int gi = g - 128; 72 | int bi = b - 128; 73 | 74 | // Multiply contrast factor 75 | ri = (ri * cfi) >> 15; 76 | gi = (gi * cfi) >> 15; 77 | bi = (bi * cfi) >> 15; 78 | 79 | // Transform back to range [0, 255] 80 | ri = ri + 128; 81 | gi = gi + 128; 82 | bi = bi + 128; 83 | 84 | // Clamp to byte boundaries 85 | r = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri)); 86 | g = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi)); 87 | b = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi)); 88 | } 89 | imageIn.setPixelColor(x, y, r, g, b); 90 | } 91 | } 92 | #ifndef WIN32 //only for apple ios 93 | imageIn.copyPixelsFromBuffer(); 94 | #endif 95 | return imageIn; 96 | } 97 | }; 98 | }// namespace HaoRan 99 | 100 | 101 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/CleanGlassFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/CleanGlassFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/ColorQuantizeFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ColorQuantizeFilter_H) 20 | #define ColorQuantizeFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class ColorQuantizeFilter : public IImageFilter{ 27 | private: 28 | float levels; 29 | 30 | public: 31 | ColorQuantizeFilter(): levels(5){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int r, g, b; 36 | for (int x = 0; x < imageIn.getWidth(); x++) { 37 | for (int y = 0; y < imageIn.getHeight(); y++) { 38 | r = imageIn.getRComponent(x, y); 39 | g = imageIn.getGComponent(x, y); 40 | b = imageIn.getBComponent(x, y); 41 | float quanR = (((float) ((int) (r * 0.003921569 * levels))) / levels) * 255; 42 | float quanG = (((float) ((int) (g * 0.003921569 * levels))) / levels) * 255; 43 | float quanB = (((float) ((int) (b * 0.003921569 * levels))) / levels) * 255; 44 | r = (quanR > 255) ? 255 : ((quanR < 0) ? 0 : ((byte) quanR)); 45 | g = (quanG > 255) ? 255 : ((quanG < 0) ? 0 : ((byte) quanG)); 46 | b = (quanB > 255) ? 255 : ((quanB < 0) ? 0: ((byte) quanB)); 47 | imageIn.setPixelColor(x,y,r,g,b); 48 | } 49 | } 50 | #ifndef WIN32 //only for apple ios 51 | imageIn.copyPixelsFromBuffer(); 52 | #endif 53 | return imageIn; 54 | } 55 | }; 56 | 57 | }// namespace HaoRan 58 | 59 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ColorToneFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ColorToneFilter_H) 20 | #define ColorToneFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class ColorToneFilter : public IImageFilter{ 28 | 29 | private: 30 | double _hue ; 31 | double _saturation ; 32 | double _lum_tab[256] ; 33 | 34 | public: 35 | /// @name RGB <--> HLS (Hue, Lightness, Saturation). 36 | //@{ 37 | /** 38 | RGB --> HLS \n 39 | prgb - address of 24bpp or 32bpp pixel. 40 | */ 41 | static void RGBtoHLS (int rgb, double& H, double& L, double& S) 42 | { 43 | Color color(rgb); 44 | int n_cmax = max(color.R, max(color.G, color.B)); 45 | int n_cmin = min(color.R, min(color.G, color.B)); 46 | 47 | L = (n_cmax + n_cmin) / 2.0 / 255.0 ; 48 | 49 | if (n_cmax == n_cmin) 50 | { 51 | S = H = 0.0 ; 52 | return ; 53 | } 54 | 55 | double r = color.R / 255.0, 56 | g = color.G / 255.0, 57 | b = color.B / 255.0, 58 | cmax = n_cmax / 255.0, 59 | cmin = n_cmin / 255.0, 60 | delta = cmax - cmin ; 61 | 62 | if (L < 0.5) 63 | S = delta / (cmax + cmin) ; 64 | else 65 | S = delta / (2.0 - cmax - cmin) ; 66 | 67 | if (color.R == n_cmax) 68 | H = (g-b) / delta ; 69 | else if (color.G == n_cmax) 70 | H = 2.0 + (b-r) / delta ; 71 | else 72 | H = 4.0 + (r-g) / delta ; 73 | 74 | H /= 6.0 ; 75 | 76 | if (H < 0.0) 77 | H += 1.0 ; 78 | } 79 | 80 | static int DoubleRGB_to_RGB (double r, double g, double b) 81 | { 82 | return Color::rgb(SAFECOLOR(r*255), SAFECOLOR(g*255), SAFECOLOR(b*255)) ; 83 | } 84 | 85 | static double HLS_Value (double n1, double n2, double h) 86 | { 87 | if (h > 6.0) 88 | h -= 6.0 ; 89 | else if (h < 0.0) 90 | h += 6.0 ; 91 | 92 | if (h < 1.0) 93 | return n1 + (n2 - n1) * h ; 94 | else if (h < 3.0) 95 | return n2 ; 96 | else if (h < 4.0) 97 | return n1 + (n2 - n1) * (4.0 - h) ; 98 | return n1 ; 99 | } 100 | 101 | /// HLS --> RGB. 102 | static int HLStoRGB (double H, double L, double S) 103 | { 104 | if ((!(S > 0)) && (!(S < 0))) // == 0 105 | return DoubleRGB_to_RGB (L, L, L) ; 106 | 107 | double m1, m2 ; 108 | if (L > 0.5) 109 | m2 = L + S - L*S ; 110 | else 111 | m2 = L * (1.0 + S) ; 112 | m1 = 2.0*L - m2 ; 113 | 114 | double r = HLS_Value (m1, m2, H*6.0 + 2.0) ; 115 | double g = HLS_Value (m1, m2, H*6.0) ; 116 | double b = HLS_Value (m1, m2, H*6.0 - 2.0) ; 117 | return DoubleRGB_to_RGB (r,g,b) ; 118 | } 119 | 120 | 121 | /** 122 | Calculate grayscale value of pixel \n 123 | prgb - address of 24bpp or 32bpp pixel. 124 | */ 125 | static int GetGrayscale (int r, int g , int b) 126 | { 127 | return (int)((30*r + 59*g + 11*g) / 100) ; 128 | } 129 | 130 | ColorToneFilter(int tone, int saturation) 131 | { 132 | double l ; 133 | RGBtoHLS (tone, _hue, l, _saturation) ; 134 | 135 | _saturation = _saturation * (saturation/255.0) * (saturation/255.0) ; 136 | _saturation = ((_saturation < 1) ? _saturation : 1) ; 137 | 138 | for (int i=0 ; i < 256 ; i++) 139 | { 140 | int cr = Color::rgb(i,i,i) ; 141 | double h, ll, s ; 142 | RGBtoHLS (cr, h, ll, s) ; 143 | 144 | ll = ll * (1 + (128-abs(saturation-128)) / 128.0 / 9.0) ; 145 | _lum_tab[i] = ((ll < 1) ? ll : 1) ; 146 | } 147 | }; 148 | 149 | 150 | virtual Image process(Image imageIn) 151 | { 152 | int r, g, b; 153 | for(int x = 0 ; x < imageIn.getWidth() ; x++){ 154 | for(int y = 0 ; y < imageIn.getHeight() ; y++){ 155 | r = imageIn.getRComponent(x, y); 156 | g = imageIn.getGComponent(x, y); 157 | b = imageIn.getBComponent(x, y); 158 | 159 | double l = _lum_tab[GetGrayscale(r, g, b)] ; 160 | int cr =HLStoRGB (_hue, l, _saturation) ; 161 | imageIn.setPixelColor(x, y, cr); 162 | } 163 | } 164 | #ifndef WIN32 //only for apple ios 165 | imageIn.copyPixelsFromBuffer(); 166 | #endif 167 | return imageIn; 168 | } 169 | }; 170 | 171 | }// namespace HaoRan 172 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ComicFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(ComicFilter_H) 19 | #define ComicFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "GradientFilter.h" 23 | #include "SaturationModifyFilter.h" 24 | #include "ImageBlender.h" 25 | #include "ParamEdgeDetectFilter.h" 26 | #include "GaussianBlurFilter.h" 27 | 28 | namespace HaoRan_ImageFilter{ 29 | 30 | class ComicFilter : public IImageFilter{ 31 | 32 | private: 33 | SaturationModifyFilter saturationFx; 34 | GaussianBlurFilter blurFx; 35 | ImageBlender blender; 36 | ParamEdgeDetectFilter edgeDetectionFx; 37 | ImageBlender edgeBlender; 38 | 39 | public: 40 | 41 | ComicFilter() 42 | { 43 | saturationFx.SaturationFactor = 1.0f; 44 | blurFx.Sigma = 1.0f; 45 | blender.Mixture = 1.0f; 46 | blender.Mode = ::Lighten; 47 | edgeDetectionFx.Threshold = 0.25f; 48 | edgeDetectionFx.DoGrayConversion = true; 49 | edgeBlender.Mixture = 0.8f; 50 | edgeBlender.Mode = ::Lighten; 51 | }; 52 | 53 | virtual Image process(Image imageIn) 54 | { 55 | Image saturated = saturationFx.process(imageIn.clone()); 56 | Image blurred = blurFx.process(saturated); 57 | imageIn = blender.Blend(saturated, blurred); 58 | Image edge = edgeDetectionFx.process(imageIn.clone()); 59 | imageIn = edgeBlender.Blend(imageIn, edge); 60 | 61 | #ifndef WIN32 //only for apple ios 62 | imageIn.copyPixelsFromBuffer(); 63 | #endif 64 | return imageIn; 65 | //return imageIn;// saturationFx.process(imageIn); 66 | } 67 | }; 68 | 69 | }// namespace HaoRan 70 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ConvolutionFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ConvolutionFilter_H) 20 | #define ConvolutionFilter_H 21 | 22 | 23 | #include "IImageFilter.h" 24 | 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class ConvolutionFilter : public IImageFilter{ 29 | protected: 30 | int GetPixelBrightness(Image input, int x, int y, int w, int h) 31 | { 32 | if (x < 0){ 33 | x = 0; 34 | } 35 | else if (x >= w){ 36 | x = w - 1; 37 | } 38 | if (y < 0){ 39 | y = 0; 40 | } 41 | else if (y >= h){ 42 | y = h - 1; 43 | } 44 | return ((((input.getRComponent(x, y) * 0x1b36) + (input.getGComponent(x, y) * 0x5b8c)) + (input.getBComponent(x, y) * 0x93e)) >> 15); 45 | } 46 | 47 | int GetPixelColor(Image input, int x, int y, int w, int h) 48 | { 49 | if (x < 0){ 50 | x = 0; 51 | } 52 | else if (x >= w){ 53 | x = w - 1; 54 | } 55 | if (y < 0){ 56 | y = 0; 57 | } 58 | else if (y >= h){ 59 | y = h - 1; 60 | } 61 | return (((255 << 24 | (input.getRComponent(x, y) << 16)) | (input.getGComponent(x, y) << 8)) | input.getBComponent(x, y)); 62 | } 63 | 64 | private: 65 | // Fields 66 | int factor; 67 | float kernel[3][3]; 68 | int offset; 69 | 70 | public: 71 | ConvolutionFilter(){ 72 | kernel[0][0] = 0; 73 | kernel[0][1] = 0; 74 | kernel[0][2] = 0; 75 | kernel[1][0] = 0; 76 | kernel[1][1] = 1; 77 | kernel[1][2] = 0; 78 | kernel[2][0] = 0; 79 | kernel[2][1] = 0; 80 | kernel[2][2] = 0.4f; 81 | factor = 1; 82 | offset = 1; 83 | } 84 | 85 | virtual Image process(Image imageIn) 86 | { 87 | int color; 88 | int width = imageIn.getWidth(); 89 | int height = imageIn.getHeight(); 90 | for (int x = 0; x < width; x++) 91 | { 92 | for (int y = 0; y < height; y++) 93 | { 94 | int r = 0, g = 0, b = 0; 95 | float value = kernel[0][0]; 96 | if (value != 0) 97 | { 98 | color = GetPixelColor(imageIn, x - 1, y - 1, width, height); 99 | r += ((0x00FF0000 & color) >> 16) * value; 100 | g += ((0x0000FF00 & color) >> 8) * value; 101 | b += (0x000000FF & color) * value; 102 | } 103 | value = kernel[0][1]; 104 | if (value != 0) 105 | { 106 | color = GetPixelColor(imageIn, x, y - 1, width, height); 107 | r += ((0x00FF0000 & color) >> 16) * value; 108 | g += ((0x0000FF00 & color) >> 8) * value; 109 | b += (0x000000FF & color) * value; 110 | } 111 | value = kernel[0][2]; 112 | if (value != 0) 113 | { 114 | color = GetPixelColor(imageIn, x + 1, y - 1, width, height); 115 | r += ((0x00FF0000 & color) >> 16) * value; 116 | g += ((0x0000FF00 & color) >> 8) * value; 117 | b += (0x000000FF & color) * value; 118 | } 119 | value = kernel[1][0]; 120 | if (value != 0) 121 | { 122 | color = GetPixelColor(imageIn, x - 1, y, width, height); 123 | r += ((0x00FF0000 & color) >> 16) * value; 124 | g += ((0x0000FF00 & color) >> 8) * value; 125 | b += (0x000000FF & color) * value; 126 | } 127 | value = kernel[1][1]; 128 | if (value != 0) 129 | { 130 | color = GetPixelColor(imageIn, x, y, width, height); 131 | r += ((0x00FF0000 & color) >> 0x10) * value; 132 | g += ((0x0000FF00 & color) >> 8) * value; 133 | b += (0x000000FF & color) * value; 134 | } 135 | value = kernel[1][2]; 136 | if (value != 0) 137 | { 138 | color = GetPixelColor(imageIn, x + 1, y, width, height); 139 | r += ((0x00FF0000 & color) >> 16) * value; 140 | g += ((0x0000FF00 & color) >> 8) * value; 141 | b += (0x000000FF & color) * value; 142 | } 143 | value = kernel[2][0]; 144 | if (value != 0) 145 | { 146 | color = GetPixelColor(imageIn, x - 1, y + 1, width, height); 147 | r += ((0x00FF0000 & color) >> 16) * value; 148 | g += ((0x0000FF00 & color) >> 8) * value; 149 | b += (0x000000FF & color) * value; 150 | } 151 | value = kernel[2][1]; 152 | if (value != 0) 153 | { 154 | color = GetPixelColor(imageIn, x, y + 1, width, height); 155 | r += ((0x00FF0000 & color) >> 16) * value; 156 | g += ((0x0000FF00 & color) >> 8) * value; 157 | b += (0x000000FF & color) * value; 158 | } 159 | value = kernel[2][2]; 160 | if (value != 0) { 161 | color = GetPixelColor(imageIn, x + 1, y + 1, width, height); 162 | r += ((0x00FF0000 & color) >> 16) * value; 163 | g += ((0x0000FF00 & color) >> 8) * value; 164 | b += (0x000000FF & color) * value; 165 | } 166 | r = (r / factor) + offset; 167 | g = (g / factor) + offset; 168 | b = (b / factor) + offset; 169 | if (r < 0){ 170 | r = 0; 171 | } 172 | if (r > 0xff){ 173 | r = 0xff; 174 | } 175 | if (b < 0) { 176 | b = 0; 177 | } 178 | if (b > 0xff){ 179 | b = 0xff; 180 | } 181 | if (g < 0){ 182 | g = 0; 183 | } 184 | if (g > 0xff){ 185 | g = 0xff; 186 | } 187 | imageIn.setPixelColor(x,y,r,g,b); 188 | } 189 | } 190 | #ifndef WIN32 //only for apple ios 191 | imageIn.copyPixelsFromBuffer(); 192 | #endif 193 | return imageIn; 194 | } 195 | }; 196 | 197 | }// namespace HaoRan 198 | 199 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Distort/BilinearDistort.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(BilinearDistort_H) 20 | #define BilinearDistort_H 21 | 22 | #include "../Image.h" 23 | #include "../GradientFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class BilinearDistort : public IImageFilter{ 28 | protected: 29 | Image clone; 30 | 31 | public: 32 | BilinearDistort(){}; 33 | 34 | virtual void calc_undistorted_coord (int x, int y, double& un_x, double& un_y) =0 ; 35 | 36 | 37 | bool IsInside (int width , int height, int x, int y) const { 38 | return (x>=0) && (x=0) && (y colors) 47 | { 48 | Color color(colors[0]); 49 | vector px0(3); 50 | px0[0] = color.R; 51 | px0[1] = color.G; 52 | px0[2] = color.B; 53 | 54 | Color color1(colors[1]); 55 | vector px1(3); 56 | px1[0] = color1.R; 57 | px1[1] = color1.G; 58 | px1[2] = color1.B; 59 | 60 | Color color2(colors[2]); 61 | vector px2(3); 62 | px2[0] = color2.R; 63 | px2[1] = color2.G; 64 | px2[2] = color2.B; 65 | 66 | Color color3(colors[3]); 67 | vector px3(3); 68 | px3[0] = color3.R; 69 | px3[1] = color3.G; 70 | px3[2] = color3.B; 71 | 72 | vector crRet(3); 73 | for (int i=0 ; i < 3 ; i++) 74 | { 75 | double m0 = px0[i] + x * (px1[i] - px0[i]); 76 | double m1 = px2[i] + x * (px3[i] - px2[i]); 77 | double my = m0 + y * (m1 - m0) ; 78 | crRet[i] = SAFECOLOR(my) ; 79 | } 80 | 81 | return Color::rgb(crRet[0], crRet[1], crRet[2]) ; 82 | } 83 | 84 | virtual Image process(Image imageIn) 85 | { 86 | clone = imageIn.clone(); 87 | int width = imageIn.getWidth(); 88 | int height = imageIn.getHeight(); 89 | for(int x = 0 ; x < width; x++){ 90 | for(int y = 0 ; y < height ; y++){ 91 | double un_x, un_y ; 92 | calc_undistorted_coord (x, y, un_x, un_y) ; 93 | 94 | int crNull = White; 95 | int cr = crNull ; 96 | if ( (un_x > -1) && (un_x < width) && (un_y > -1) && (un_y < height) ) 97 | { 98 | // only this range is valid 99 | int nSrcX = ((un_x < 0) ? -1 : (int)un_x); 100 | int nSrcY = ((un_y < 0) ? -1 : (int)un_y); 101 | int nSrcX_1 = nSrcX + 1; 102 | int nSrcY_1 = nSrcY + 1; 103 | 104 | vector color(4); 105 | color[0] = IsInside(width, height, nSrcX, nSrcY) ? clone.getPixelColor(nSrcX,nSrcY) : crNull; 106 | color[1] = IsInside(width, height, nSrcX_1, nSrcY) ? clone.getPixelColor(nSrcX_1,nSrcY) : crNull; 107 | color[2] = IsInside(width, height, nSrcX, nSrcY_1) ? clone.getPixelColor(nSrcX,nSrcY_1) : crNull; 108 | color[3] = IsInside(width, height, nSrcX_1, nSrcY_1) ? clone.getPixelColor(nSrcX_1,nSrcY_1) : crNull; 109 | cr = GetBilinear(un_x-nSrcX, un_y-nSrcY, color); 110 | } 111 | imageIn.setPixelColor(x, y, cr); 112 | } 113 | } 114 | #ifndef WIN32 //only for apple ios 115 | imageIn.copyPixelsFromBuffer(); 116 | #endif 117 | return imageIn; 118 | } 119 | }; 120 | 121 | }// namespace HaoRan 122 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Distort/BulgeFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(BulgeFilter_H) 20 | #define BulgeFilter_H 21 | 22 | #include "BilinearDistort.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class BulgeFilter : public BilinearDistort{ 28 | 29 | private: 30 | double _amount ; 31 | double _offsetX ; 32 | double _offsetY ; 33 | 34 | public: 35 | /** 36 | Constructor \n 37 | param -200 <= nAmount <= 100 \n 38 | param -1 <= _offsetX (_offsetY) <= 1 39 | */ 40 | BulgeFilter (int amount, double offsetX=0, double offsetY=0) 41 | { 42 | _amount = amount / 100.0 ; 43 | _offsetX = FClamp(offsetX, -1.0, 1.0) ; 44 | _offsetY = FClamp(offsetY, -1.0, 1.0) ; 45 | } 46 | 47 | virtual void calc_undistorted_coord (int x, int y, double& un_x, double& un_y) 48 | { 49 | double hw = clone.getWidth() / 2.0 ; 50 | double hh = clone.getHeight() / 2.0 ; 51 | double maxrad = (hw < hh ? hw : hh) ; 52 | hw += _offsetX * hw ; 53 | hh += _offsetY * hh ; 54 | 55 | double u = x - hw ; 56 | double v = y - hh ; 57 | double r = sqrt(u*u + v*v) ; 58 | double rscale1 = 1.0 - (r / maxrad) ; 59 | if (rscale1 > 0) 60 | { 61 | double rscale2 = 1.0 - _amount * rscale1 * rscale1 ; 62 | un_x = FClamp (u * rscale2 + hw, 0.0, clone.getWidth()-1.0) ; 63 | un_y = FClamp (v * rscale2 + hh, 0.0, clone.getHeight()-1.0) ; 64 | } 65 | else 66 | { 67 | un_x = x ; 68 | un_y = y ; 69 | } 70 | } 71 | 72 | }; 73 | 74 | }// namespace HaoRan 75 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Distort/RippleFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(RippleFilter_H) 20 | #define RippleFilter_H 21 | 22 | #include "BilinearDistort.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class RippleFilter : public BilinearDistort{ 28 | 29 | private: 30 | int _waveLength ; 31 | int _amplitude ; 32 | int _sinType ; 33 | 34 | public: 35 | /* 36 | _waveLength >= 1 37 | _amplitude >= 1 38 | */ 39 | RippleFilter (int waveLength, int amplitude, bool sinType=true) 40 | { 41 | _waveLength = ((waveLength >= 1) ? waveLength : 1) ; 42 | _amplitude = ((amplitude >= 1) ? amplitude : 1) ; 43 | _sinType = (sinType ? 1 : 0) ; 44 | } 45 | 46 | virtual void calc_undistorted_coord (int x, int y, double& un_x, double& un_y) 47 | { 48 | double w = clone.getWidth() ; 49 | un_x = fmod (x + w + shift_amount(y), w) ; 50 | un_x = FClamp (un_x, 0.0, w-1) ; 51 | un_y = y ; 52 | } 53 | double shift_amount (int nPos) const 54 | { 55 | if (_sinType) 56 | return _amplitude * sin(nPos*2*LIB_PI/_waveLength) ; 57 | else 58 | return floor (_amplitude * (fabs ((((nPos % _waveLength) / (double)_waveLength) * 4) - 2) - 1)) ; 59 | } 60 | }; 61 | 62 | }// namespace HaoRan 63 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Distort/TwistFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(TwistFilter_H) 20 | #define TwistFilter_H 21 | 22 | #include "BilinearDistort.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class TwistFilter : public BilinearDistort{ 28 | 29 | private: 30 | double _twist ; 31 | double _size ; 32 | double _offsetX ; 33 | double _offsetY ; 34 | 35 | public: 36 | /** 37 | param -45 <= _amount <= 45 \n 38 | param 1 <= _size <= 200 \n 39 | param -2 <= _offsetX (_offsetY) <= 2 40 | */ 41 | TwistFilter (int amount, int size, double offsetX=0, double offsetY=0) 42 | { 43 | amount = -amount ; 44 | _twist = amount * amount * ((amount > 0) ? 1 : -1) ; 45 | 46 | _size = 1.0 / (FClamp(size, 1, 200) / 100.0) ; 47 | _offsetX = FClamp(offsetX, -2.0, 2.0) ; 48 | _offsetY = FClamp(offsetY, -2.0, 2.0) ; 49 | } 50 | private: 51 | virtual void calc_undistorted_coord (int x, int y, double& un_x, double& un_y) 52 | { 53 | double width = clone.getWidth() / 2.0 ; 54 | double height = clone.getHeight() / 2.0 ; 55 | double invmaxrad = 1.0 / (width < height ? width : height) ; 56 | width += _offsetX * width ; 57 | height += _offsetY * height ; 58 | 59 | double u = x - width ; 60 | double v = y - height ; 61 | double r = sqrt(u*u + v*v) ; 62 | double theta = atan2(v, u) ; 63 | 64 | double t = 1 - ((r * _size) * invmaxrad) ; 65 | t = (t < 0) ? 0 : (t * t * t) ; 66 | theta += (t * _twist) / 100.0 ; 67 | 68 | un_x = FClamp (width + r * cos(theta), 0.0, clone.getWidth()-1.0) ; 69 | un_y = FClamp (height + r * sin(theta), 0.0, clone.getHeight()-1.0) ; 70 | } 71 | 72 | }; 73 | 74 | }// namespace HaoRan 75 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Distort/WaveFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(WaveFilter_H) 20 | #define WaveFilter_H 21 | 22 | #include "BilinearDistort.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class WaveFilter : public BilinearDistort{ 28 | 29 | private: 30 | double _phase; 31 | double _amplitude ; 32 | double _waveLength ; 33 | 34 | public: 35 | 36 | WaveFilter(int wavelength, int amplitude, double phase=0) 37 | { 38 | _waveLength = 2 * ((wavelength >= 1) ? wavelength : 1) ; 39 | _amplitude = ((amplitude >= 1) ? amplitude : 1) ; 40 | _phase = phase ; 41 | }; 42 | 43 | virtual void calc_undistorted_coord (int x, int y, double& un_x, double& un_y) 44 | { 45 | double width = clone.getWidth(); 46 | double height = clone.getHeight() ; 47 | double fScaleX = 1.0; 48 | double fScaleY = 1.0 ; 49 | if (width < height) 50 | fScaleX = height / width ; 51 | else if (width > height) 52 | fScaleY = width / height ; 53 | 54 | // distances to center, scaled 55 | double cen_x = width / 2.0; 56 | double cen_y = height / 2.0; 57 | double dx = (x - cen_x) * fScaleX; 58 | double dy = (y - cen_y) * fScaleY; 59 | double amnt = _amplitude * sin (2 * LIB_PI * sqrt (dx*dx + dy*dy) / _waveLength + _phase) ; 60 | un_x = (amnt + dx) / fScaleX + cen_x ; 61 | un_y = (amnt + dy) / fScaleY + cen_y ; 62 | un_x = FClamp (un_x, 0.0, width-1.0) ; 63 | un_y = FClamp (un_y, 0.0, height-1.0) ; 64 | } 65 | }; 66 | 67 | }// namespace HaoRan 68 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/EdgeFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/EdgeFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/FeatherFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(FeatherFilter_H) 20 | #define FeatherFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class FeatherFilter : public IImageFilter{ 27 | 28 | public: 29 | float Size; 30 | FeatherFilter(): Size(0.5){}; 31 | 32 | virtual Image process(Image imageIn) 33 | { 34 | int r, g, b; 35 | int width = imageIn.getWidth(); 36 | int height = imageIn.getHeight(); 37 | int ratio = width > height ? height * 32768 / width : width * 32768 / height; 38 | 39 | // Calculate center, min and max 40 | int cx = width >> 1; 41 | int cy = height >> 1; 42 | int max = cx * cx + cy * cy; 43 | int min = (int)(max * (1 - Size)); 44 | int diff = max - min; 45 | 46 | for (int x = 0; x < width; x++) { 47 | for (int y = 0; y < height; y++) { 48 | r = imageIn.getRComponent(x, y); 49 | g = imageIn.getGComponent(x, y); 50 | b = imageIn.getBComponent(x, y); 51 | 52 | // Calculate distance to center and adapt aspect ratio 53 | int dx = cx - x; 54 | int dy = cy - y; 55 | if (width > height){ 56 | dx = (dx * ratio) >> 15; 57 | } 58 | else{ 59 | dy = (dy * ratio) >> 15; 60 | } 61 | int distSq = dx * dx + dy * dy; 62 | float v = ((float)distSq / diff) * 255; 63 | r = (int)(r + (v)); 64 | g = (int)(g + (v)); 65 | b = (int)(b + (v)); 66 | r = (byte)(r > 255 ? 255 : (r < 0 ? 0 : r)); 67 | g = (byte)(g > 255 ? 255 : (g < 0 ? 0 : g)); 68 | b = (byte)(b > 255 ? 255 : (b < 0 ? 0 : b)); 69 | imageIn.setPixelColor(x,y,r,g,b); 70 | } 71 | } 72 | #ifndef WIN32 //only for apple ios 73 | imageIn.copyPixelsFromBuffer(); 74 | #endif 75 | return imageIn; 76 | } 77 | 78 | }; 79 | 80 | }// namespace HaoRan 81 | 82 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/FillPatternFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(FillPatternFilter_H) 20 | #define FillPatternFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class FillPatternFilter : public IImageFilter{ 28 | private: 29 | Image pattern; 30 | float m_Mixture; 31 | public: 32 | 33 | FillPatternFilter(NSString* path) 34 | { 35 | pattern = HaoRan_ImageFilter::Image::LoadImage(path); 36 | m_Mixture = 0.2f; 37 | }; 38 | 39 | FillPatternFilter(NSString* path, float mixture) 40 | { 41 | pattern = HaoRan_ImageFilter::Image::LoadImage(path); 42 | m_Mixture = mixture; 43 | }; 44 | 45 | virtual Image process(Image imageIn) 46 | { 47 | int mix1 = (int) (m_Mixture * 255); 48 | int mix2 = 255 - mix1; 49 | int r, g, b, r1, g1, b1; 50 | for (int x = 0; x < imageIn.getWidth(); x++) 51 | { 52 | for (int y = 0; y < imageIn.getHeight(); y++) 53 | { 54 | int xx = x % pattern.getWidth(); 55 | int yy = y % pattern.getHeight(); 56 | 57 | r = imageIn.getRComponent(x, y); 58 | g = imageIn.getGComponent(x, y); 59 | b = imageIn.getBComponent(x, y); 60 | r1 = SAFECOLOR(r + pattern.getRComponent(xx, yy)); 61 | g1 = SAFECOLOR(g + pattern.getGComponent(xx, yy)); 62 | b1 = SAFECOLOR(b + pattern.getBComponent(xx, yy)); 63 | r = (r * mix2) + (r1 * mix1); 64 | g = (g * mix2) + (g1 * mix1); 65 | b = (b * mix2) + (b1 * mix1); 66 | imageIn.setPixelColor(x, y, r >> 8, g >> 8, b >> 8); 67 | } 68 | } 69 | #ifndef WIN32 //only for apple ios 70 | imageIn.copyPixelsFromBuffer(); 71 | #endif 72 | //pattern.Destroy(); 73 | return imageIn; 74 | } 75 | }; 76 | 77 | }// namespace HaoRan 78 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/FilmFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(FilmFilter_H) 19 | #define FilmFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "GradientFilter.h" 23 | #include "SaturationModifyFilter.h" 24 | #include "ImageBlender.h" 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class FilmFilter : public IImageFilter{ 29 | 30 | private: 31 | GradientFilter gradient; 32 | SaturationModifyFilter saturationFx; 33 | 34 | 35 | public: 36 | 37 | FilmFilter(float angle) 38 | { 39 | gradient.gradient = Gradient::Fade(); 40 | gradient.OriginAngleDegree = angle; 41 | 42 | saturationFx.SaturationFactor = -0.6f; 43 | }; 44 | 45 | virtual Image process(Image imageIn) 46 | { 47 | Image clone = imageIn.clone(); 48 | imageIn = gradient.process(imageIn); 49 | ImageBlender blender; 50 | blender.Mode = Multiply; 51 | imageIn = saturationFx.process(blender.Blend(clone, imageIn)); 52 | 53 | #ifndef WIN32 //only for apple ios 54 | imageIn.copyPixelsFromBuffer(); 55 | #endif 56 | return imageIn; 57 | //return imageIn;// saturationFx.process(imageIn); 58 | } 59 | }; 60 | 61 | }// namespace HaoRan 62 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/FocusFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.2 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(FocusFilter_H) 19 | #define FocusFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "GradientFilter.h" 23 | #include "GaussianBlurFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class FocusFilter : public GaussianBlurFilter{ 28 | 29 | 30 | public: 31 | 32 | /// 33 | /// Should be in the range [0, 1]. 34 | /// 35 | float Size; 36 | 37 | FocusFilter() 38 | { 39 | Size = 0.5f; 40 | Sigma = 25.0f; 41 | }; 42 | 43 | virtual Image process(Image imageIn) 44 | { 45 | int ratio = imageIn.getWidth() > imageIn.getHeight() ? imageIn.getHeight() * 32768 / imageIn.getWidth() : imageIn.getWidth() * 32768 / imageIn.getHeight(); 46 | 47 | // Calculate center, min and max 48 | int cx = imageIn.getWidth() >> 1; 49 | int cy = imageIn.getHeight() >> 1; 50 | int max = cx * cx + cy * cy; 51 | int min = (int)(max * (1 - Size)); 52 | int diff = max - min; 53 | 54 | int width = imageIn.getWidth(); 55 | int height = imageIn.getHeight(); 56 | vector imageArray = ConvertImageWithPadding(imageIn, width, height); 57 | imageArray = ApplyBlur(imageArray, width, height); 58 | int newwidth = width + Padding * 2; 59 | for (int i = 0; i < height; i++) 60 | { 61 | int num = ((i + 3) * newwidth) + 3; 62 | for (int j = 0; j < width; j++) 63 | { 64 | // Calculate distance to center and adapt aspect ratio 65 | int dx = cx - j; 66 | int dy = cy - i; 67 | if (imageIn.getWidth() > imageIn.getHeight()) 68 | { 69 | dy = (dy * ratio) >> 14; 70 | } 71 | else 72 | { 73 | dx = (dx * ratio) >> 14; 74 | } 75 | int distSq = dx * dx + dy * dy; 76 | 77 | if (distSq > min) 78 | { 79 | int pos = (num + j) * 3; 80 | imageIn.setPixelColor(j, i, (byte)(imageArray[pos] * 255.0f), (byte)(imageArray[pos + 1] * 255.0f), (byte)(imageArray[pos + 2] * 255.0f)); 81 | } 82 | } 83 | } 84 | 85 | #ifndef WIN32 //only for apple ios 86 | imageIn.copyPixelsFromBuffer(); 87 | #endif 88 | return imageIn; 89 | //return imageIn;// saturationFx.process(imageIn); 90 | } 91 | }; 92 | 93 | }// namespace HaoRan 94 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/GaussianBlurFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(GaussianBlurFilter_H) 20 | #define GaussianBlurFilter_H 21 | 22 | #include "IImageFilter.h" 23 | #include "math.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class GaussianBlurFilter : public IImageFilter{ 28 | 29 | protected: 30 | int Padding; 31 | 32 | public: 33 | /// 34 | /// The bluriness factor. 35 | /// Should be in the range [0, 40]. 36 | /// 37 | float Sigma; 38 | 39 | GaussianBlurFilter(): Padding(3), Sigma(0.75) {}; 40 | 41 | vector ApplyBlur(vector srcPixels, int width, int height) 42 | { 43 | vector destPixels(srcPixels.begin(), srcPixels.end()); 44 | 45 | int w = width + Padding * 2; 46 | int h = height + Padding * 2; 47 | 48 | // Calculate the coefficients 49 | float q = Sigma; 50 | float q2 = q * q; 51 | float q3 = q2 * q; 52 | 53 | float b0 = 1.57825f + 2.44413f * q + 1.4281f * q2 + 0.422205f * q3; 54 | float b1 = 2.44413f * q + 2.85619f * q2 + 1.26661f * q3; 55 | float b2 = -(1.4281f * q2 + 1.26661f * q3); 56 | float b3 = 0.422205f * q3; 57 | 58 | float b = 1.0f - ((b1 + b2 + b3) / b0); 59 | 60 | // Apply horizontal pass 61 | destPixels = ApplyPass(destPixels, w, h, b0, b1, b2, b3, b); 62 | 63 | // Transpose the array 64 | vector transposedPixels(destPixels.size()); 65 | transposedPixels = Transpose(destPixels, transposedPixels, w, h); 66 | 67 | // Apply vertical pass 68 | transposedPixels = ApplyPass(transposedPixels, h, w, b0, b1, b2, b3, b); 69 | 70 | // transpose back 71 | destPixels = Transpose(transposedPixels, destPixels, h, w); 72 | 73 | return destPixels; 74 | } 75 | 76 | vector ApplyPass(vector pixels, int width, int height, float b0, float b1, float b2, float b3, float b) 77 | { 78 | float num = 1 / b0; 79 | int triplewidth = width * 3; 80 | for (int i = 0; i < height; i++) 81 | { 82 | int steplength = i * triplewidth; 83 | for (int j = steplength + 9; j < (steplength + triplewidth); j += 3) 84 | { 85 | pixels[j] = (b * pixels[j]) + ((((b1 * pixels[j - 3]) + (b2 * pixels[j - 6])) + (b3 * pixels[j - 9])) * num); 86 | pixels[j + 1] = (b * pixels[j + 1]) + ((((b1 * pixels[(j + 1) - 3]) + (b2 * pixels[(j + 1) - 6])) + (b3 * pixels[(j + 1) - 9])) * num); 87 | pixels[j + 2] = (b * pixels[j + 2]) + ((((b1 * pixels[(j + 2) - 3]) + (b2 * pixels[(j + 2) - 6])) + (b3 * pixels[(j + 2) - 9])) * num); 88 | } 89 | for (int k = ((steplength + triplewidth) - 9) - 3; k >= steplength; k -= 3) 90 | { 91 | pixels[k] = (b * pixels[k]) + ((((b1 * pixels[k + 3]) + (b2 * pixels[k + 6])) + (b3 * pixels[k + 9])) * num); 92 | pixels[k + 1] = (b * pixels[k + 1]) + ((((b1 * pixels[(k + 1) + 3]) + (b2 * pixels[(k + 1) + 6])) + (b3 * pixels[(k + 1) + 9])) * num); 93 | pixels[k + 2] = (b * pixels[k + 2]) + ((((b1 * pixels[(k + 2) + 3]) + (b2 * pixels[(k + 2) + 6])) + (b3 * pixels[(k + 2) + 9])) * num); 94 | } 95 | } 96 | return pixels; 97 | } 98 | 99 | 100 | vector Transpose(vector input, vector output, int width, int height) 101 | { 102 | for (int i = 0; i < height; i++) 103 | { 104 | for (int j = 0; j < width; j++) 105 | { 106 | int index = (j * height) * 3 + (i * 3); 107 | int pos = (i * width) * 3 + (j * 3); 108 | output[index] = input[pos]; 109 | output[index + 1] = input[pos + 1]; 110 | output[index + 2] = input[pos + 2]; 111 | } 112 | } 113 | return output; 114 | } 115 | 116 | 117 | vector ConvertImageWithPadding(Image imageIn, int width, int height) 118 | { 119 | int newheight = height + Padding * 2; 120 | int newwidth = width + Padding * 2; 121 | vector numArray((newheight * newwidth) * 3); 122 | int index = 0; 123 | int num = 0; 124 | for (int i = -3; num < newheight; i++) 125 | { 126 | int y = i; 127 | if (i < 0) 128 | { 129 | y = 0; 130 | } 131 | else if (i >= height) 132 | { 133 | y = height - 1; 134 | } 135 | int count = 0; 136 | int negpadding = -1 * Padding; 137 | while (count < newwidth) 138 | { 139 | int x = negpadding; 140 | if (negpadding < 0) 141 | { 142 | x = 0; 143 | } 144 | else if (negpadding >= width) 145 | { 146 | x = width - 1; 147 | } 148 | numArray[index] = imageIn.getRComponent(x, y) * 0.003921569f; 149 | numArray[index + 1] = imageIn.getGComponent(x, y) * 0.003921569f; 150 | numArray[index + 2] = imageIn.getBComponent(x, y) * 0.003921569f; 151 | 152 | count++; negpadding++; 153 | index += 3; 154 | } 155 | num++; 156 | } 157 | return numArray; 158 | } 159 | 160 | 161 | virtual Image process(Image imageIn) 162 | { 163 | int width = imageIn.getWidth(); 164 | int height = imageIn.getHeight(); 165 | vector imageArray = ConvertImageWithPadding(imageIn, width, height); 166 | imageArray = ApplyBlur(imageArray, width, height); 167 | int newwidth = width + Padding * 2; 168 | for (int i = 0; i < height; i++) 169 | { 170 | int num = ((i + 3) * newwidth) + 3; 171 | for (int j = 0; j < width; j++) 172 | { 173 | int pos = (num + j) * 3; 174 | imageIn.setPixelColor(j, i, (byte)(imageArray[pos] * 255), (byte)(imageArray[pos + 1] * 255), (byte)(imageArray[pos + 2] * 255)); 175 | } 176 | } 177 | #ifndef WIN32 //only for apple ios 178 | imageIn.copyPixelsFromBuffer(); 179 | #endif 180 | return imageIn; 181 | } 182 | }; 183 | 184 | }// namespace HaoRan 185 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/GradientMapFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(GradientMapFilter_H) 20 | #define GradientMapFilter_H 21 | 22 | #include "GradientFilter.h" 23 | #include 24 | 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class GradientMapFilter : public IImageFilter{ 29 | public: 30 | float BrightnessFactor; 31 | float ContrastFactor; 32 | Gradient Map; 33 | 34 | GradientMapFilter() : BrightnessFactor(0),ContrastFactor(0) {}; 35 | GradientMapFilter(Gradient gradient) : Map(gradient), BrightnessFactor(0),ContrastFactor(0) {}; 36 | 37 | virtual Image process(Image imageIn) 38 | { 39 | Palette palette = Map.CreatePalette(0x100); 40 | vector red = palette.Red; 41 | vector green = palette.Green; 42 | vector blue = palette.Blue; 43 | Image bitmap = imageIn.clone(); 44 | bitmap.clearImage(::White); 45 | int bfactor = (int) (BrightnessFactor * 255); 46 | float cfactor = 1 + ContrastFactor; 47 | cfactor *= cfactor; 48 | int limit = ((int) (cfactor * 32768)) + 1; 49 | int size = imageIn.getHeight()*imageIn.getWidth(); 50 | for (int i = 0; i < size; i++) 51 | { 52 | int r = (imageIn.colorArray[i]& 0x00FF0000) >> 16; 53 | int g = (imageIn.colorArray[i]& 0x0000FF00) >> 8; 54 | int b = imageIn.colorArray[i]& 0x000000FF; 55 | int index = (((r * 0x1b36) + (g * 0x5b8c)) + (b * 0x93e)) >> 15; 56 | if (bfactor != 0) 57 | { 58 | index += bfactor; 59 | index = (index > 0xff) ? 0xff : ((index < 0) ? 0 : index); 60 | } 61 | if (limit != 0x8001) 62 | { 63 | index -= 0x80; 64 | index = (index * limit) >> 15; 65 | index += 0x80; 66 | index = (index > 0xff) ? 0xff : ((index < 0) ? 0 : index); 67 | } 68 | bitmap.colorArray[i] = (0xff << 24) + (red[index] << 16) + (green[index] << 8) + blue[index]; 69 | } 70 | #ifndef WIN32 //only for apple ios 71 | imageIn.copyPixelsFromBuffer(); 72 | #endif 73 | return bitmap; 74 | } 75 | }; 76 | 77 | }// namespace HaoRan 78 | 79 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/HistogramEqualFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(HistogramEqualFilter_H) 20 | #define HistogramEqualFilter_H 21 | 22 | #include "IImageFilter.h" 23 | #include 24 | 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class HistogramEqualFilter : public IImageFilter{ 29 | public: 30 | float ContrastIntensity ; 31 | 32 | HistogramEqualFilter():ContrastIntensity(1){}; 33 | 34 | virtual Image process(Image imageIn) 35 | { 36 | int r, g, b; 37 | int _array[256]; 38 | vector numArray(imageIn.getHeight()*imageIn.getWidth()); 39 | int contrast = (int) (ContrastIntensity * 255); 40 | int pos = 0; 41 | for (int x = 0; x < imageIn.getWidth(); x++) { 42 | for (int y = 0; y < imageIn.getHeight(); y++) { 43 | r = imageIn.getRComponent(x, y); 44 | g = imageIn.getGComponent(x, y); 45 | b = imageIn.getBComponent(x, y); 46 | int index = (r * 0x1b36 + g * 0x5b8c + b * 0x93e) >> 15; 47 | _array[index]++; 48 | numArray[pos] = index; 49 | pos++; 50 | } 51 | } 52 | for (int i = 1; i < 0x100; i++){ 53 | _array[i] += _array[i - 1]; 54 | } 55 | for (int i = 0; i < 0x100; i++){ 56 | _array[i] = (_array[i] << 8) / imageIn.getHeight()*imageIn.getWidth(); 57 | _array[i] = ((contrast * _array[i]) >> 8) + (((0xff - contrast) * i) >> 8); 58 | } 59 | pos = 0; 60 | for (int x = 0; x < imageIn.getWidth(); x++) { 61 | for (int y = 0; y < imageIn.getHeight(); y++) { 62 | r = imageIn.getRComponent(x, y); 63 | g = imageIn.getGComponent(x, y); 64 | b = imageIn.getBComponent(x, y); 65 | if (numArray[pos] != 0){ 66 | int num = _array[numArray[pos]]; 67 | r = (r * num) / numArray[pos]; 68 | g = (g * num) / numArray[pos]; 69 | b = (b * num) / numArray[pos]; 70 | r = (r > 0xff) ? ((byte) 0xff) : ((r < 0) ? ((byte) 0) : ((byte) r)); 71 | g = (g > 0xff) ? ((byte) 0xff) : ((g < 0) ? ((byte) 0) : ((byte) g)); 72 | b = (b > 0xff) ? ((byte) 0xff) : ((b < 0) ? ((byte) 0) : ((byte) b)); 73 | } 74 | imageIn.setPixelColor(x,y,r,g,b); 75 | pos++; 76 | } 77 | } 78 | #ifndef WIN32 //only for apple ios 79 | imageIn.copyPixelsFromBuffer(); 80 | #endif 81 | return imageIn; 82 | } 83 | }; 84 | 85 | }// namespace HaoRan 86 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/HslColor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(HslColorH) 20 | #define HslColorH 21 | 22 | #include 23 | 24 | #include "IImageFilter.h" 25 | #include "Image.h" 26 | 27 | namespace HaoRan_ImageFilter{ 28 | class HslColor 29 | { 30 | 31 | public: 32 | float h; 33 | float l; 34 | float s; 35 | 36 | HslColor(float _h, float _s, float _l) 37 | { 38 | h = _h; 39 | s = _s; 40 | l = _l; 41 | } 42 | 43 | 44 | private: 45 | // HSL to RGB helper routine 46 | static double Hue_2_RGB(double v1, double v2, double vH) 47 | { 48 | if (vH < 0) 49 | vH += 1; 50 | if (vH > 1) 51 | vH -= 1; 52 | if ((6 * vH) < 1) 53 | return (v1 + (v2 - v1) * 6 * vH); 54 | if ((2 * vH) < 1) 55 | return v2; 56 | if ((3 * vH) < 2) 57 | return (v1 + (v2 - v1) * ((2.0 / 3) - vH) * 6); 58 | return v1; 59 | } 60 | 61 | static float HueToRgb(float t1, float t2, float h) 62 | { 63 | if (h < 0) 64 | { 65 | h++; 66 | } 67 | if (h > 1) 68 | { 69 | h--; 70 | } 71 | if ((6 * h) < 1) 72 | { 73 | return (t1 + (((t2 - t1) * 6) * h)); 74 | } 75 | if ((2 * h) < 1) 76 | { 77 | return t2; 78 | } 79 | if ((3 * h) < 2) 80 | { 81 | return (t1 + (((t2 - t1) * (0.6666667f - h)) * 6)); 82 | } 83 | return t1; 84 | } 85 | 86 | public: 87 | static int HslToRgb(HslColor hsl) 88 | { 89 | int r, g, b; 90 | if (hsl.h == 0) 91 | { 92 | // gray values 93 | r = g = b = (BYTE)(hsl.l * 255); 94 | } 95 | else 96 | { 97 | double v1, v2; 98 | double hue = (double)hsl.h / 360; 99 | 100 | v2 = (hsl.l < 0.5) ? 101 | (hsl.l * (1 + hsl.s)) : 102 | ((hsl.l + hsl.s) - (hsl.l * hsl.s)); 103 | v1 = 2 * hsl.l - v2; 104 | 105 | r = (byte)(255 * Hue_2_RGB(v1, v2, hue + (1.0 / 3))); 106 | g = (byte)(255 * Hue_2_RGB(v1, v2, hue)); 107 | b = (byte)(255 * Hue_2_RGB(v1, v2, hue - (1.0 / 3))); 108 | } 109 | return (255 << 24) + (r << 16) + (g << 8) + b; 110 | } 111 | 112 | 113 | 114 | HslColor Interpolate(HslColor c2, float amount) 115 | { 116 | return HslColor(h + ((c2.h - h) * amount), s + ((c2.s - s) * amount), l + ((c2.l - l) * amount)); 117 | } 118 | 119 | static void RgbToHsl(int color, HslColor hsl) 120 | { 121 | RgbToHsl(0xff & (color >> 0x10), 0xff & (color >> 8), 0xff & color, hsl); 122 | } 123 | 124 | static HslColor RgbToHsl(int rr, int gg, int bb, HslColor hsl) 125 | { 126 | double r = (rr / 255.0); 127 | double g = (gg / 255.0); 128 | double b = (bb / 255.0); 129 | 130 | double min = MIN(MIN(r, g), b); 131 | double max = MAX(MAX(r, g), b); 132 | double delta = max - min; 133 | 134 | // get luminance value 135 | hsl.l = (float)(max + min) / 2; 136 | 137 | if (delta == 0) 138 | { 139 | // gray color 140 | hsl.h = 0; 141 | hsl.s = 0.0f; 142 | } 143 | else 144 | { 145 | // get saturation value 146 | hsl.s = (float)((hsl.l < 0.5) ? (delta / (max + min)) : (delta / (2 - max - min))); 147 | 148 | // get hue value 149 | double del_r = (((max - r) / 6) + (delta / 2)) / delta; 150 | double del_g = (((max - g) / 6) + (delta / 2)) / delta; 151 | double del_b = (((max - b) / 6) + (delta / 2)) / delta; 152 | double hue; 153 | 154 | if (r == max) 155 | hue = del_b - del_g; 156 | else if (g == max) 157 | hue = (1.0 / 3) + del_r - del_b; 158 | else 159 | hue = (2.0 / 3) + del_g - del_r; 160 | 161 | // correct hue if needed 162 | if (hue < 0) 163 | hue += 1; 164 | if (hue > 1) 165 | hue -= 1; 166 | 167 | hsl.h = (int)(hue * 360); 168 | } 169 | return hsl; 170 | } 171 | 172 | }; 173 | 174 | }// namespace HaoRan 175 | #endif 176 | 177 | -------------------------------------------------------------------------------- /Classes/imageFilter/HslModifyFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/HslModifyFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/IImageFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(IImageFilter_H) 20 | #define IImageFilter_H 21 | 22 | typedef unsigned char BYTE; 23 | typedef unsigned char byte; 24 | 25 | #include "Image.h" 26 | #include "math.h" 27 | #include 28 | 29 | #define LIB_PI 3.14159265358979323846 30 | 31 | namespace HaoRan_ImageFilter{ 32 | 33 | class Point 34 | { 35 | public: 36 | float X; 37 | float Y; 38 | Point(){ 39 | X = 0; 40 | Y = 0; 41 | } 42 | 43 | Point(float x, float y){ 44 | X = x; 45 | Y = y; 46 | } 47 | }; 48 | 49 | 50 | class Color{ 51 | public: 52 | int R; 53 | int G; 54 | int B; 55 | Color(){} 56 | 57 | Color(int r, int g, int b) : R(r), G(g), B(b){} 58 | 59 | Color(int rgb){ 60 | R = ((rgb& 0x00FF0000) >> 16); 61 | G = ((rgb& 0x0000FF00) >> 8); 62 | B = ( rgb& 0x000000FF); 63 | } 64 | 65 | static int rgb(int r, int g, int b){ 66 | return (255 << 24) + (r << 16) + (g << 8) + b; 67 | } 68 | }; 69 | 70 | class IImageFilter{ 71 | 72 | public: 73 | virtual Image process(Image image){ 74 | return image; 75 | } 76 | 77 | //------------------------------------------------------------------------------------- 78 | // basic function 79 | //------------------------------------------------------------------------------------- 80 | // bound in [tLow, tHigh] 81 | template inline T FClamp (const T& t, const T& tLow, const T& tHigh) 82 | { 83 | if (t < tHigh) 84 | { 85 | return ((t > tLow) ? t : tLow) ; 86 | } 87 | return tHigh ; 88 | } 89 | inline int FClamp0255(const double d) 90 | { 91 | return (int)(FClamp(d, 0.0, 255.0) + 0.5) ; 92 | }; 93 | 94 | virtual ~IImageFilter() {} 95 | }; 96 | 97 | }// namespace HaoRan 98 | #endif 99 | -------------------------------------------------------------------------------- /Classes/imageFilter/IllusionFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(IllusionFilter_H) 20 | #define IllusionFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class IllusionFilter : public IImageFilter{ 28 | 29 | private: 30 | double _amount; 31 | double _scale; 32 | double _offset; 33 | 34 | public: 35 | 36 | IllusionFilter (int amount) 37 | { 38 | _amount = LIB_PI / ((amount >= 1) ? amount : 1) ; 39 | } 40 | 41 | virtual Image process(Image imageIn) 42 | { 43 | double width = imageIn.getWidth(); 44 | double height = imageIn.getHeight(); 45 | Image clone = imageIn.clone(); 46 | int r, g, b; 47 | for(int x = 0 ; x < (width - 1) ; x++){ 48 | for(int y = 0 ; y < (height - 1) ; y++){ 49 | r = imageIn.getRComponent(x, y); 50 | g = imageIn.getGComponent(x, y); 51 | b = imageIn.getBComponent(x, y); 52 | 53 | _scale = sqrt(width*width + height*height) / 2 ; 54 | _offset = (int)(_scale / 2) ; 55 | double cx = (x - width / 2.0) / _scale ; 56 | double cy = (y - height / 2.0) / _scale ; 57 | double angle = floor (atan2(cy,cx) / 2.0 / _amount) * 2.0 * _amount + _amount; 58 | double radius = sqrt(cx*cx + cy*cy) ; 59 | int xx = (int)(x - _offset * cos(angle)) ; 60 | int yy = (int)(y - _offset * sin(angle)) ; 61 | xx = FClamp(xx, 0, (int)(width-1)); 62 | yy = FClamp(yy, 0, (int)(height-1)); 63 | 64 | r = FClamp0255 (r + radius * (clone.getRComponent(xx, yy) - r)) ; 65 | g = FClamp0255 (g + radius * (clone.getGComponent(xx, yy) - g)) ; 66 | b = FClamp0255 (b + radius * (clone.getBComponent(xx, yy) - b)) ; 67 | imageIn.setPixelColor(x, y, r, g, b); 68 | } 69 | } 70 | #ifndef WIN32 //only for apple ios 71 | imageIn.copyPixelsFromBuffer(); 72 | #endif 73 | return imageIn; 74 | } 75 | }; 76 | 77 | }// namespace HaoRan 78 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ImageBlender.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/ImageBlender.h -------------------------------------------------------------------------------- /Classes/imageFilter/InvertFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(INVERTFILTER_H) 20 | #define INVERTFILTER_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class InvertFilter : public IImageFilter{ 28 | 29 | public: 30 | 31 | InvertFilter(){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int r, g, b; 36 | for(int x = 0 ; x < imageIn.getWidth() ; x++){ 37 | for(int y = 0 ; y < imageIn.getHeight(); y++){ 38 | r = 255 - imageIn.getRComponent(x, y); 39 | g = 255 - imageIn.getGComponent(x, y); 40 | b = 255 - imageIn.getBComponent(x, y); 41 | imageIn.setPixelColor(x, y, r, g, b); 42 | } 43 | } 44 | #ifndef WIN32 //only for apple ios 45 | imageIn.copyPixelsFromBuffer(); 46 | #endif 47 | return imageIn; 48 | } 49 | }; 50 | 51 | }// namespace HaoRan 52 | //#endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Classes/imageFilter/LightFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/LightFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/LomoFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.2 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(LomoFilter_H) 19 | #define LomoFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "BrightContrastFilter.h" 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class LomoFilter : public IImageFilter{ 27 | 28 | private: 29 | BrightContrastFilter contrastFx; 30 | GradientMapFilter gradientMapFx; 31 | ImageBlender blender; 32 | VignetteFilter vignetteFx; 33 | NoiseFilter noiseFx; 34 | 35 | public: 36 | 37 | LomoFilter(){ 38 | contrastFx.BrightnessFactor = 0.05f; 39 | contrastFx.ContrastFactor = 0.5f; 40 | 41 | blender.Mixture = 0.5f; 42 | blender.Mode = ::Multiply; 43 | 44 | vignetteFx.Size = 0.6f; 45 | 46 | noiseFx.Intensity = 0.02f; 47 | }; 48 | 49 | virtual Image process(Image imageIn) 50 | { 51 | Image tempImg = contrastFx.process(imageIn); 52 | tempImg = noiseFx.process(tempImg); 53 | imageIn = gradientMapFx.process(tempImg); 54 | imageIn = blender.Blend(imageIn, tempImg); 55 | imageIn = vignetteFx.process(imageIn); 56 | #ifndef WIN32 //only for apple ios 57 | imageIn.copyPixelsFromBuffer(); 58 | #endif 59 | return imageIn; 60 | } 61 | }; 62 | 63 | }// namespace HaoRan 64 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/MirrorFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/MirrorFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/MistFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/MistFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/MonitorFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(MonitorFilter_H) 20 | #define MonitorFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class MonitorFilter : public IImageFilter{ 28 | private: 29 | /** 30 | * method to calculate an appropriate interval for flicker lines 31 | * 32 | * @param a_value 33 | * @return 34 | */ 35 | /* int getValidInterval(int a_value){ 36 | if(a_value < 0) return 0; 37 | if(a_value > 255) return 255; 38 | return a_value; 39 | }*/ 40 | 41 | public: 42 | 43 | MonitorFilter(){}; 44 | 45 | virtual Image process(Image imageIn) 46 | { 47 | int r,g,b; 48 | for (int x = 0; x < imageIn.getWidth(); x++) { 49 | for (int y = 0; y < imageIn.getHeight(); y+=3) { 50 | r=0; 51 | g=0; 52 | b=0; 53 | for(int w=0; w<3; w++){ 54 | if(y+w < imageIn.getHeight() ){ 55 | r += (imageIn.getRComponent(x, y+w))/2; 56 | g += (imageIn.getGComponent(x, y+w))/2; 57 | b += (imageIn.getBComponent(x, y+w))/2; 58 | } 59 | } 60 | r = SAFECOLOR(r); 61 | g = SAFECOLOR(g); 62 | b = SAFECOLOR(b); 63 | 64 | for(int w=0; w<3; w++){ 65 | if(y+w < imageIn.getHeight()){ 66 | if(w == 0){ 67 | imageIn.setPixelColor(x,y+w,r,0,0); 68 | } 69 | else if(w ==1){ 70 | imageIn.setPixelColor(x,y+w,0,g,0); 71 | } 72 | else if(w==2){ 73 | imageIn.setPixelColor(x,y+w,0,0,b); 74 | } 75 | } 76 | } 77 | } 78 | } 79 | #ifndef WIN32 //only for apple ios 80 | imageIn.copyPixelsFromBuffer(); 81 | #endif 82 | return imageIn; 83 | } 84 | }; 85 | 86 | }// namespace HaoRan 87 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/MosaicFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/MosaicFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/NeonFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/NeonFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/NightVisionFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(NightVisionFilter_H) 20 | #define NightVisionFilter_H 21 | 22 | #include "NoiseFilter.h" 23 | #include "VignetteFilter.h" 24 | #include "GradientMapFilter.h" 25 | #include "GradientFilter.h" 26 | 27 | #include "ImageBlender.h" 28 | 29 | namespace HaoRan_ImageFilter{ 30 | 31 | class NightVisionFilter : public IImageFilter{ 32 | 33 | private: 34 | NoiseFilter noisefx; 35 | ImageBlender blender; 36 | VignetteFilter vignetteFx; 37 | GradientMapFilter gradientFx; 38 | 39 | public: 40 | 41 | NightVisionFilter(){ 42 | noisefx.Intensity = 0.15f; 43 | 44 | vignetteFx.Size = 1; 45 | 46 | vector colors(2); 47 | colors[0] = ::Black; 48 | colors[1] = ::Green; 49 | Gradient gradient(colors); 50 | gradientFx.Map = gradient; 51 | gradientFx.BrightnessFactor = 0.2f; 52 | }; 53 | 54 | virtual Image process(Image imageIn) 55 | { 56 | imageIn = noisefx.process(imageIn); 57 | imageIn = gradientFx.process(imageIn); 58 | imageIn = vignetteFx.process(imageIn); 59 | return imageIn; 60 | } 61 | }; 62 | 63 | }// namespace HaoRan 64 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/NoiseFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(NoiseFilter_H) 20 | #define NoiseFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class NoiseFilter : public IImageFilter{ 28 | public: 29 | float Intensity; 30 | 31 | static int getRandomInt(int a, int b) { 32 | return rand()%((b)-(a)) + (a); 33 | } 34 | 35 | NoiseFilter() : Intensity(0.2f){}; 36 | 37 | virtual Image process(Image imageIn) 38 | { 39 | int r, g, b; 40 | int num = (int)(Intensity * 32768); 41 | for (int x = 0; x < imageIn.getWidth(); x++) { 42 | for (int y = 0; y < imageIn.getHeight(); y++) { 43 | r = imageIn.getRComponent(x, y); 44 | g = imageIn.getGComponent(x, y); 45 | b = imageIn.getBComponent(x, y); 46 | if (num != 0){ 47 | int rr = getRandomInt(-255, 0xff) * num; 48 | int gg = getRandomInt(-255, 0xff) * num; 49 | int bb = getRandomInt(-255, 0xff) * num; 50 | int rrr = r + (rr >> 15); 51 | int ggg = g + (gg >> 15); 52 | int bbb = b + (bb >> 15); 53 | r = SAFECOLOR(rrr); 54 | g = SAFECOLOR(ggg); 55 | b = SAFECOLOR(bbb); 56 | } 57 | imageIn.setPixelColor(x,y,r,g,b); 58 | } 59 | } 60 | #ifndef WIN32 //only for apple ios 61 | imageIn.copyPixelsFromBuffer(); 62 | #endif 63 | return imageIn; 64 | } 65 | }; 66 | 67 | }// namespace HaoRan 68 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/OilPaintFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | 20 | #if !defined(OilPaintFilter_H) 21 | #define OilPaintFilter_H 22 | 23 | #include "NoiseFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class OilPaintFilter : public IImageFilter{ 28 | public: 29 | int Model; 30 | 31 | OilPaintFilter(): Model(3){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int width = imageIn.getWidth(); 36 | int height = imageIn.getHeight(); 37 | Image clone = imageIn.clone(); 38 | int r = 0, g = 0, b = 0, xx = 0, yy = 0; 39 | for (int x = 0; x < width; x++) { 40 | for (int y = 0; y < height; y++) { 41 | int pos = NoiseFilter::getRandomInt(1, 10000) % Model; 42 | xx = (x + pos) < width ? (x + pos) : (x - pos) >= 0 ? (x - pos) : x; 43 | yy = (y + pos) < height ? (y + pos) : (y - pos) >= 0 ? (y - pos) : y; 44 | r = clone.getRComponent(xx, yy); 45 | g = clone.getGComponent(xx, yy); 46 | b = clone.getBComponent(xx, yy); 47 | imageIn.setPixelColor(x, y, r, g, b); 48 | } 49 | } 50 | #ifndef WIN32 //only for apple ios 51 | imageIn.copyPixelsFromBuffer(); 52 | #endif 53 | return imageIn; 54 | } 55 | }; 56 | 57 | }// namespace HaoRan 58 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/OldPhotoFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(OldPhotoFilter_H) 20 | #define OldPhotoFilter_H 21 | 22 | #include "GaussianBlurFilter.h" 23 | #include "NoiseFilter.h" 24 | #include "VignetteFilter.h" 25 | #include "GradientMapFilter.h" 26 | 27 | namespace HaoRan_ImageFilter{ 28 | 29 | class OldPhotoFilter : public IImageFilter{ 30 | 31 | private: 32 | GaussianBlurFilter blurFx; 33 | NoiseFilter noiseFx; 34 | VignetteFilter vignetteFx; 35 | GradientMapFilter gradientFx; 36 | 37 | public: 38 | 39 | OldPhotoFilter(){ 40 | blurFx.Sigma = 0.3f; 41 | noiseFx.Intensity = 0.03f; 42 | vignetteFx.Size = 0.6f; 43 | gradientFx.ContrastFactor = 0.3f; 44 | }; 45 | 46 | 47 | virtual Image process(Image imageIn) 48 | { 49 | imageIn = noiseFx.process(blurFx.process(imageIn)); 50 | imageIn = gradientFx.process(imageIn); 51 | return vignetteFx.process(imageIn); 52 | } 53 | }; 54 | 55 | }// namespace HaoRan 56 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/PaintBorderFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.2 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(PaintBorderFilter_H) 19 | #define PaintBorderFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "ImageBlender.h" 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class PaintBorderFilter : public IImageFilter{ 27 | 28 | private: 29 | /// 30 | /// Should be in the range [0, 10]. 31 | /// 32 | float Size; 33 | int R, G, B; 34 | 35 | public: 36 | PaintBorderFilter(int color): Size(1.0f) /*color reference http://www.wescn.com/tool/color_3.html*/ 37 | { 38 | R = (color & 0x00FF0000) >> 16; 39 | G = (color & 0x0000FF00) >> 8; 40 | B = (color & 0x000000FF); 41 | }; 42 | 43 | PaintBorderFilter(int color, float size) 44 | { 45 | Size = size; 46 | R = (color & 0x00FF0000) >> 16; 47 | G = (color & 0x0000FF00) >> 8; 48 | B = (color & 0x000000FF); 49 | } 50 | 51 | //@Override 52 | virtual Image process(Image imageIn) 53 | { 54 | int r, g, b; 55 | int width = imageIn.getWidth(); 56 | int height = imageIn.getHeight(); 57 | int ratio = width > height ? height * 32768 / width : width * 32768 / height; 58 | 59 | // Calculate center, min and max 60 | int cx = width >> 1; 61 | int cy = height >> 1; 62 | int max = cx * cx + cy * cy; 63 | int min = (int)(max * (1 - Size)); 64 | int diff = max - min; 65 | Image clone = imageIn.clone(); 66 | for (int x = 0; x < width; x++) 67 | { 68 | for (int y = 0; y < height; y++) 69 | { 70 | // Calculate distance to center and adapt aspect ratio 71 | int dx = cx - x; 72 | int dy = cy - y; 73 | if (width > height) 74 | dx = (dx * ratio) >> 15; 75 | else 76 | dy = (dy * ratio) >> 15; 77 | int distSq = dx * dx + dy * dy; 78 | 79 | r = (int)((((float)distSq / diff) * R)); 80 | g = (int)((((float)distSq / diff) * G)); 81 | b = (int)((((float)distSq / diff) * B)); 82 | r = (r > R ? R : (r < 0 ? 0 : r)); 83 | g = (g > G ? G : (g < 0 ? 0 : g)); 84 | b = (b > B ? B : (b < 0 ? 0 : b)); 85 | imageIn.setPixelColor(x, y, r, g, b); 86 | } 87 | } 88 | ImageBlender blender; 89 | 90 | blender.Mode = ::Additive; 91 | clone = blender.Blend(clone, imageIn); 92 | #ifndef WIN32 //only for apple ios 93 | clone.copyPixelsFromBuffer(); 94 | #endif 95 | imageIn.Destroy(); 96 | return clone; 97 | } 98 | }; 99 | 100 | }// namespace HaoRan 101 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/PixelateFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | 20 | #if !defined(PixelateFilter_H) 21 | #define PixelateFilter_H 22 | 23 | #include "IImageFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class PixelateFilter : public IImageFilter{ 28 | private: 29 | int pixelSize; 30 | 31 | public: 32 | 33 | int getPixelSize() { 34 | return pixelSize; 35 | }; 36 | 37 | /** 38 | * @param pixelSize the pixelSize to set 39 | */ 40 | void setPixelSize(int size) { 41 | pixelSize = size; 42 | }; 43 | 44 | int getPredominantRGB(Image imageIn, int a_x, int a_y, int squareSize){ 45 | int red=-1; 46 | int green=-1; 47 | int blue=-1; 48 | 49 | for(int x=a_x; x= 2 74 | */ 75 | PosterizeFilter (int nLevel) 76 | { 77 | _level = ((nLevel >= 2) ? nLevel : 2) ; 78 | } 79 | }; 80 | 81 | 82 | class GammaFilter : public LUTFilter 83 | { 84 | double _fInvGamma ; 85 | public: 86 | /** 87 | Constructor \n 88 | nGamma >= 1, 100 means not change 89 | */ 90 | GammaFilter (int gamma) 91 | { 92 | gamma = ((gamma >= 1) ? gamma : 1) ; 93 | _fInvGamma = 1.0 / (gamma / 100.0) ; 94 | } 95 | private: 96 | virtual int InitLUTtable (int nLUTIndex) 97 | { 98 | double fMax = pow (255.0, _fInvGamma) / 255.0 ; 99 | double d = pow((double)nLUTIndex, _fInvGamma) ; 100 | return FClamp0255(d / fMax) ; 101 | } 102 | }; 103 | 104 | }// namespace HaoRan 105 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/RadialDistortionFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(RadialDistortionFilter_H) 20 | #define RadialDistortionFilter_H 21 | 22 | #include "IImageFilter.h" 23 | #include "math.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class RadialDistortionFilter : public IImageFilter{ 28 | 29 | public: 30 | float Radius; 31 | float Distortion; 32 | Point *Center; 33 | 34 | RadialDistortionFilter() : Radius(0.5), Distortion(1.5){ 35 | Center = new Point(0.5f, 0.5f); 36 | } 37 | 38 | RadialDistortionFilter(float radius, float distortion): Radius(radius), Distortion(distortion){ 39 | Center = new Point(0.5f, 0.5f); 40 | } 41 | 42 | virtual Image process(Image imageIn) { 43 | int r, g, b; 44 | int width = imageIn.getWidth(); 45 | int height = imageIn.getHeight(); 46 | int realxpos = (int)(width * Center->X); 47 | int realypos = (int)(height * Center->Y); 48 | float realradius = min(width, height) * Radius; 49 | Image clone = imageIn.clone(); 50 | for (int x = 0; x < width; x++) 51 | { 52 | for (int y = 0; y < height; y++) 53 | { 54 | float pos = 1 - ((float)sqrt((double)(((x - realxpos) * (x - realxpos)) + (y - realypos) * (y - realypos))) / realradius); 55 | if (pos > 0) 56 | { 57 | pos = 1 - (Distortion * pos * pos); 58 | float pos1 = (x - realxpos) * pos + realxpos; 59 | float pos2 = (y - realypos) * pos + realypos; 60 | int x1 = (int)pos1; 61 | float pos3 = pos1 - x1; 62 | int x2 = (pos3 > 0) ? (x1 + 1) : x1; 63 | int y1 = (int)pos2; 64 | float pos4 = pos2 - y1; 65 | int y2 = (pos4 > 0) ? (y1 + 1) : y1; 66 | if (x1 < 0){ 67 | x1 = 0; 68 | } 69 | else if (x1 >= width){ 70 | x1 = width - 1; 71 | } 72 | if (x2 < 0){ 73 | x2 = 0; 74 | } 75 | else if (x2 >= width){ 76 | x2 = width - 1; 77 | } 78 | if (y1 < 0){ 79 | y1 = 0; 80 | } 81 | else if (y1 >= height){ 82 | y1 = height - 1; 83 | } 84 | if (y2 < 0){ 85 | y2 = 0; 86 | } 87 | else if (y2 >= height){ 88 | y2 = height - 1; 89 | } 90 | r = clone.getRComponent(x1, y1); 91 | g = clone.getGComponent(x1, y1); 92 | b = clone.getBComponent(x1, y1); 93 | 94 | int r2 = clone.getRComponent(x2, y1); 95 | int g2 = clone.getGComponent(x2, y1); 96 | int b2 = clone.getBComponent(x2, y1); 97 | int r3 = clone.getRComponent(x2, y2); 98 | int g3 = clone.getGComponent(x2, y2); 99 | int b3 = clone.getBComponent(x2, y2); 100 | int r4 = clone.getRComponent(x1, y2); 101 | int g4 = clone.getGComponent(x1, y2); 102 | int b4 = clone.getBComponent(x1, y2); 103 | r = (int)((r * (1 - pos4) * (1 - pos3) + r2 * (1 - pos4) * pos3 + r3 * pos4 * pos3) + r4 * pos4 * (1 - pos3)); 104 | g = (int)((g * (1 - pos4) * (1 - pos3) + g2 * (1 - pos4) * pos3 + g3 * pos4 * pos3) + g4 * pos4 * (1 - pos3)); 105 | b = (int)((b * (1 - pos4) * (1 - pos3) + b2 * (1 - pos4) * pos3 + b3 * pos4 * pos3) + b4 * pos4 * (1 - pos3)); 106 | } 107 | else { 108 | r = clone.getRComponent(x, y); 109 | g = clone.getGComponent(x, y); 110 | b = clone.getBComponent(x, y); 111 | } 112 | imageIn.setPixelColor(x,y,r,g,b); 113 | } 114 | } 115 | #ifndef WIN32 //only for apple ios 116 | imageIn.copyPixelsFromBuffer(); 117 | #endif 118 | return imageIn; 119 | } 120 | }; 121 | 122 | }// namespace HaoRan 123 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/RainBowFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(RainBowFilter_H) 19 | #define RainBowFilter_H 20 | 21 | #include "ImageBlender.h" 22 | #include "GradientFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class RainBowFilter : public IImageFilter{ 28 | private: 29 | ImageBlender blender; 30 | GradientFilter gradientFx; 31 | 32 | public: 33 | float gradAngleDegree; 34 | bool IsDoubleRainbow; 35 | 36 | RainBowFilter(){ 37 | IsDoubleRainbow = true; 38 | gradAngleDegree = 40; 39 | 40 | blender.Mixture = 0.25f; 41 | blender.Mode = Additive;//LinearLight; 42 | 43 | vector rainbowColors = Gradient::RainBow().MapColors; 44 | if (IsDoubleRainbow) 45 | { 46 | rainbowColors.erase(rainbowColors.begin() + rainbowColors.size() - 1);//remove red 47 | vector vi = Gradient::RainBow().MapColors; 48 | for(vector::iterator it = vi.begin(); it!=vi.end(); it++){ 49 | rainbowColors.push_back(*it); 50 | } 51 | } 52 | gradientFx.OriginAngleDegree = gradAngleDegree; 53 | Gradient gradient(rainbowColors); 54 | gradientFx.gradient = gradient; 55 | }; 56 | 57 | virtual Image process(Image imageIn) 58 | { 59 | Image clone = gradientFx.process(imageIn.clone()); 60 | return blender.Blend(imageIn, clone); 61 | } 62 | }; 63 | 64 | }// namespace HaoRan 65 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/RaiseFrameFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(RaiseFrameFilter_H) 20 | #define RaiseFrameFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class RaiseFrameFilter : public IImageFilter{ 28 | int _size ; 29 | public: 30 | 31 | RaiseFrameFilter(int size) 32 | { 33 | _size = ((size >= 1) ? size : 1) ; 34 | }; 35 | 36 | virtual Image process(Image imageIn) 37 | { 38 | int r, g, b, a = 20; 39 | int width = imageIn.getWidth(); 40 | int height = imageIn.getHeight(); 41 | for(int x = 0 ; x < width ; x++){ 42 | for(int y = 0 ; y < height; y++){ 43 | r = imageIn.getRComponent(x, y); 44 | g = imageIn.getGComponent(x, y); 45 | b = imageIn.getBComponent(x, y); 46 | int cr ; 47 | if ((x < _size) && (y < height-x) && (y >= x)) 48 | cr = Color::rgb(255,255,65) ; // left 49 | else if ((y < _size) && (x < width-y) && (x >= y)) 50 | cr = Color::rgb(255,255,120) ; // top 51 | else if ((x >width-_size) && (y >= width-x) && (y < height+x-width)) 52 | cr = Color::rgb(0,0,65) ; // right 53 | else if (y >height-_size) 54 | cr = Color::rgb(0,0,120) ; // bottom 55 | else 56 | continue; 57 | 58 | Color color(cr); 59 | int t = 0xFF - a ; 60 | imageIn.setPixelColor(x, y, (color.R * a + r * t) / 0xFF, (color.G * a + g * t) / 0xFF, (color.B * a + b * t) / 0xFF); 61 | } 62 | } 63 | #ifndef WIN32 //only for apple ios 64 | imageIn.copyPixelsFromBuffer(); 65 | #endif 66 | return imageIn; 67 | } 68 | }; 69 | 70 | }// namespace HaoRan 71 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/RectMatrixFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/RectMatrixFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/ReflectionFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ReflectionFilter_H) 20 | #define ReflectionFilter_H 21 | 22 | 23 | #include "IImageFilter.h" 24 | 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class ReflectionFilter : public IImageFilter{ 29 | 30 | public: 31 | /** 32 | * ˮƽͶӰ? 33 | */ 34 | bool IsHorizontal; 35 | float Offset; 36 | 37 | ReflectionFilter(bool isHorizontal) :IsHorizontal(isHorizontal), Offset(0.5f) {}; 38 | 39 | virtual Image process(Image imageIn) 40 | { 41 | int r, g, b; 42 | int height = imageIn.getHeight(); 43 | int width = imageIn.getWidth(); 44 | int start; 45 | int limit; 46 | Image clone = imageIn.clone(); 47 | 48 | if (IsHorizontal) 49 | { 50 | int y_offset = (int) (Offset * height); 51 | if (Offset > 0.5f) { 52 | start = y_offset - (height - y_offset); 53 | limit = y_offset; 54 | } 55 | else{ 56 | start = y_offset; 57 | limit = y_offset + y_offset; 58 | } 59 | if (start < 0) { 60 | start = 0; 61 | } 62 | for (int y = start; (y < limit) && (y < height); y++) 63 | { 64 | int y_pos = (-y + (2 * y_offset)) - 1; 65 | y_pos = (y_pos < 0) ? 0 : (y_pos >= height ? height - 1 : y_pos) ; 66 | for (int x = 0; x < width; x++) 67 | { 68 | r = clone.getRComponent(x, y); 69 | g = clone.getGComponent(x, y); 70 | b = clone.getBComponent(x, y); 71 | imageIn.setPixelColor(x, y_pos, r, g, b); 72 | } 73 | } 74 | } 75 | else { 76 | int x_offset = (int) (Offset * width); 77 | if (Offset > 0.5f){ 78 | start = x_offset - (width - x_offset); 79 | limit = x_offset; 80 | } 81 | else { 82 | start = x_offset; 83 | limit = x_offset + x_offset; 84 | } 85 | if (start < 0){ 86 | start = 0; 87 | } 88 | for (int x = start; (x < limit) && (x < width); x++) 89 | { 90 | int x_pos = (-x + (2 * x_offset)) - 1; 91 | x_pos = x_pos < 0 ? 0 : (x_pos >= width ? width - 1: x_pos); 92 | for (int y = 0; y < height; y++) 93 | { 94 | r = clone.getRComponent(x, y); 95 | g = clone.getGComponent(x, y); 96 | b = clone.getBComponent(x, y); 97 | imageIn.setPixelColor(x_pos, y, r, g, b); 98 | } 99 | } 100 | } 101 | #ifndef WIN32 //only for apple ios 102 | imageIn.copyPixelsFromBuffer(); 103 | #endif 104 | return imageIn; 105 | } 106 | }; 107 | 108 | }// namespace HaoRan 109 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ReliefFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/ReliefFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/SaturationModifyFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(SaturationModifyFilter_H) 20 | #define SaturationModifyFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class SaturationModifyFilter : public IImageFilter{ 28 | 29 | public: 30 | float SaturationFactor; 31 | SaturationModifyFilter() : SaturationFactor(0.5f){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | float saturation = SaturationFactor + 1; 36 | float negosaturation = 1 - saturation; 37 | int r, g, b; 38 | for (int x = 0; x < imageIn.getWidth(); x++) { 39 | for (int y = 0; y < imageIn.getHeight(); y++) { 40 | r = imageIn.getRComponent(x, y); 41 | g = imageIn.getGComponent(x, y); 42 | b = imageIn.getBComponent(x, y); 43 | 44 | float nego1 = negosaturation * 0.2126; 45 | float ngeo2 = nego1 + saturation; 46 | float ngeo3 = negosaturation * 0.7152; 47 | float nego4 = ngeo3 + saturation; 48 | float nego5 = negosaturation * 0.0722; 49 | float nego6 = nego5 + saturation; 50 | float rr = ((r * ngeo2) + (g * ngeo3)) + (b * nego5); 51 | float gg = ((r * nego1) + (g * nego4)) + (b * nego5); 52 | float bb = ((r * nego1) + (g * ngeo3)) + (b * nego6); 53 | r = SAFECOLOR(rr); 54 | g = SAFECOLOR(gg); 55 | b = SAFECOLOR(bb); 56 | imageIn.setPixelColor(x,y,r,g,b); 57 | } 58 | } 59 | #ifndef WIN32 //only for apple ios 60 | imageIn.copyPixelsFromBuffer(); 61 | #endif 62 | return imageIn; 63 | } 64 | }; 65 | 66 | }// namespace HaoRan 67 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SceneFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(SceneFilter_H) 19 | #define SceneFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "GradientFilter.h" 23 | #include "SaturationModifyFilter.h" 24 | #include "ImageBlender.h" 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | class SceneFilter : public IImageFilter{ 29 | 30 | private: 31 | GradientFilter gradientFx; 32 | SaturationModifyFilter saturationFx; 33 | 34 | public: 35 | 36 | SceneFilter(float angle, Gradient gradient) 37 | { 38 | gradientFx.gradient = gradient; 39 | gradientFx.OriginAngleDegree = angle; 40 | 41 | saturationFx.SaturationFactor = -0.6f; 42 | }; 43 | 44 | virtual Image process(Image imageIn) 45 | { 46 | Image clone = imageIn.clone(); 47 | imageIn = gradientFx.process(imageIn); 48 | ImageBlender blender; 49 | blender.Mode = ::Subractive; 50 | imageIn = saturationFx.process(blender.Blend(clone, imageIn)); 51 | 52 | #ifndef WIN32 //only for apple ios 53 | imageIn.copyPixelsFromBuffer(); 54 | #endif 55 | return imageIn; 56 | //return imageIn;// saturationFx.process(imageIn); 57 | } 58 | }; 59 | 60 | }// namespace HaoRan 61 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SepiaFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(SepiaFilter_H) 20 | #define SepiaFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class SepiaFilter : public IImageFilter{ 28 | private: 29 | GradientMapFilter gradientMapFx; 30 | SaturationModifyFilter saturationFx; 31 | public: 32 | 33 | SepiaFilter(){ 34 | gradientMapFx.Map = Gradient::BlackSepia(); 35 | gradientMapFx.ContrastFactor = 0.2f; 36 | gradientMapFx.BrightnessFactor = 0.1f; 37 | 38 | saturationFx.SaturationFactor = -0.6f; 39 | }; 40 | 41 | virtual Image process(Image imageIn) 42 | { 43 | imageIn = gradientMapFx.process(imageIn); 44 | return saturationFx.process(imageIn); 45 | } 46 | }; 47 | 48 | }// namespace HaoRan 49 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SharpFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/SharpFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/ShiftFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ShiftFilter_H) 20 | #define ShiftFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class ShiftFilter : public IImageFilter{ 28 | 29 | private: 30 | int _amount ; // max shift pixel 31 | 32 | public: 33 | /** 34 | Constructor \n 35 | amount >= 2. 36 | */ 37 | ShiftFilter(int amount) 38 | { 39 | _amount = ((amount >= 2) ? amount : 2) ; 40 | } 41 | 42 | 43 | virtual Image process(Image imageIn) 44 | { 45 | int r, g, b, sx, m_current; 46 | int width = imageIn.getWidth(); 47 | int height = imageIn.getHeight(); 48 | Image clone = imageIn.clone(); 49 | for(int y = 0 ; y < height ; y++){ 50 | for(int x = 0 ; x < width ; x++){ 51 | if (x == 0) { 52 | m_current = (rand() % _amount) * ((rand() % 2) ? 1 : -1) ; 53 | } 54 | int sx = FClamp(x+m_current, 0, width-1); 55 | r = clone.getRComponent(sx, y); 56 | g = clone.getGComponent(sx, y); 57 | b = clone.getBComponent(sx, y); 58 | imageIn.setPixelColor(x, y, r, g, b); 59 | } 60 | } 61 | #ifndef WIN32 //only for apple ios 62 | imageIn.copyPixelsFromBuffer(); 63 | #endif 64 | return imageIn; 65 | } 66 | }; 67 | 68 | }// namespace HaoRan 69 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SmashColorFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(SmashColorFilter_H) 20 | #define SmashColorFilter_H 21 | 22 | #include "ParamEdgeDetectFilter.h" 23 | #include "ImageBlender.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class SmashColorFilter : public IImageFilter{ 28 | 29 | public: 30 | 31 | SmashColorFilter(){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | ParamEdgeDetectFilter pde; 36 | pde.K00 = 1; 37 | pde.K01 = 2; 38 | pde.K02 = 1; 39 | pde.Threshold = 0.25f; 40 | pde.DoGrayConversion = false; 41 | pde.DoInversion = false; 42 | ImageBlender ib; 43 | ib.Mode = ::LinearLight; 44 | ib.Mixture = 2.5f; 45 | return ib.Blend(imageIn.clone(), pde.process(imageIn)); 46 | } 47 | }; 48 | 49 | }// namespace HaoRan 50 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SoftGlowFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | #if !defined(SoftGlowFilter_H) 19 | #define SoftGlowFilter_H 20 | 21 | #include "IImageFilter.h" 22 | #include "BrightContrastFilter.h" 23 | #include "GaussianBlurFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class SoftGlowFilter : public IImageFilter{ 28 | 29 | private: 30 | BrightContrastFilter contrastFx; 31 | 32 | GaussianBlurFilter gaussianBlurFx; 33 | 34 | public: 35 | 36 | SoftGlowFilter(int nSigma, float nBrightness, float nContrast){ 37 | contrastFx.BrightnessFactor = nBrightness; 38 | contrastFx.ContrastFactor = nContrast; 39 | gaussianBlurFx.Sigma = nSigma; 40 | }; 41 | 42 | virtual Image process(Image imageIn) 43 | { 44 | Image clone = imageIn.clone(); 45 | imageIn = gaussianBlurFx.process(imageIn); 46 | imageIn = contrastFx.process(imageIn); 47 | 48 | int old_r, old_g, old_b, r, g, b; 49 | for(int x = 0 ; x < (imageIn.getWidth() - 1) ; x++){ 50 | for(int y = 0 ; y < (imageIn.getHeight() - 1) ; y++){ 51 | old_r = clone.getRComponent(x, y); 52 | old_g = clone.getGComponent(x, y); 53 | old_b = clone.getBComponent(x, y); 54 | 55 | r = 255 - (255 - old_r)*(255 - imageIn.getRComponent(x, y))/255 ; 56 | g = 255 - (255 - old_g)*(255 - imageIn.getGComponent(x, y))/255 ; 57 | b = 255 - (255 - old_b)*(255 - imageIn.getBComponent(x, y))/255 ; 58 | imageIn.setPixelColor(x, y, r, g, b); 59 | } 60 | } 61 | 62 | 63 | #ifndef WIN32 //only for apple ios 64 | imageIn.copyPixelsFromBuffer(); 65 | #endif 66 | return imageIn; 67 | } 68 | }; 69 | 70 | }// namespace HaoRan 71 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/SupernovaFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(SupernovaFilter_H) 20 | #define SupernovaFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class SupernovaFilter : public IImageFilter{ 28 | 29 | private: 30 | Point _pt ; 31 | double _radius ; 32 | int _count ; 33 | 34 | std::vector _spoke ; 35 | std::vector _spokecolor ; 36 | 37 | static double get_gauss() 38 | { 39 | double s = 0 ; 40 | for (int i=0 ; i < 6 ; i++) 41 | s = s + rand() / (double)(RAND_MAX + 1.0) ; 42 | return s / 6.0 ; 43 | } 44 | 45 | static int BoundParam1 (int n) 46 | { 47 | return ((n >= 1) ? n : 1) ; 48 | } 49 | 50 | public: 51 | 52 | SupernovaFilter(Point pt, int cr, int radius, int count) : _spoke(BoundParam1(count)), _spokecolor(BoundParam1(count)) 53 | { 54 | _pt = pt ; 55 | _radius = BoundParam1(radius) ; 56 | _count = BoundParam1(count) ; 57 | 58 | for (int i=0 ; i < _count ; i++) 59 | { 60 | _spoke[i] = get_gauss() ; 61 | _spokecolor[i] = cr ; 62 | } 63 | } 64 | 65 | SupernovaFilter(int cr, int radius, int count) : _pt(Point(0,0)), _spoke(BoundParam1(count)), _spokecolor(BoundParam1(count)) 66 | { 67 | _radius = BoundParam1(radius) ; 68 | _count = BoundParam1(count) ; 69 | 70 | for (int i=0 ; i < _count ; i++) 71 | { 72 | _spoke[i] = get_gauss() ; 73 | _spokecolor[i] = cr ; 74 | } 75 | } 76 | 77 | virtual Image process(Image imageIn) 78 | { 79 | if((_pt.X + _pt.Y) <= 0){ 80 | _pt.X = imageIn.getWidth() /2; 81 | _pt.Y = imageIn.getHeight() /2; 82 | } 83 | for(int x = 0 ; x < (imageIn.getWidth() - 1) ; x++){ 84 | for(int y = 0 ; y < (imageIn.getHeight() - 1) ; y++){ 85 | std::vector pixel(3); 86 | pixel[0] = imageIn.getRComponent(x, y); 87 | pixel[1] = imageIn.getGComponent(x, y); 88 | pixel[2] = imageIn.getBComponent(x, y); 89 | 90 | double u = (x - _pt.X + 0.001) / _radius ; 91 | double v = (y - _pt.Y + 0.001) / _radius ; 92 | 93 | double t = (atan2 (u, v) / (2 * LIB_PI) + 0.51) * _count ; 94 | int i = (int)floor(t) ; 95 | t -= i ; 96 | i %= _count ; 97 | 98 | double w1 = _spoke[i] * (1-t) + _spoke[(i+1) % _count] * t ; 99 | w1 = w1 * w1 ; 100 | 101 | double w = 1.0 / sqrt (u*u + v*v) * 0.9 ; 102 | double fRatio = FClamp (w, 0.0, 1.0) ; 103 | 104 | double ws = FClamp (w1 * w, 0.0, 1.0) ; 105 | 106 | for (int m=0 ; m < 3 ; m++) 107 | { 108 | double spokecol = ((BYTE*)&_spokecolor[i])[m]/255.0 * (1-t) + ((BYTE*)&_spokecolor[(i+1) % _count])[m]/255.0 * t ; 109 | 110 | double r; 111 | if (w > 1.0) 112 | r = FClamp (spokecol * w, 0.0, 1.0); 113 | else { 114 | r = pixel[m]/255.0 * (1.0 - fRatio) + spokecol * fRatio ; 115 | } 116 | 117 | r += ws ; 118 | pixel[m] = FClamp0255 (r*255) ; 119 | imageIn.setPixelColor(x, y, pixel[0], pixel[1], pixel[2]); 120 | } 121 | } 122 | } 123 | #ifndef WIN32 //only for apple ios 124 | imageIn.copyPixelsFromBuffer(); 125 | #endif 126 | return imageIn; 127 | } 128 | }; 129 | 130 | }// namespace HaoRan 131 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/CloudsTexture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/Textures/CloudsTexture.h -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/ITextureGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ITextureGeneratorH) 20 | #define ITextureGeneratorH 21 | 22 | #include 23 | 24 | namespace HaoRan_ImageFilter{ 25 | 26 | class ITextureGenerator{ 27 | 28 | public: 29 | /// 30 | /// Generate texture 31 | /// 32 | /// 33 | /// Texture's width 34 | /// Texture's height 35 | /// 36 | /// Two dimensional array of intensities 37 | /// 38 | /// Generates new texture with specified dimension. 39 | /// 40 | virtual vector< vector > Generate( int width, int height ){ return (vector< vector >)NULL;}; 41 | 42 | /// 43 | /// Reset generator 44 | /// 45 | /// 46 | /// Resets the generator - resets interl variables, regenerates 47 | /// internal random numbers, etc. 48 | /// 49 | virtual void Reset( ){} 50 | 51 | }; 52 | 53 | }// namespace HaoRan 54 | #endif 55 | -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/LabyrinthTexture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/Textures/LabyrinthTexture.h -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/MarbleTexture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/Textures/MarbleTexture.h -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/PerlinNoise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(PerlinNoiseH) 20 | #define PerlinNoiseH 21 | 22 | #include "../IImageFilter.h" 23 | 24 | namespace HaoRan_ImageFilter 25 | { 26 | // http://www.student.kuleuven.ac.be/~m0216922/CG/perlinnoise.html 27 | /// 28 | /// Perlin Noise function 29 | /// 30 | /// 31 | /// The class represents Gaussian function. 32 | /// 33 | class PerlinNoise 34 | { 35 | 36 | private: 37 | double m_initFrequency;// = 1.0 / 16; 38 | double m_initAmplitude;// = 1.0f; 39 | double m_persistance;// = 0.65; 40 | int m_octaves;// = 4; 41 | 42 | public: 43 | 44 | /// 45 | /// Initial frequency 46 | /// 47 | double InitFrequency; 48 | 49 | /// 50 | /// Initial aplitude 51 | /// 52 | double InitAplitude; 53 | 54 | /// 55 | /// Persistance 56 | /// 57 | double Persistance; 58 | 59 | /// 60 | /// Octaves 61 | /// 62 | int Octaves; 63 | 64 | 65 | /// 66 | /// Initializes a new instance of the class 67 | /// 68 | /// 69 | PerlinNoise( ) { } 70 | 71 | /// 72 | /// Initializes a new instance of the class 73 | /// 74 | /// 75 | /// Initial frequency 76 | /// Initial amplitude 77 | /// Persistance 78 | /// Octaves 79 | /// 80 | PerlinNoise( double initFrequency, double initAmplitude, double persistance, int octaves ) 81 | { 82 | m_initFrequency = initFrequency; 83 | m_initAmplitude = initAmplitude; 84 | m_persistance = persistance; 85 | m_octaves = octaves; 86 | } 87 | 88 | /// 89 | /// 1-D Perlin noise function 90 | /// 91 | /// 92 | /// x value 93 | /// 94 | /// Returns function's value at point x. 95 | /// 96 | double Function( double x ) 97 | { 98 | double frequency = m_initFrequency; 99 | double amplitude = m_initAmplitude; 100 | double sum = 0; 101 | 102 | // octaves 103 | for ( int i = 0; i < m_octaves; i++ ) 104 | { 105 | sum += SmoothedNoise( x * frequency ) * amplitude; 106 | 107 | frequency *= 2; 108 | amplitude *= m_persistance; 109 | } 110 | return sum; 111 | } 112 | 113 | /// 114 | /// 2-D Perlin noise function 115 | /// 116 | /// 117 | /// x value 118 | /// y value 119 | /// 120 | /// Returns function's value at point (x, y). 121 | /// 122 | double Function2D( double x, double y ) 123 | { 124 | double frequency = m_initFrequency; 125 | double amplitude = m_initAmplitude; 126 | double sum = 0; 127 | 128 | // octaves 129 | for ( int i = 0; i < m_octaves; i++ ) 130 | { 131 | sum += SmoothedNoise( x * frequency, y * frequency ) * amplitude; 132 | 133 | frequency *= 2; 134 | amplitude *= m_persistance; 135 | } 136 | return sum; 137 | } 138 | 139 | 140 | /// 141 | /// Ordinary noise function 142 | /// 143 | double Noise( int x ) 144 | { 145 | int n = ( x << 13 ) ^ x; 146 | 147 | return ( 1.0 - ( ( n * ( n * n * 15731 + 789221 ) + 1376312589 ) & 0x7fffffff ) / 1073741824.0 ); 148 | } 149 | 150 | double Noise( int x, int y ) 151 | { 152 | int n = x + y * 57; 153 | n = ( n << 13 ) ^ n ; 154 | 155 | return ( 1.0 - ( ( n * ( n * n * 15731 + 789221 ) + 1376312589 ) & 0x7fffffff ) / 1073741824.0 ); 156 | } 157 | 158 | private: 159 | /// 160 | /// Smoothed noise 161 | /// 162 | double SmoothedNoise( double x ) 163 | { 164 | int xInt = (int) x; 165 | double xFrac = x - xInt; 166 | 167 | return CosineInterpolate( Noise( xInt ) , Noise( xInt + 1 ), xFrac ); 168 | } 169 | 170 | double SmoothedNoise( double x, double y ) 171 | { 172 | int xInt = (int) x; 173 | int yInt = (int) y; 174 | double xFrac = x - xInt; 175 | double yFrac = y - yInt; 176 | 177 | // get four noise values 178 | double x0y0 = Noise( xInt , yInt ); 179 | double x1y0 = Noise( xInt + 1, yInt ); 180 | double x0y1 = Noise( xInt , yInt + 1 ); 181 | double x1y1 = Noise( xInt + 1, yInt + 1) ; 182 | 183 | // x interpolation 184 | double v1 = CosineInterpolate( x0y0, x1y0, xFrac ); 185 | double v2 = CosineInterpolate( x0y1, x1y1, xFrac ); 186 | // y interpolation 187 | return CosineInterpolate( v1, v2, yFrac ); 188 | } 189 | 190 | 191 | /// 192 | /// Cosine interpolation 193 | /// 194 | double CosineInterpolate( double x1, double x2, double a ) 195 | { 196 | double f = ( 1 - cos( a * LIB_PI ) ) * 0.5; 197 | 198 | return x1 * ( 1 - f ) + x2 * f; 199 | } 200 | 201 | }; 202 | 203 | }// namespace HaoRan 204 | #endif 205 | -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/TextileTexture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/Textures/TextileTexture.h -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/TexturerFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #include 20 | #include "../IImageFilter.h" 21 | #include "ITextureGenerator.h" 22 | 23 | #if !defined(TexturerFilterH) 24 | #define TexturerFilterH 25 | 26 | namespace HaoRan_ImageFilter{ 27 | 28 | /// 29 | /// Texturer filter 30 | /// 31 | /// 32 | /// Adjust pixel colors using factors from texture. 33 | /// 34 | class TexturerFilter : public IImageFilter 35 | { 36 | 37 | private: 38 | // texture generator 39 | ITextureGenerator *m_textureGenerator; 40 | // generated texture 41 | vector< vector > m_texture; 42 | 43 | // filtering factor 44 | double m_filterLevel;// = 0.5; 45 | // preservation factor 46 | double m_preserveLevel;// = 0.5; 47 | 48 | public: 49 | 50 | /// 51 | /// Initializes a new instance of the class 52 | /// 53 | /// 54 | /// Generated texture 55 | /// 56 | TexturerFilter(vector< vector > texture ) 57 | { 58 | m_texture = texture; 59 | }; 60 | 61 | /// 62 | /// Initializes a new instance of the class 63 | /// 64 | /// 65 | /// Generated texture 66 | /// Filter level value 67 | /// Preserve level value 68 | /// 69 | TexturerFilter(vector< vector > texture , double filterLevel, double preserveLevel ) 70 | { 71 | m_texture = texture; 72 | m_filterLevel = filterLevel; 73 | m_preserveLevel = preserveLevel; 74 | }; 75 | 76 | /// 77 | /// Initializes a new instance of the class 78 | /// 79 | /// 80 | /// Texture generator 81 | /// 82 | TexturerFilter( ITextureGenerator *generator ) 83 | { 84 | m_textureGenerator = generator; 85 | }; 86 | 87 | /// 88 | /// Initializes a new instance of the class 89 | /// 90 | /// 91 | /// Texture generator 92 | /// Filter level value 93 | /// Preserve level value 94 | /// 95 | TexturerFilter(ITextureGenerator *generator, double filterLevel, double preserveLevel) 96 | { 97 | m_textureGenerator = generator; 98 | m_filterLevel = filterLevel; 99 | m_preserveLevel = preserveLevel; 100 | } 101 | 102 | 103 | virtual Image process(Image imageIn) 104 | { 105 | // get source image size 106 | int width = imageIn.getWidth(); 107 | int height = imageIn.getHeight(); 108 | 109 | // processing region's dimension 110 | int widthToProcess = width; 111 | int heightToProcess = height; 112 | 113 | // if generator was specified, then generate a texture 114 | // otherwise use provided texture 115 | if ( m_textureGenerator != NULL ) 116 | { 117 | m_texture = m_textureGenerator->Generate( width, height ); 118 | } 119 | else 120 | { 121 | widthToProcess = width;//min( width, m_texture.l.GetLength( 1 ) ); 122 | heightToProcess = height;//min( height, m_texture.GetLength( 0 ) ); 123 | } 124 | 125 | int r, g, b; 126 | 127 | // texture 128 | for ( int y = 0; y < heightToProcess; y++ ) 129 | { 130 | for ( int x = 0; x < widthToProcess; x++ ) 131 | { 132 | double t = m_texture[y][x]; 133 | r = imageIn.getRComponent(x, y); 134 | g = imageIn.getGComponent(x, y); 135 | b = imageIn.getBComponent(x, y); 136 | // process each pixel 137 | 138 | r = (byte) MIN( 255.0f, ( m_preserveLevel * r) + ( m_filterLevel * r) * t ); 139 | g = (byte) MIN( 255.0f, ( m_preserveLevel * g) + ( m_filterLevel * g) * t ); 140 | b = (byte) MIN( 255.0f, ( m_preserveLevel * b) + ( m_filterLevel * b) * t ); 141 | imageIn.setPixelColor(x, y, r, g, b); 142 | } 143 | } 144 | #ifndef WIN32 //only for apple ios 145 | imageIn.copyPixelsFromBuffer(); 146 | #endif 147 | return imageIn; 148 | } 149 | 150 | }; 151 | }// namespace HaoRan 152 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/Textures/WoodTexture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/Textures/WoodTexture.h -------------------------------------------------------------------------------- /Classes/imageFilter/ThreeDGridFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ThreeDGridFilter_h) 20 | #define ThreeDGridFilter_h 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class ThreeDGridFilter : public IImageFilter{ 28 | private: 29 | int _size ; 30 | int _depth ; 31 | public: 32 | 33 | ThreeDGridFilter(int size, int depth) 34 | { 35 | _size = ((size >= 1) ? size : 1) ; 36 | _depth = depth ; 37 | }; 38 | 39 | virtual Image process(Image imageIn) 40 | { 41 | int r, g, b; 42 | for(int x = 0 ; x < imageIn.getWidth() ; x++){ 43 | for(int y = 0 ; y < imageIn.getHeight() ; y++){ 44 | r = imageIn.getRComponent(x, y); 45 | g = imageIn.getGComponent(x, y); 46 | b = imageIn.getBComponent(x, y); 47 | 48 | int d = 0 ; 49 | if (((y-1) % _size == 0) && (x % _size) && ((x+1) % _size)) 50 | d = -_depth ; // top 51 | else if (((y+2) % _size == 0) && (x % _size) && ((x+1) % _size)) 52 | d = _depth ; // bottom 53 | else if (((x-1) % _size == 0) && (y % _size) && ((y+1) % _size)) 54 | d = _depth ; // left 55 | else if (((x+2) % _size == 0) && (y % _size) && ((y+1) % _size)) 56 | d = -_depth ; // right 57 | 58 | imageIn.setPixelColor(x, y, SAFECOLOR(r+d), SAFECOLOR(g+d), SAFECOLOR(b+d)); 59 | } 60 | } 61 | #ifndef WIN32 //only for apple ios 62 | imageIn.copyPixelsFromBuffer(); 63 | #endif 64 | return imageIn; 65 | } 66 | }; 67 | 68 | }// namespace HaoRan 69 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/ThresholdFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | 20 | #if !defined(ThresholdFilter_H) 21 | #define ThresholdFilter_H 22 | 23 | #include "IImageFilter.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class ThresholdFilter : public IImageFilter{ 28 | private: 29 | float Threshold; 30 | public: 31 | 32 | ThresholdFilter() : Threshold(0.5){}; 33 | 34 | virtual Image process(Image imageIn) 35 | { 36 | int r, g, b; 37 | int threshold = (int)(Threshold * 255); 38 | 39 | for (int x = 0; x < imageIn.getWidth(); x++) { 40 | for (int y = 0; y < imageIn.getHeight(); y++) { 41 | r = imageIn.getRComponent(x, y); 42 | g = imageIn.getGComponent(x, y); 43 | b = imageIn.getBComponent(x, y); 44 | 45 | int rgb = (((r * 0x1b36) + (g * 0x5b8c)) + (b * 0x93e)) >> 15; 46 | r = g = b = rgb > threshold ? 0xff : 0; 47 | imageIn.setPixelColor(x,y,r,g,b); 48 | } 49 | } 50 | #ifndef WIN32 //only for apple ios 51 | imageIn.copyPixelsFromBuffer(); 52 | #endif 53 | return imageIn; 54 | } 55 | }; 56 | 57 | }// namespace HaoRan 58 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/TileReflectionFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/TileReflectionFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/TintFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(TintFilter_H) 20 | #define TintFilter_H 21 | 22 | #include "GradientFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class TintFilter : public IImageFilter{ 28 | 29 | public: 30 | 31 | TintFilter(){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int tr = ::Red; 36 | int tg = ::Green; 37 | int tb = ::Blue; 38 | int r,g,b; 39 | for (int x = 0; x < imageIn.getWidth(); x++) { 40 | for (int y = 0; y < imageIn.getHeight(); y++) { 41 | r = (255-imageIn.getRComponent(x, y)); 42 | g = (255-imageIn.getGComponent(x, y)); 43 | b = (255-imageIn.getBComponent(x, y)); 44 | 45 | // Convert to gray with constant factors 0.2126, 0.7152, 0.0722 46 | int gray = (r * 6966 + g * 23436 + b * 2366) >> 15; 47 | 48 | // Apply Tint color 49 | r = (byte)((gray * tr) >> 8); 50 | g = (byte)((gray * tg) >> 8); 51 | b = (byte)((gray * tb) >> 8); 52 | 53 | imageIn.setPixelColor(x,y,r,g,b); 54 | } 55 | } 56 | #ifndef WIN32 //only for apple ios 57 | imageIn.copyPixelsFromBuffer(); 58 | #endif 59 | return imageIn; 60 | } 61 | }; 62 | 63 | }// namespace HaoRan 64 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/VideoFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.4 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(VideoFilter_H) 20 | #define VideoFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class VideoFilter : public IImageFilter{ 28 | 29 | public: 30 | enum VIDEO_TYPE { VIDEO_STAGGERED = 0, VIDEO_TRIPED = 1, VIDEO_3X3 = 2, VIDEO_DOTS = 3 } ; 31 | 32 | private: 33 | VIDEO_TYPE m_VideoType; 34 | 35 | public: 36 | 37 | VideoFilter(VIDEO_TYPE nVideoType) 38 | { 39 | m_VideoType = nVideoType; 40 | 41 | }; 42 | 43 | virtual Image process(Image imageIn) 44 | { 45 | static const int pattern_width[] = {2, 1, 3, 5} ; 46 | static const int pattern_height[] = {6, 3, 3, 15} ; 47 | static const int video_pattern[4][15 * 5/* max pattern size */] = 48 | { 49 | { 50 | 0, 1, 51 | 0, 2, 52 | 1, 2, 53 | 1, 0, 54 | 2, 0, 55 | 2, 1, 56 | }, 57 | { 58 | 0, 59 | 1, 60 | 2, 61 | }, 62 | { 63 | 0, 1, 2, 64 | 2, 0, 1, 65 | 1, 2, 0, 66 | }, 67 | { 68 | 0, 1, 2, 0, 0, 69 | 1, 1, 1, 2, 0, 70 | 0, 1, 2, 2, 2, 71 | 0, 0, 1, 2, 0, 72 | 0, 1, 1, 1, 2, 73 | 2, 0, 1, 2, 2, 74 | 0, 0, 0, 1, 2, 75 | 2, 0, 1, 1, 1, 76 | 2, 2, 0, 1, 2, 77 | 2, 0, 0, 0, 1, 78 | 1, 2, 0, 1, 1, 79 | 2, 2, 2, 0, 1, 80 | 1, 2, 0, 0, 0, 81 | 1, 1, 2, 0, 1, 82 | 1, 2, 2, 2, 0, 83 | } 84 | }; 85 | 86 | int r, g, b; 87 | for (int x = 0; x < imageIn.getWidth(); x++) 88 | { 89 | for (int y = 0; y < imageIn.getHeight(); y++) 90 | { 91 | r = imageIn.getRComponent(x, y); 92 | g = imageIn.getGComponent(x, y); 93 | b = imageIn.getBComponent(x, y); 94 | 95 | int nWidth = pattern_width[(int)m_VideoType]; 96 | int nHeight = pattern_height[(int)m_VideoType]; 97 | int index = nWidth * (y % nHeight) + (x % nWidth); 98 | 99 | if (video_pattern[m_VideoType][index] == 0) 100 | r = FClamp0255(2 * r); 101 | if (video_pattern[m_VideoType][index] == 1) 102 | g = FClamp0255(2 * g); 103 | if (video_pattern[m_VideoType][index] == 2) 104 | b = FClamp0255(2 * b); 105 | 106 | imageIn.setPixelColor(x, y, r, g, b); 107 | } 108 | } 109 | 110 | #ifndef WIN32 //only for apple ios 111 | imageIn.copyPixelsFromBuffer(); 112 | #endif 113 | return imageIn; 114 | } 115 | }; 116 | 117 | }// namespace HaoRan 118 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/VignetteFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(VignetteFilter_H) 20 | #define VignetteFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class VignetteFilter : public IImageFilter{ 28 | public: 29 | float Size; 30 | 31 | VignetteFilter() : Size(0.5){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | int r, g, b; 36 | int ratio = imageIn.getWidth() > imageIn.getHeight() ? imageIn.getHeight() * 32768 / imageIn.getWidth() : imageIn.getWidth() * 32768 / imageIn.getHeight(); 37 | 38 | // Calculate center, min and max 39 | int cx = imageIn.getWidth() >> 1; 40 | int cy = imageIn.getHeight() >> 1; 41 | int max = cx * cx + cy * cy; 42 | int min = (int)(max * (1 - Size)); 43 | int diff = max - min; 44 | 45 | for (int x = 0; x < imageIn.getWidth(); x++) { 46 | for (int y = 0; y < imageIn.getHeight(); y++) { 47 | r = imageIn.getRComponent(x, y); 48 | g = imageIn.getGComponent(x, y); 49 | b = imageIn.getBComponent(x, y); 50 | 51 | // Calculate distance to center and adapt aspect ratio 52 | int dx = cx - x; 53 | int dy = cy - y; 54 | if (imageIn.getWidth() > imageIn.getHeight()){ 55 | dx = (dx * ratio) >> 15; 56 | } 57 | else{ 58 | dy = (dy * ratio) >> 15; 59 | } 60 | int distSq = dx * dx + dy * dy; 61 | 62 | if (distSq > min){ 63 | // Calculate vignette 64 | int v = ((max - distSq) << 8) / diff; 65 | v *= v; 66 | 67 | // Apply vignette 68 | int ri = (r * v) >> 16; 69 | int gi = (g * v) >> 16; 70 | int bi = (b * v) >> 16; 71 | 72 | // Check bounds 73 | r = SAFECOLOR(ri); 74 | g = SAFECOLOR(gi); 75 | b = SAFECOLOR(bi); 76 | } 77 | 78 | imageIn.setPixelColor(x,y,r,g,b); 79 | } 80 | } 81 | #ifndef WIN32 //only for apple ios 82 | imageIn.copyPixelsFromBuffer(); 83 | #endif 84 | return imageIn; 85 | } 86 | }; 87 | 88 | }// namespace HaoRan 89 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/VintageFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(VintageFilter_H) 20 | #define VintageFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class VintageFilter : public IImageFilter{ 28 | 29 | public: 30 | 31 | VintageFilter(){}; 32 | 33 | virtual Image process(Image imageIn) 34 | { 35 | GradientMapFilter gmf(Gradient::BlackSepia()); 36 | gmf.ContrastFactor = 0.15f; 37 | 38 | ImageBlender ib; 39 | ib.Mixture = 0.7f; 40 | ib.Mode = ::Overlay; 41 | imageIn = ib.Blend(imageIn.clone(), gmf.process(imageIn)); 42 | 43 | VignetteFilter vigette; 44 | vigette.Size = 0.7f; 45 | return vigette.process(imageIn); 46 | } 47 | }; 48 | 49 | }// namespace HaoRan 50 | #endif -------------------------------------------------------------------------------- /Classes/imageFilter/WaterWaveFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Classes/imageFilter/WaterWaveFilter.h -------------------------------------------------------------------------------- /Classes/imageFilter/XRadiationFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.1 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(XRadiationFilter_H) 20 | #define XRadiationFilter_H 21 | 22 | #include "GradientMapFilter.h" 23 | #include "ImageBlender.h" 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class XRadiationFilter : public IImageFilter{ 28 | private: 29 | GradientMapFilter gradientMapFx; 30 | ImageBlender blender; 31 | public: 32 | 33 | XRadiationFilter(){ 34 | vector colors(2); 35 | colors[0] = ::LightCyan; 36 | colors[1] = ::Black; 37 | Gradient gradient(colors); 38 | gradientMapFx.Map = gradient; 39 | blender.Mode = ::ColorBurn; 40 | blender.Mixture = 0.8f; 41 | }; 42 | 43 | virtual Image process(Image imageIn) 44 | { 45 | imageIn = gradientMapFx.process(imageIn); 46 | imageIn = blender.Blend(imageIn, imageIn); 47 | return imageIn; 48 | } 49 | }; 50 | 51 | }// namespace HaoRan 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Classes/imageFilter/ZoomBlurFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HaoRan ImageFilter Classes v0.3 3 | * Copyright (C) 2012 Zhenjun Dai 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by the 7 | * Free Software Foundation; either version 2.1 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation. 17 | */ 18 | 19 | #if !defined(ZoomBlurFilter_H) 20 | #define ZoomBlurFilter_H 21 | 22 | #include "IImageFilter.h" 23 | 24 | 25 | namespace HaoRan_ImageFilter{ 26 | 27 | class ZoomBlurFilter : public IImageFilter{ 28 | 29 | private: 30 | int m_length; 31 | double m_offset_x; 32 | double m_offset_y; 33 | int m_fcx, m_fcy; 34 | 35 | public: 36 | 37 | const static int RADIUS_LENGTH = 64; 38 | 39 | ZoomBlurFilter(int nLength, double offset_x = 0.0f, double offset_y = 0.0f) 40 | { 41 | m_length = (nLength >= 1) ? nLength : 1 ; 42 | m_offset_x = (offset_x > 2.0 ? 2.0 : ( offset_x< -2.0 ? 0 : offset_x)); 43 | m_offset_y =(offset_y > 2.0 ? 2.0 : ( offset_y< -2.0 ? 0 : offset_y)); 44 | } 45 | 46 | 47 | virtual Image process(Image imageIn) 48 | { 49 | int width = imageIn.getWidth(); 50 | int height = imageIn.getHeight(); 51 | m_fcx = (int)(width * m_offset_x * 32768.0) + (width * 32768) ; 52 | m_fcy = (int)(height * m_offset_y * 32768.0) + (height * 32768) ; 53 | 54 | const int ta = 255; 55 | Image clone = imageIn.clone(); 56 | for(int x = 0 ; x < width ; x++){ 57 | for(int y = 0 ; y < height ; y++){ 58 | int sr=0, sg=0, sb=0, sa=0; 59 | sr = clone.getRComponent(x, y) * ta; 60 | sg = clone.getGComponent(x, y) * ta; 61 | sb = clone.getBComponent(x, y) * ta; 62 | sa += ta; 63 | int fx = (x * 65536) - m_fcx ; 64 | int fy = (y * 65536) - m_fcy ; 65 | for (int i = 0 ; i < RADIUS_LENGTH ; i++) 66 | { 67 | fx = fx - (fx / 16) * m_length / 1024 ; 68 | fy = fy - (fy / 16) * m_length / 1024 ; 69 | 70 | int u = (fx + m_fcx + 32768) / 65536 ; 71 | int v = (fy + m_fcy + 32768) / 65536 ; 72 | if (u>=0 && u=0 && v 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ImagePicker 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | logo2.png 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /CustomImagePicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomImagePicker.xcodeproj/project.xcworkspace/xcuserdata/daizhenjun.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/CustomImagePicker.xcodeproj/project.xcworkspace/xcuserdata/daizhenjun.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CustomImagePicker.xcodeproj/xcuserdata/daizhenjun.xcuserdatad/xcschemes/CustomImagePicker.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 50 | 51 | 57 | 58 | 59 | 60 | 61 | 62 | 68 | 69 | 75 | 76 | 77 | 78 | 80 | 81 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /CustomImagePicker.xcodeproj/xcuserdata/daizhenjun.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CustomImagePicker.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1D6058900D05DD3D006BFB54 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CustomImagePicker_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CustomImagePicker' target in the 'CustomImagePicker' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /Koala.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/Koala.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ImageFilterForIOS 2 | ================= 3 | 4 | ImageFilter only for IOS -------------------------------------------------------------------------------- /icon/autoadjust_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/autoadjust_filter.jpg -------------------------------------------------------------------------------- /icon/banner_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/banner_filter1.jpg -------------------------------------------------------------------------------- /icon/banner_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/banner_filter2.jpg -------------------------------------------------------------------------------- /icon/bigbrother_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/bigbrother_filter.jpg -------------------------------------------------------------------------------- /icon/blackwhite_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/blackwhite_filter.jpg -------------------------------------------------------------------------------- /icon/blind_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/blind_filter1.jpg -------------------------------------------------------------------------------- /icon/blind_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/blind_filter2.jpg -------------------------------------------------------------------------------- /icon/blockprint_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/blockprint_filter.jpg -------------------------------------------------------------------------------- /icon/brick_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/brick_filter.jpg -------------------------------------------------------------------------------- /icon/brightcontrast_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/brightcontrast_filter.jpg -------------------------------------------------------------------------------- /icon/bulge_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/bulge_filter.jpg -------------------------------------------------------------------------------- /icon/camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/camera.png -------------------------------------------------------------------------------- /icon/colorquantize_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/colorquantize_filter.jpg -------------------------------------------------------------------------------- /icon/colortone_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/colortone_filter.jpg -------------------------------------------------------------------------------- /icon/colortone_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/colortone_filter2.jpg -------------------------------------------------------------------------------- /icon/colortone_filter3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/colortone_filter3.jpg -------------------------------------------------------------------------------- /icon/colortone_filter4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/colortone_filter4.jpg -------------------------------------------------------------------------------- /icon/edge_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/edge_filter.jpg -------------------------------------------------------------------------------- /icon/feather_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/feather_filter.jpg -------------------------------------------------------------------------------- /icon/fillpattern_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/fillpattern_filter.jpg -------------------------------------------------------------------------------- /icon/fillpattern_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/fillpattern_filter1.jpg -------------------------------------------------------------------------------- /icon/gamma_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/gamma_filter.jpg -------------------------------------------------------------------------------- /icon/gaussianblur_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/gaussianblur_filter.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter0.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter1.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter2.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter3.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter4.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter5.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter6.jpg -------------------------------------------------------------------------------- /icon/hslmodify_filter7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/hslmodify_filter7.jpg -------------------------------------------------------------------------------- /icon/illusion_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/illusion_filter.jpg -------------------------------------------------------------------------------- /icon/invert_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/invert_filter.jpg -------------------------------------------------------------------------------- /icon/lensflare_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/lensflare_filter.jpg -------------------------------------------------------------------------------- /icon/light_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/light_filter.jpg -------------------------------------------------------------------------------- /icon/mirror_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/mirror_filter1.jpg -------------------------------------------------------------------------------- /icon/mirror_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/mirror_filter2.jpg -------------------------------------------------------------------------------- /icon/mist_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/mist_filter.jpg -------------------------------------------------------------------------------- /icon/monitor_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/monitor_filter.jpg -------------------------------------------------------------------------------- /icon/mosaic_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/mosaic_filter.jpg -------------------------------------------------------------------------------- /icon/neon_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/neon_filter.jpg -------------------------------------------------------------------------------- /icon/nightvision_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/nightvision_filter.jpg -------------------------------------------------------------------------------- /icon/noisefilter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/noisefilter.jpg -------------------------------------------------------------------------------- /icon/oilpaint_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/oilpaint_filter.jpg -------------------------------------------------------------------------------- /icon/oldphoto_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/oldphoto_filter.jpg -------------------------------------------------------------------------------- /icon/pixelate_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/pixelate_filter.jpg -------------------------------------------------------------------------------- /icon/posterize_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/posterize_filter.jpg -------------------------------------------------------------------------------- /icon/radialdistortion_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/radialdistortion_filter.jpg -------------------------------------------------------------------------------- /icon/rainbow_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/rainbow_filter.jpg -------------------------------------------------------------------------------- /icon/raiseframe_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/raiseframe_filter.jpg -------------------------------------------------------------------------------- /icon/rectmatrix_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/rectmatrix_filter.jpg -------------------------------------------------------------------------------- /icon/reflection1_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/reflection1_filter.jpg -------------------------------------------------------------------------------- /icon/reflection2_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/reflection2_filter.jpg -------------------------------------------------------------------------------- /icon/relief_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/relief_filter.jpg -------------------------------------------------------------------------------- /icon/ripple_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/ripple_filter.jpg -------------------------------------------------------------------------------- /icon/saturationmodify_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/saturationmodify_filter.jpg -------------------------------------------------------------------------------- /icon/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/save.png -------------------------------------------------------------------------------- /icon/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/search.png -------------------------------------------------------------------------------- /icon/sepia_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/sepia_filter.jpg -------------------------------------------------------------------------------- /icon/sharp_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/sharp_filter.jpg -------------------------------------------------------------------------------- /icon/shift_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/shift_filter.jpg -------------------------------------------------------------------------------- /icon/smashcolor_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/smashcolor_filter.jpg -------------------------------------------------------------------------------- /icon/softglow_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/softglow_filter.jpg -------------------------------------------------------------------------------- /icon/supernova_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/supernova_filter.jpg -------------------------------------------------------------------------------- /icon/texture1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texture1.png -------------------------------------------------------------------------------- /icon/texture2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texture2.png -------------------------------------------------------------------------------- /icon/texturer_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texturer_filter.jpg -------------------------------------------------------------------------------- /icon/texturer_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texturer_filter1.jpg -------------------------------------------------------------------------------- /icon/texturer_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texturer_filter2.jpg -------------------------------------------------------------------------------- /icon/texturer_filter3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texturer_filter3.jpg -------------------------------------------------------------------------------- /icon/texturer_filter4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/texturer_filter4.jpg -------------------------------------------------------------------------------- /icon/threedgrid_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/threedgrid_filter.jpg -------------------------------------------------------------------------------- /icon/threshold_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/threshold_filter.jpg -------------------------------------------------------------------------------- /icon/tilereflection_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/tilereflection_filter.jpg -------------------------------------------------------------------------------- /icon/tilereflection_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/tilereflection_filter1.jpg -------------------------------------------------------------------------------- /icon/tilereflection_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/tilereflection_filter2.jpg -------------------------------------------------------------------------------- /icon/tint_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/tint_filter.jpg -------------------------------------------------------------------------------- /icon/twist_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/twist_filter.jpg -------------------------------------------------------------------------------- /icon/video_filter1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/video_filter1.jpg -------------------------------------------------------------------------------- /icon/video_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/video_filter2.jpg -------------------------------------------------------------------------------- /icon/video_filter3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/video_filter3.jpg -------------------------------------------------------------------------------- /icon/video_filter4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/video_filter4.jpg -------------------------------------------------------------------------------- /icon/vignette_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/vignette_filter.jpg -------------------------------------------------------------------------------- /icon/vintage_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/vintage_filter.jpg -------------------------------------------------------------------------------- /icon/waterwave_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/waterwave_filter.jpg -------------------------------------------------------------------------------- /icon/wave_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/wave_filter.jpg -------------------------------------------------------------------------------- /icon/xradiation_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/xradiation_filter.jpg -------------------------------------------------------------------------------- /icon/ycb_crlinear_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/ycb_crlinear_filter.jpg -------------------------------------------------------------------------------- /icon/ycb_crlinear_filter2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/ycb_crlinear_filter2.jpg -------------------------------------------------------------------------------- /icon/zoomblur_filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/icon/zoomblur_filter.jpg -------------------------------------------------------------------------------- /logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/logo1.png -------------------------------------------------------------------------------- /logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daizhenjun/ImageFilterForIOS/7f0bc0e7dff3f6445447d20cca595ddd7e14efd7/logo2.png -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CustomImagePicker 4 | // 5 | // Created by Ray Wenderlich on 1/27/10. 6 | // Copyright Ray Wenderlich 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | --------------------------------------------------------------------------------