Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedBitmap.java @ 015642fb

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 size 'size' 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 gridSize Horizontal size of the distortion grid. 2<=size&lt;256.
69
 */
70
   public DistortedBitmap(int width, int height, int gridSize)
71
     {     
72
     int xsize = gridSize;
73
     int ysize = xsize*height/width;
74
     
75
     if( xsize<2   ) xsize=  2;
76
     if( xsize>256 ) xsize=256;
77
     if( ysize<2   ) ysize=  2;
78
     if( ysize>256 ) ysize=256;
79
     
80
     mSizeX= width;
81
     mSizeY= height;
82
     mSizeZ= 1;     
83
     mGrid = new DistortedBitmapGrid(xsize,ysize);
84
     initializeData(gridSize);
85
     }
86

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

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

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

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

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