2323import android .graphics .PointF ;
2424import android .opengl .Matrix ;
2525
26- import jp .co .cyberagent .android .gpuimage .*;
27-
2826import java .util .LinkedList ;
2927import java .util .List ;
3028
29+ import jp .co .cyberagent .android .gpuimage .*;
30+
3131public class GPUImageFilterTools {
3232 public static void showDialog (final Context context ,
33- final OnGpuImageFilterChosenListener listener ) {
33+ final OnGpuImageFilterChosenListener listener ) {
3434 final FilterList filters = new FilterList ();
3535 filters .addFilter ("Contrast" , FilterType .CONTRAST );
3636 filters .addFilter ("Invert" , FilterType .INVERT );
@@ -68,8 +68,11 @@ public static void showDialog(final Context context,
6868 filters .addFilter ("Blend (Add)" , FilterType .BLEND_ADD );
6969 filters .addFilter ("Blend (Divide)" , FilterType .BLEND_DIVIDE );
7070 filters .addFilter ("Blend (Multiply)" , FilterType .BLEND_MULTIPLY );
71+ filters .addFilter ("Blend Color (Multiply)" , FilterType .BLEND_COLOR_MULTIPLY );
7172 filters .addFilter ("Blend (Overlay)" , FilterType .BLEND_OVERLAY );
73+ filters .addFilter ("Blend Color (Overlay)" , FilterType .BLEND_COLOR_OVERLAY );
7274 filters .addFilter ("Blend (Screen)" , FilterType .BLEND_SCREEN );
75+ filters .addFilter ("Blend Color (Screen)" , FilterType .BLEND_COLOR_SCREEN );
7376 filters .addFilter ("Blend (Alpha)" , FilterType .BLEND_ALPHA );
7477 filters .addFilter ("Blend (Color)" , FilterType .BLEND_COLOR );
7578 filters .addFilter ("Blend (Hue)" , FilterType .BLEND_HUE );
@@ -109,7 +112,7 @@ public static void showDialog(final Context context,
109112
110113 filters .addFilter ("Levels Min (Mid Adjust)" , FilterType .LEVELS_FILTER_MIN );
111114
112- filters . addFilter ("Bilateral Blur" , FilterType .BILATERAL_BLUR );
115+ filters .addFilter ("Bilateral Blur" , FilterType .BILATERAL_BLUR );
113116
114117 filters .addFilter ("Transform (2-D)" , FilterType .TRANSFORM2D );
115118
@@ -153,7 +156,7 @@ private static GPUImageFilter createFilterForType(final Context context, final F
153156 return new GPUImageSobelEdgeDetection ();
154157 case THREE_X_THREE_CONVOLUTION :
155158 GPUImage3x3ConvolutionFilter convolution = new GPUImage3x3ConvolutionFilter ();
156- convolution .setConvolutionKernel (new float [] {
159+ convolution .setConvolutionKernel (new float []{
157160 -1.0f , 0.0f , 1.0f ,
158161 -2.0f , 0.0f , 2.0f ,
159162 -1.0f , 0.0f , 1.0f
@@ -174,9 +177,9 @@ private static GPUImageFilter createFilterForType(final Context context, final F
174177 case EXPOSURE :
175178 return new GPUImageExposureFilter (0.0f );
176179 case HIGHLIGHT_SHADOW :
177- return new GPUImageHighlightShadowFilter (0.0f , 1.0f );
180+ return new GPUImageHighlightShadowFilter (0.0f , 1.0f );
178181 case MONOCHROME :
179- return new GPUImageMonochromeFilter (1.0f , new float []{0.6f , 0.45f , 0.3f , 1.0f });
182+ return new GPUImageMonochromeFilter (1.0f , new float []{0.6f , 0.45f , 0.3f , 1.0f });
180183 case OPACITY :
181184 return new GPUImageOpacityFilter (1.0f );
182185 case RGB :
@@ -187,7 +190,7 @@ private static GPUImageFilter createFilterForType(final Context context, final F
187190 PointF centerPoint = new PointF ();
188191 centerPoint .x = 0.5f ;
189192 centerPoint .y = 0.5f ;
190- return new GPUImageVignetteFilter (centerPoint , new float [] {0.0f , 0.0f , 0.0f }, 0.3f , 0.75f );
193+ return new GPUImageVignetteFilter (centerPoint , new float []{0.0f , 0.0f , 0.0f }, 0.3f , 0.75f );
191194 case TONE_CURVE :
192195 GPUImageToneCurveFilter toneCurveFilter = new GPUImageToneCurveFilter ();
193196 toneCurveFilter .setFromCurveFileInputStream (
@@ -207,8 +210,6 @@ private static GPUImageFilter createFilterForType(final Context context, final F
207210 return createBlendFilter (context , GPUImageDissolveBlendFilter .class );
208211 case BLEND_EXCLUSION :
209212 return createBlendFilter (context , GPUImageExclusionBlendFilter .class );
210-
211-
212213 case BLEND_HARD_LIGHT :
213214 return createBlendFilter (context , GPUImageHardLightBlendFilter .class );
214215 case BLEND_LIGHTEN :
@@ -219,10 +220,16 @@ private static GPUImageFilter createFilterForType(final Context context, final F
219220 return createBlendFilter (context , GPUImageDivideBlendFilter .class );
220221 case BLEND_MULTIPLY :
221222 return createBlendFilter (context , GPUImageMultiplyBlendFilter .class );
223+ case BLEND_COLOR_MULTIPLY :
224+ return new GPUImageMultiplyColorBlendFilter (new float []{1.0f , 1.0f , 1.0f , 1.0f });
222225 case BLEND_OVERLAY :
223226 return createBlendFilter (context , GPUImageOverlayBlendFilter .class );
227+ case BLEND_COLOR_OVERLAY :
228+ return new GPUImageOverlayColorBlendFilter (new float []{1.0f , 1.0f , 1.0f , 1.0f });
224229 case BLEND_SCREEN :
225230 return createBlendFilter (context , GPUImageScreenBlendFilter .class );
231+ case BLEND_COLOR_SCREEN :
232+ return new GPUImageScreenColorBlendFilter (new float []{1.0f , 1.0f , 1.0f , 1.0f });
226233 case BLEND_ALPHA :
227234 return createBlendFilter (context , GPUImageAlphaBlendFilter .class );
228235 case BLEND_COLOR :
@@ -327,7 +334,7 @@ public interface OnGpuImageFilterChosenListener {
327334 private enum FilterType {
328335 CONTRAST , GRAYSCALE , SHARPEN , SEPIA , SOBEL_EDGE_DETECTION , THREE_X_THREE_CONVOLUTION , FILTER_GROUP , EMBOSS , POSTERIZE , GAMMA , BRIGHTNESS , INVERT , HUE , PIXELATION ,
329336 SATURATION , EXPOSURE , HIGHLIGHT_SHADOW , MONOCHROME , OPACITY , RGB , WHITE_BALANCE , VIGNETTE , TONE_CURVE , BLEND_COLOR_BURN , BLEND_COLOR_DODGE , BLEND_DARKEN , BLEND_DIFFERENCE ,
330- BLEND_DISSOLVE , BLEND_EXCLUSION , BLEND_SOURCE_OVER , BLEND_HARD_LIGHT , BLEND_LIGHTEN , BLEND_ADD , BLEND_DIVIDE , BLEND_MULTIPLY , BLEND_OVERLAY , BLEND_SCREEN , BLEND_ALPHA ,
337+ BLEND_DISSOLVE , BLEND_EXCLUSION , BLEND_SOURCE_OVER , BLEND_HARD_LIGHT , BLEND_LIGHTEN , BLEND_ADD , BLEND_DIVIDE , BLEND_MULTIPLY , BLEND_COLOR_MULTIPLY , BLEND_OVERLAY , BLEND_COLOR_OVERLAY , BLEND_SCREEN , BLEND_COLOR_SCREEN , BLEND_ALPHA ,
331338 BLEND_COLOR , BLEND_HUE , BLEND_SATURATION , BLEND_LUMINOSITY , BLEND_LINEAR_BURN , BLEND_SOFT_LIGHT , BLEND_SUBTRACT , BLEND_CHROMA_KEY , BLEND_NORMAL , LOOKUP_AMATORKA ,
332339 GAUSSIAN_BLUR , CROSSHATCH , BOX_BLUR , CGA_COLORSPACE , DILATION , KUWAHARA , RGB_DILATION , SKETCH , TOON , SMOOTH_TOON , BULGE_DISTORTION , GLASS_SPHERE , HAZE , LAPLACIAN , NON_MAXIMUM_SUPPRESSION ,
333340 SPHERE_REFRACTION , SWIRL , WEAK_PIXEL_INCLUSION , FALSE_COLOR , COLOR_BALANCE , LEVELS_FILTER_MIN , BILATERAL_BLUR , HALFTONE , TRANSFORM2D
@@ -409,9 +416,13 @@ public FilterAdjuster(final GPUImageFilter filter) {
409416 adjuster = new BilateralAdjuster ().filter (filter );
410417 } else if (filter instanceof GPUImageTransformFilter ) {
411418 adjuster = new RotateAdjuster ().filter (filter );
412- }
413- else {
414-
419+ } else if (filter instanceof GPUImageMultiplyColorBlendFilter ) {
420+ adjuster = new MultiplyColorAdjuster ().filter (filter );
421+ } else if (filter instanceof GPUImageScreenColorBlendFilter ) {
422+ adjuster = new ScreenColorAdjuster ().filter (filter );
423+ } else if (filter instanceof GPUImageOverlayColorBlendFilter ) {
424+ adjuster = new OverlayColorAdjuster ().filter (filter );
425+ } else {
415426 adjuster = null ;
416427 }
417428 }
@@ -458,17 +469,17 @@ public void adjust(final int percentage) {
458469 }
459470
460471 private class PixelationAdjuster extends Adjuster <GPUImagePixelationFilter > {
461- @ Override
462- public void adjust (final int percentage ) {
463- getFilter ().setPixel (range (percentage , 1.0f , 100.0f ));
464- }
472+ @ Override
473+ public void adjust (final int percentage ) {
474+ getFilter ().setPixel (range (percentage , 1.0f , 100.0f ));
475+ }
465476 }
466477
467478 private class HueAdjuster extends Adjuster <GPUImageHueFilter > {
468- @ Override
469- public void adjust (final int percentage ) {
470- getFilter ().setHue (range (percentage , 0.0f , 360.0f ));
471- }
479+ @ Override
480+ public void adjust (final int percentage ) {
481+ getFilter ().setHue (range (percentage , 0.0f , 360.0f ));
482+ }
472483 }
473484
474485 private class ContrastAdjuster extends Adjuster <GPUImageContrastFilter > {
@@ -659,6 +670,36 @@ public void adjust(int percentage) {
659670 }
660671 }
661672
673+ private class MultiplyColorAdjuster extends Adjuster <GPUImageMultiplyColorBlendFilter > {
674+
675+ @ Override
676+ public void adjust (int percentage ) {
677+ getFilter ().setBlendColor (new float []{
678+ range (percentage , 0.0f , 1.0f ),
679+ 1.0f , 1.0f , 1.0f });
680+ }
681+ }
682+
683+ private class ScreenColorAdjuster extends Adjuster <GPUImageScreenColorBlendFilter > {
684+
685+ @ Override
686+ public void adjust (int percentage ) {
687+ getFilter ().setBlendColor (new float []{
688+ range (percentage , 0.0f , 1.0f ),
689+ 1.0f , 1.0f , 1.0f });
690+ }
691+ }
692+
693+ private class OverlayColorAdjuster extends Adjuster <GPUImageOverlayColorBlendFilter > {
694+
695+ @ Override
696+ public void adjust (int percentage ) {
697+ getFilter ().setBlendColor (new float []{
698+ range (percentage , 0.0f , 1.0f ),
699+ 1.0f , 1.0f , 1.0f });
700+ }
701+ }
702+
662703 private class LevelsMinMidAdjuster extends Adjuster <GPUImageLevelsFilter > {
663704 @ Override
664705 public void adjust (int percentage ) {
0 commit comments