blob: 52d9692b149cbfd52511cc8fec63c4255cd22e7f [file] [log] [blame]
Yuli Huang6a12ad72011-09-12 22:25:30 +08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.photoeditor;
18
19import android.graphics.Bitmap;
20
21/**
22 * Photo that holds a GL texture and all its methods must be only accessed from the GL thread.
23 */
24public class Photo {
25
26 private int texture;
27 private int width;
28 private int height;
29
30 /**
31 * Factory method to ensure every Photo instance holds a valid texture.
32 */
33 public static Photo create(Bitmap bitmap) {
34 return (bitmap != null) ? new Photo(
35 RendererUtils.createTexture(bitmap), bitmap.getWidth(), bitmap.getHeight()) : null;
36 }
37
38 public static Photo create(int width, int height) {
39 return new Photo(RendererUtils.createTexture(), width, height);
40 }
41
42 private Photo(int texture, int width, int height) {
43 this.texture = texture;
44 this.width = width;
45 this.height = height;
46 }
47
48 public int texture() {
49 return texture;
50 }
51
52 public boolean matchDimension(Photo photo) {
Yuli Huange0e82f12011-10-10 00:55:26 +080053 return ((photo.width == width) && (photo.height == height));
Yuli Huang6a12ad72011-09-12 22:25:30 +080054 }
55
56 public void changeDimension(int width, int height) {
57 this.width = width;
58 this.height = height;
59 RendererUtils.clearTexture(texture);
60 texture = RendererUtils.createTexture();
61 }
62
63 public int width() {
64 return width;
65 }
66
67 public int height() {
68 return height;
69 }
70
71 public Bitmap save() {
72 return RendererUtils.saveTexture(texture, width, height);
73 }
74
75 /**
76 * Clears the texture; this instance should not be used after its clear() is called.
77 */
78 public void clear() {
79 RendererUtils.clearTexture(texture);
80 }
81}