1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
21 |
|
|
|
22 |
|
|
import android.graphics.Bitmap;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
/**
|
26 |
b73dcaa7
|
Leszek Koltunski
|
* DistortedObject descendant - with a Grid of flat rectangles.
|
27 |
6a06a912
|
Leszek Koltunski
|
*/
|
28 |
|
|
public class DistortedBitmap extends DistortedObject
|
29 |
|
|
{
|
30 |
|
|
|
31 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
|
|
// PUBLIC API
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
/**
|
35 |
|
|
* Default constructor: creates a DistortedBitmap (width,height) pixels in size, with the distortion
|
36 |
ffbf279e
|
Leszek Koltunski
|
* grid of 'cols' and does not fill it up with any Bitmap data just yet.
|
37 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
38 |
|
|
* Distortion grid is a grid of rectangles the Bitmap is split to. The vertices of this grid are then
|
39 |
|
|
* moved around by the Vertex Shader to create various Vertex Effects.
|
40 |
|
|
* <p>
|
41 |
|
|
* Size parameter describes the horizontal size, i.e. the number of rectangles the top (or bottom) edge
|
42 |
|
|
* is split to. So when size=1, the whole Bitmap is just one giant rectangle. When size=10, the Bitmap
|
43 |
|
|
* is split into a grid of 10x10 rectangles.
|
44 |
|
|
* <p>
|
45 |
|
|
* The higher the size, the better Vertex Effects look; on the other hand too high size will slow things
|
46 |
|
|
* down.
|
47 |
|
|
*
|
48 |
|
|
* @param width width of the DistortedBitmap, in pixels.
|
49 |
|
|
* @param height height of the DistortedBitmap, in pixels.
|
50 |
ffbf279e
|
Leszek Koltunski
|
* @param cols Number of columns in the distortion grid. 2<=size<256.
|
51 |
|
|
* Number of rows gets calculated with 'rows = cols*height/width'.
|
52 |
6a06a912
|
Leszek Koltunski
|
*/
|
53 |
ffbf279e
|
Leszek Koltunski
|
public DistortedBitmap(int width, int height, int cols)
|
54 |
6a06a912
|
Leszek Koltunski
|
{
|
55 |
adb2661c
|
Leszek Koltunski
|
int xsize = cols;
|
56 |
|
|
int ysize = cols*height/width;
|
57 |
|
|
|
58 |
79f172ab
|
Leszek Koltunski
|
if( xsize<1 ) xsize= 1;
|
59 |
6a06a912
|
Leszek Koltunski
|
if( xsize>256 ) xsize=256;
|
60 |
79f172ab
|
Leszek Koltunski
|
if( ysize<1 ) ysize= 1;
|
61 |
6a06a912
|
Leszek Koltunski
|
if( ysize>256 ) ysize=256;
|
62 |
|
|
|
63 |
0729bc41
|
Leszek Koltunski
|
mGrid = DistortedGridFactory.getGrid(xsize,ysize);
|
64 |
3d590d8d
|
Leszek Koltunski
|
initializeData(width,height,1);
|
65 |
6a06a912
|
Leszek Koltunski
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
/**
|
69 |
|
|
* Creates a DistortedBitmap and immediately fills it up with Bitmap data.
|
70 |
|
|
* The dimensions of the created DistortedBitmap object are the same like that of the passed Bitmap.
|
71 |
|
|
*
|
72 |
|
|
* @param bmp The android.graphics.Bitmap object to apply effects to and display.
|
73 |
da7ce0d8
|
LeszekKoltunski
|
* @param gridSize Horizontal size of the distortion grid. 1<=size<256.
|
74 |
6a06a912
|
Leszek Koltunski
|
*/
|
75 |
|
|
public DistortedBitmap(Bitmap bmp, int gridSize)
|
76 |
|
|
{
|
77 |
|
|
this(bmp.getWidth(), bmp.getHeight(), gridSize);
|
78 |
|
|
setBitmap(bmp);
|
79 |
|
|
}
|
80 |
9361b337
|
Leszek Koltunski
|
|
81 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82 |
|
|
/**
|
83 |
8298e6af
|
Leszek Koltunski
|
* Copy constructor.
|
84 |
|
|
*
|
85 |
|
|
* @param db Object to copy
|
86 |
350cc2f5
|
Leszek Koltunski
|
* @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
|
87 |
6a06a912
|
Leszek Koltunski
|
*/
|
88 |
|
|
public DistortedBitmap(DistortedBitmap db, int flags)
|
89 |
|
|
{
|
90 |
9361b337
|
Leszek Koltunski
|
super(db,flags);
|
91 |
6a06a912
|
Leszek Koltunski
|
}
|
92 |
|
|
|
93 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
|
95 |
|
|
protected DistortedObject deepCopy(int flags)
|
96 |
|
|
{
|
97 |
|
|
return new DistortedBitmap(this,flags);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101 |
|
|
}
|
102 |
|
|
|