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

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: Code changed as per review comments. 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.cc » ('j') | ui/gfx/android/java_bitmap.cc » ('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 int bitmapFormatValue) {
23 if (is565Config) { 23 Bitmap.Config bitmapConfig = getJavabitmapConfig(bitmapFormatValue);
24 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 24 return Bitmap.createBitmap(width, height, bitmapConfig);
25 }
26 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
27 } 25 }
28 26
29 /** 27 /**
30 * Decode and sample down a bitmap resource to the requested width and heigh t. 28 * Decode and sample down a bitmap resource to the requested width and heigh t.
31 * 29 *
32 * @param name The resource name of the bitmap to decode. 30 * @param name The resource name of the bitmap to decode.
33 * @param reqWidth The requested width of the resulting bitmap. 31 * @param reqWidth The requested width of the resulting bitmap.
34 * @param reqHeight The requested height of the resulting bitmap. 32 * @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. 33 * @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. 34 * 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; 74 return inSampleSize;
77 } 75 }
78 76
79 /** 77 /**
80 * Provides a matching integer constant for the Bitmap.Config value passed. 78 * Provides a matching integer constant for the Bitmap.Config value passed.
81 * 79 *
82 * @param bitmapConfig The Bitmap Configuration value. 80 * @param bitmapConfig The Bitmap Configuration value.
83 * @return Matching integer constant for the Bitmap.Config value passed. 81 * @return Matching integer constant for the Bitmap.Config value passed.
84 */ 82 */
85 @CalledByNative 83 @CalledByNative
86 private static int bitmapConfig(Bitmap.Config bitmapConfig) { 84 private static int getConfigEnumValue(Bitmap.Config bitmapConfig) {
bulach 2014/03/04 13:05:13 nit: how about "getBitmapFormatForConfig" and the
sivag 2014/03/04 13:57:55 Done.
87 switch (bitmapConfig) { 85 switch (bitmapConfig) {
88 case ALPHA_8: 86 case ALPHA_8:
89 return BitmapFormat.FORMAT_ALPHA_8; 87 return BitmapFormat.FORMAT_ALPHA_8;
90 case ARGB_4444: 88 case ARGB_4444:
91 return BitmapFormat.FORMAT_ARGB_4444; 89 return BitmapFormat.FORMAT_ARGB_4444;
92 case ARGB_8888: 90 case ARGB_8888:
93 return BitmapFormat.FORMAT_ARGB_8888; 91 return BitmapFormat.FORMAT_ARGB_8888;
94 case RGB_565: 92 case RGB_565:
95 return BitmapFormat.FORMAT_RGB_565; 93 return BitmapFormat.FORMAT_RGB_565;
96 default: 94 default:
97 return BitmapFormat.FORMAT_NO_CONFIG; 95 return BitmapFormat.FORMAT_NO_CONFIG;
98 } 96 }
99 } 97 }
98
99 /**
100 * Provides a matching Bitmap.Config for the enum config value passed.
101 *
102 * @param bitmapFormatValue The Bitmap Configuration enum value.
103 * @return Matching Bitmap.Config for the enum value passed.
104 */
105 private static Bitmap.Config getJavabitmapConfig(int bitmapFormatValue) {
bulach 2014/03/04 13:05:13 nit: I'd prefer my suggestion above, but if we dec
sivag 2014/03/04 13:57:55 Done.
106 switch (bitmapFormatValue) {
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:
bulach 2014/03/04 13:05:13 nit: unindent "default" and keep at the same level
sivag 2014/03/04 13:57:55 Done.
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.cc » ('j') | ui/gfx/android/java_bitmap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698