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

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

Issue 157033007: API to Convert Java Bitmap Config to SkBitmap::Config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code changed as per review comments. Created 6 years, 10 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
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 private static final int BITMAP_CONFIG_NO_CONFIG = 0;
bulach 2014/02/17 10:33:58 please, use the "shared enum" mechanism, it's much
sivag 2014/02/18 16:06:22 Done.
20 private static final int BITMAP_CONFIG_ALPHA_8 = 1;
21 private static final int BITMAP_CONFIG_ARGB_4444 = 2;
22 private static final int BITMAP_CONFIG_ARGB_8888 = 3;
23 private static final int BITMAP_CONFIG_RGB_565 = 4;
24
19 @CalledByNative 25 @CalledByNative
20 private static Bitmap createBitmap(int width, 26 private static Bitmap createBitmap(int width,
21 int height, 27 int height,
22 boolean is565Config) { 28 boolean is565Config) {
23 if (is565Config) { 29 if (is565Config) {
24 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 30 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
25 } 31 }
26 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 32 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
27 } 33 }
28 34
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 final int widthRatio = Math.round((float) width / (float) reqWidth); 74 final int widthRatio = Math.round((float) width / (float) reqWidth);
69 75
70 // Choose the smallest ratio as inSampleSize value, this will guaran tee 76 // Choose the smallest ratio as inSampleSize value, this will guaran tee
71 // a final image with both dimensions larger than or equal to the 77 // a final image with both dimensions larger than or equal to the
72 // requested height and width. 78 // requested height and width.
73 inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; 79 inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
74 } 80 }
75 81
76 return inSampleSize; 82 return inSampleSize;
77 } 83 }
84
85 /**
86 * Provides a matching integer constant for the Bitmap.Config value passed.
87 *
88 * @param Bitmap Configuration value.
89 * @return Matching integer constant for the Bitmap.Config value passed.
90 */
91 @CalledByNative
92 private static int bitmapConfig(Bitmap.Config bitmap_config) {
93 switch (bitmap_config) {
94 case ALPHA_8:
95 return BITMAP_CONFIG_ALPHA_8;
96 case ARGB_4444:
97 return BITMAP_CONFIG_ARGB_4444;
98 case ARGB_8888:
99 return BITMAP_CONFIG_ARGB_8888;
100 case RGB_565:
101 return BITMAP_CONFIG_RGB_565;
102 default:
103 return BITMAP_CONFIG_NO_CONFIG;
104 }
105 }
78 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698