Project

General

Profile

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

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

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
 * DistortedObject descendant - with a Grid of flat rectangles.
27
 */
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
 * grid of 'cols' and does not fill it up with any Bitmap data just yet.
37
 * <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
 * @param cols   Number of columns in the distortion grid. 2<=size&lt;256.
51
 *               Number of rows gets calculated with 'rows = cols*height/width'.
52
 */
53
   public DistortedBitmap(int width, int height, int cols)
54
     {     
55
     int xsize = cols;
56
     int ysize = cols*height/width;
57

    
58
     if( xsize<1   ) xsize=  1;
59
     if( xsize>256 ) xsize=256;
60
     if( ysize<1   ) ysize=  1;
61
     if( ysize>256 ) ysize=256;
62
     
63
     mGrid = DistortedGridFactory.getGrid(xsize,ysize);
64
     initializeData(width,height,1);
65
     }
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
 * @param gridSize Horizontal size of the distortion grid. 1<=size&lt;256.
74
 */
75
   public DistortedBitmap(Bitmap bmp, int gridSize)
76
     {
77
     this(bmp.getWidth(), bmp.getHeight(), gridSize); 
78
     setBitmap(bmp);
79
     }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
/**
83
 * Copy constructor.
84
 *
85
 * @param db Object to copy
86
 * @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
87
 */
88
   public DistortedBitmap(DistortedBitmap db, int flags)
89
     {
90
     super(db,flags);
91
     }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
   protected DistortedObject deepCopy(int flags)
96
     {
97
     return new DistortedBitmap(this,flags);
98
     }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
}
102
    
(2-2/17)