1/*
2 * Copyright (C) 2014 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 */
16package androidx.core.graphics;
17
18import android.graphics.Bitmap;
19import android.os.Build;
20
21import androidx.annotation.NonNull;
22
23/**
24 * Helper for accessing features in {@link android.graphics.Bitmap}.
25 */
26public final class BitmapCompat {
27    public static boolean hasMipMap(@NonNull Bitmap bitmap) {
28        if (Build.VERSION.SDK_INT >= 18) {
29            return bitmap.hasMipMap();
30        }
31        return false;
32    }
33
34    public static void setHasMipMap(@NonNull Bitmap bitmap, boolean hasMipMap) {
35        if (Build.VERSION.SDK_INT >= 18) {
36            bitmap.setHasMipMap(hasMipMap);
37        }
38    }
39
40    /**
41     * Returns the size of the allocated memory used to store this bitmap's pixels in a backwards
42     * compatible way.
43     *
44     * @param bitmap the bitmap in which to return its allocation size
45     * @return the allocation size in bytes
46     */
47    public static int getAllocationByteCount(@NonNull Bitmap bitmap) {
48        if (Build.VERSION.SDK_INT >= 19) {
49            return bitmap.getAllocationByteCount();
50        }
51        return bitmap.getByteCount();
52    }
53
54    private BitmapCompat() {}
55}
56