Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: ui/android/java/src/org/chromium/ui/gfx/BitmapHelper.java

Issue 184453002: Android::Pass Bitmap.Config instead of bool to CreateJavaBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass Bitmap.Config instead of bool to CreateJavaBitmap Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/android/java_bitmap.h » ('j') | ui/gfx/android/java_bitmap.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui.gfx; 5 package org.chromium.ui.gfx;
6 6
7 import android.content.res.Resources; 7 import android.content.res.Resources;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.BitmapFactory; 9 import android.graphics.BitmapFactory;
10 10
11 import org.chromium.base.CalledByNative; 11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.JNINamespace; 12 import org.chromium.base.JNINamespace;
13 13
14 /** 14 /**
15 * Helper class to decode and sample down bitmap resources. 15 * Helper class to decode and sample down bitmap resources.
16 */ 16 */
17 @JNINamespace("gfx") 17 @JNINamespace("gfx")
18 public class BitmapHelper { 18 public class BitmapHelper {
19 @CalledByNative 19 @CalledByNative
20 private static Bitmap createBitmap(int width, 20 private static Bitmap createBitmap(int width,
21 int height, 21 int height,
22 boolean is565Config) { 22 Bitmap.Config bitmapConfig) {
bulach 2014/02/28 13:19:25 this will require an extra JNI call, how about pas
sivag 2014/03/04 12:36:04 Done.
23 if (is565Config) { 23 return Bitmap.createBitmap(width, height, bitmapConfig);
24 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
25 }
26 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
27 } 24 }
28 25
29 /** 26 /**
30 * Decode and sample down a bitmap resource to the requested width and heigh t. 27 * Decode and sample down a bitmap resource to the requested width and heigh t.
31 * 28 *
32 * @param name The resource name of the bitmap to decode. 29 * @param name The resource name of the bitmap to decode.
33 * @param reqWidth The requested width of the resulting bitmap. 30 * @param reqWidth The requested width of the resulting bitmap.
34 * @param reqHeight The requested height of the resulting bitmap. 31 * @param reqHeight The requested height of the resulting bitmap.
35 * @return A bitmap sampled down from the original with the same aspect rati o and dimensions. 32 * @return A bitmap sampled down from the original with the same aspect rati o and dimensions.
36 * that are equal to or greater than the requested width and height. 33 * that are equal to or greater than the requested width and height.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return inSampleSize; 73 return inSampleSize;
77 } 74 }
78 75
79 /** 76 /**
80 * Provides a matching integer constant for the Bitmap.Config value passed. 77 * Provides a matching integer constant for the Bitmap.Config value passed.
81 * 78 *
82 * @param bitmapConfig The Bitmap Configuration value. 79 * @param bitmapConfig The Bitmap Configuration value.
83 * @return Matching integer constant for the Bitmap.Config value passed. 80 * @return Matching integer constant for the Bitmap.Config value passed.
84 */ 81 */
85 @CalledByNative 82 @CalledByNative
86 private static int bitmapConfig(Bitmap.Config bitmapConfig) { 83 private static int getConfigEnumValue(Bitmap.Config bitmapConfig) {
87 switch (bitmapConfig) { 84 switch (bitmapConfig) {
88 case ALPHA_8: 85 case ALPHA_8:
89 return BitmapFormat.FORMAT_ALPHA_8; 86 return BitmapFormat.FORMAT_ALPHA_8;
90 case ARGB_4444: 87 case ARGB_4444:
91 return BitmapFormat.FORMAT_ARGB_4444; 88 return BitmapFormat.FORMAT_ARGB_4444;
92 case ARGB_8888: 89 case ARGB_8888:
93 return BitmapFormat.FORMAT_ARGB_8888; 90 return BitmapFormat.FORMAT_ARGB_8888;
94 case RGB_565: 91 case RGB_565:
95 return BitmapFormat.FORMAT_RGB_565; 92 return BitmapFormat.FORMAT_RGB_565;
96 default: 93 default:
97 return BitmapFormat.FORMAT_NO_CONFIG; 94 return BitmapFormat.FORMAT_NO_CONFIG;
98 } 95 }
99 } 96 }
97
98 /**
99 * Provides a matching Bitmap.Config for the enum config value passed.
100 *
101 * @param matchingenumConfig The Bitmap Configuration enum value.
102 * @return Matching Bitmap.Config for the enum value passed.
103 */
104 @CalledByNative
bulach 2014/02/28 13:19:25 see above, I think this method can be kept private
sivag 2014/03/04 12:36:04 Done.
105 private static Bitmap.Config getJavabitmapConfig(int matchingenumConfig) {
106 switch (matchingenumConfig) {
107 case BitmapFormat.FORMAT_ALPHA_8:
108 return Bitmap.Config.ALPHA_8;
109 case BitmapFormat.FORMAT_ARGB_4444:
110 return Bitmap.Config.ARGB_4444;
111 case BitmapFormat.FORMAT_RGB_565:
112 return Bitmap.Config.RGB_565;
113 case BitmapFormat.FORMAT_ARGB_8888:
114 default:
115 return Bitmap.Config.ARGB_8888;
116 }
117 }
118
100 } 119 }
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/android/java_bitmap.h » ('j') | ui/gfx/android/java_bitmap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698