Project

General

Profile

Download (5.55 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedBitmap.java @ ffbf279e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.library;
21

    
22
import android.graphics.Bitmap;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
/**
26
 * Wrapper around the standard Android Bitmap class to which one can apply graphical effects.
27
 * <p>
28
 * General idea is as follows:
29
 * <ul>
30
 * <li> Create an instance of DistortedBitmap
31
 * <li> Paint something onto the Bitmap that's backing it up
32
 * <li> Apply some effects
33
 * <li> Draw it!
34
 * </ul>
35
 * <p>
36
 * The effects we can apply fall into three general categories:
37
 * <ul>
38
 * <li> Matrix Effects, i.e. ones that change the Bitmap's ModelView Matrix (moves, scales, rotations)
39
 * <li> Vertex Effects, i.e. effects that are implemented in the Vertex Shader. Those typically change
40
 *      the shape of (some sub-Region of) the Bitmap in some way (deforms, distortions, sinks)
41
 * <li> Fragment Effects, i.e. effects that change (some of) the pixels of the Bitmap (transparency, macroblock)
42
 * </ul>
43
 * <p>
44
 * 
45
 */
46
public class DistortedBitmap extends DistortedObject
47
   {
48
   
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
// PUBLIC API
51
///////////////////////////////////////////////////////////////////////////////////////////////////  
52
/**
53
 * Default constructor: creates a DistortedBitmap (width,height) pixels in size, with the distortion
54
 * grid of 'cols' and does not fill it up with any Bitmap data just yet.
55
 * <p>
56
 * Distortion grid is a grid of rectangles the Bitmap is split to. The vertices of this grid are then 
57
 * moved around by the Vertex Shader to create various Vertex Effects.
58
 * <p>
59
 * Size parameter describes the horizontal size, i.e. the number of rectangles the top (or bottom) edge
60
 * is split to. So when size=1, the whole Bitmap is just one giant rectangle. When size=10, the Bitmap
61
 * is split into a grid of 10x10 rectangles.
62
 * <p>
63
 * The higher the size, the better Vertex Effects look; on the other hand too high size will slow things 
64
 * down.  
65
 *       
66
 * @param width  width of the DistortedBitmap, in pixels.
67
 * @param height height of the DistortedBitmap, in pixels.
68
 * @param cols   Number of columns in the distortion grid. 2<=size&lt;256.
69
 *               Number of rows gets calculated with 'rows = cols*height/width'.
70
 */
71
   public DistortedBitmap(int width, int height, int cols)
72
     {     
73
     int xsize = cols;
74
     int ysize = cols*height/width;
75
     
76
     if( xsize<2   ) xsize=  2;
77
     if( xsize>256 ) xsize=256;
78
     if( ysize<2   ) ysize=  2;
79
     if( ysize>256 ) ysize=256;
80
     
81
     mSizeX= width;
82
     mSizeY= height;
83
     mSizeZ= 1;
84
     mGrid = new DistortedBitmapGrid(xsize,ysize);
85
     initializeData();
86
     }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////   
89
/**
90
 * Creates a DistortedBitmap and immediately fills it up with Bitmap data.
91
 * The dimensions of the created DistortedBitmap object are the same like that of the passed Bitmap.
92
 *       
93
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
94
 * @param gridSize Horizontal size of the distortion grid. 1<=size&lt;256.
95
 */
96
   public DistortedBitmap(Bitmap bmp, int gridSize)
97
     {
98
     this(bmp.getWidth(), bmp.getHeight(), gridSize); 
99
     setBitmap(bmp);
100
     }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
/**
104
 * {@see DistortedObject#DistortedObject(DistortedObject,int)}
105
 */
106
   public DistortedBitmap(DistortedBitmap db, int flags)
107
     {
108
     super(db,flags);
109
     }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
   protected DistortedObject deepCopy(int flags)
114
     {
115
     return new DistortedBitmap(this,flags);
116
     }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
}
120
    
(2-2/17)