securesmartcam / app / src / main / java / org / witness / obscuracam / photo / filters / CrowdPixelizeObscure.java @ 41590feb
History | View | Annotate | Download (2.33 KB)
1 |
/*
|
---|---|
2 |
* This ObscureMethod pixelizes the region
|
3 |
*/
|
4 |
|
5 |
package org.witness.obscuracam.photo.filters; |
6 |
|
7 |
|
8 |
import java.util.Properties; |
9 |
|
10 |
import android.graphics.Bitmap; |
11 |
import android.graphics.Canvas; |
12 |
import android.graphics.RectF; |
13 |
|
14 |
public class CrowdPixelizeObscure implements RegionProcesser { |
15 |
|
16 |
Bitmap originalBmp; |
17 |
Properties mProps;
|
18 |
|
19 |
public static int PIXEL_BLOCK = 50; |
20 |
|
21 |
public CrowdPixelizeObscure() {
|
22 |
mProps = new Properties(); |
23 |
mProps.put("obfuscationType", this.getClass().getName()); |
24 |
} |
25 |
|
26 |
public void processRegion(RectF rect, Canvas canvas, Bitmap bitmap) { |
27 |
|
28 |
originalBmp = bitmap; |
29 |
|
30 |
int pixelSize = originalBmp.getWidth()/PIXEL_BLOCK;
|
31 |
|
32 |
if (pixelSize <= 0) //1 is the smallest it can be |
33 |
pixelSize = 1;
|
34 |
|
35 |
pixelate(rect, pixelSize); |
36 |
|
37 |
// return properties and data as a map
|
38 |
mProps.put("initialCoordinates", "[" + rect.top + "," + rect.left + "]"); |
39 |
mProps.put("regionWidth", Float.toString(Math.abs(rect.left - rect.right))); |
40 |
mProps.put("regionHeight", Float.toString(Math.abs(rect.top - rect.bottom))); |
41 |
|
42 |
} |
43 |
|
44 |
private void pixelate(RectF rect, int pixelSize) |
45 |
{ |
46 |
if (rect.left <= 0) { |
47 |
rect.left = 1;
|
48 |
} else if (rect.right >= originalBmp.getWidth()-1) { |
49 |
rect.right = originalBmp.getWidth() - 1;
|
50 |
} |
51 |
|
52 |
if (rect.top <= 0) { |
53 |
rect.top = 1;
|
54 |
} else if (rect.bottom >= originalBmp.getHeight()) { |
55 |
rect.bottom = originalBmp.getHeight(); |
56 |
} |
57 |
|
58 |
int px, py;
|
59 |
|
60 |
for (int x = 0; x < originalBmp.getWidth() - 1; x+=pixelSize) { |
61 |
for (int y = 0; y < originalBmp.getHeight() - 1; y+=pixelSize) { |
62 |
|
63 |
if (rect.contains(x, y))
|
64 |
continue;
|
65 |
|
66 |
px = (x/pixelSize)*pixelSize; |
67 |
py = (y/pixelSize)*pixelSize; |
68 |
|
69 |
try
|
70 |
{ |
71 |
//originalBmp.setPixel(x, y, originalBmp.getPixel(px,py));
|
72 |
|
73 |
int pixels[] = new int[pixelSize*pixelSize]; |
74 |
int newPixel = originalBmp.getPixel(px, py);
|
75 |
for (int i = 0; i < pixels.length; i++) |
76 |
pixels[i] = newPixel; |
77 |
|
78 |
originalBmp.setPixels(pixels, 0, pixelSize, px, py, pixelSize, pixelSize);
|
79 |
} |
80 |
catch (IllegalArgumentException iae) |
81 |
{ |
82 |
//something is wrong with our pixel math
|
83 |
break; //stop the filter |
84 |
} |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
public Properties getProperties() |
90 |
{ |
91 |
return mProps;
|
92 |
} |
93 |
|
94 |
public void setProperties(Properties props) |
95 |
{ |
96 |
mProps = props; |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public Bitmap getBitmap() {
|
101 |
// TODO Auto-generated method stub
|
102 |
return null; |
103 |
} |
104 |
} |
105 |
|
106 |
|
107 |
|
108 |
|