App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

APDBitmap.java
Go to the documentation of this file.
1 package mhr.appandroid.adapters;
2
3 import android.graphics.Bitmap;
4 import mhr.appcore.bitmap.BitmapInfo;
5 import mhr.appcore.bitmap.ChannelCount;
6 import mhr.appcore.bitmap.ColorMode;
7 import mhr.appcore.bitmap.Depth;
8 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
9 import mhr.appcore.interfaces.PDBitmap;
10
14 public class APDBitmap implements PDBitmap {
15
16 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
17 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
18 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
19
20 //===== FIELDS ==============================================================================================================================//
21 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
22 protected Bitmap bitmap = null;
23
24 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
25
26 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
27 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
28 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
32 public APDBitmap() {
33 }
34
39 public APDBitmap(Bitmap bitmap) {
40 this.bitmap = bitmap;
41 }
42
47 public APDBitmap(BitmapInfo info) throws UnsupportedBitmapException {
48 if (info.channelCount == ChannelCount.SINGLE_CHANNEL && info.depth == Depth.DEPTH_8_BIT) {
49 this.bitmap = Bitmap.createBitmap(info.width, info.height, Bitmap.Config.ALPHA_8);
50 } else if (info.channelCount == ChannelCount.FOUR_CHANNEL && info.depth == Depth.DEPTH_8_BIT) {
51 this.bitmap = Bitmap.createBitmap(info.width, info.height, Bitmap.Config.ARGB_8888);
52 } else {
53 throw new UnsupportedBitmapException("Could not create bitmap with supplied parameters");
54 }
55 }
56
57 //===== METHODS =============================================================================================================================//
58 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
65 protected static native long getAndLockData(Object bitmap);
66
73 protected static native int unlockData(Object bitmap);
74
75 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
80 public Bitmap getBitmap() {
81 return bitmap;
82 }
83
88 public void setBitmap(Bitmap bitmap) {
89 this.bitmap = bitmap;
90 }
91
92 @Override
93 public long getAndLockData() throws NullPointerException {
94 if (bitmap == null) {
95 throw new NullPointerException();
96 }
97 return APDBitmap.getAndLockData(bitmap);
98 }
99
100 @Override
101 public int unlockData() throws NullPointerException {
102 if (bitmap == null) {
103 throw new NullPointerException();
104 }
105 return APDBitmap.unlockData(bitmap);
106 }
107
108 @Override
109 public BitmapInfo getInfo() throws UnsupportedBitmapException, NullPointerException {
110 BitmapInfo retVal = new BitmapInfo();
111 retVal.width = bitmap.getWidth();
112 retVal.height = bitmap.getHeight();
113 retVal.premultiplied = true; // tohle nelze zjisit, až v API 17
114 Bitmap.Config config = bitmap.getConfig();
115 if (config != null) {
116 switch (config) {
117 case ARGB_8888:
118 retVal.depth = Depth.DEPTH_8_BIT;
119 retVal.channelCount = ChannelCount.FOUR_CHANNEL;
120 retVal.colorMode = ColorMode.RGBA;
121 break;
122 case ALPHA_8:
123 retVal.depth = Depth.DEPTH_8_BIT;
124 retVal.channelCount = ChannelCount.SINGLE_CHANNEL;
125 retVal.colorMode = ColorMode.MONO;
126 break;
127 default:
128 throw new UnsupportedBitmapException("Bitmap type is not supported");
129 }
130 } else {
131 throw new NullPointerException();
132 }
133 return retVal;
134 }
135
136 @Override
137 public PDBitmap makeCopy() {
138 return new APDBitmap(bitmap.copy(bitmap.getConfig(), false));
139 }
140
141 @Override
142 public void dispose() {
143 bitmap.recycle();
144 }
145
146
147 @Override
148 public PDBitmap createBitmap(BitmapInfo i) throws UnsupportedBitmapException {
149 return new APDBitmap(i);
150 }
151 }