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 */ 16 17 package com.android.printspooler.util; 18 19 import android.graphics.Bitmap; 20 import android.os.ParcelFileDescriptor; 21 22 /** 23 * Helper for serialization of bitmaps in the very specific 24 * use case of having the same bitmap on both ends and just 25 * marshaling the pixels from one side to the other. 26 */ 27 public final class BitmapSerializeUtils { 28 29 static { 30 System.loadLibrary("printspooler_jni"); 31 } 32 BitmapSerializeUtils()33 private BitmapSerializeUtils() { 34 /* do nothing */ 35 } 36 37 /** 38 * Reads a bitmap pixels from a file descriptor. 39 * 40 * @param bitmap A bitmap whose pixels to populate. 41 * @param source The source file descriptor. 42 */ readBitmapPixels(Bitmap bitmap, ParcelFileDescriptor source)43 public static void readBitmapPixels(Bitmap bitmap, ParcelFileDescriptor source) { 44 nativeReadBitmapPixels(bitmap, source.getFd()); 45 } 46 47 /** 48 * Writes a bitmap pixels to a file descriptor. 49 * 50 * @param bitmap The bitmap. 51 * @param destination The destination file descriptor. 52 */ writeBitmapPixels(Bitmap bitmap, ParcelFileDescriptor destination)53 public static void writeBitmapPixels(Bitmap bitmap, ParcelFileDescriptor destination) { 54 nativeWriteBitmapPixels(bitmap, destination.getFd()); 55 } 56 nativeReadBitmapPixels(Bitmap bitmap, int fd)57 private static native void nativeReadBitmapPixels(Bitmap bitmap, int fd); 58 nativeWriteBitmapPixels(Bitmap bitmap, int fd)59 private static native void nativeWriteBitmapPixels(Bitmap bitmap, int fd); 60 } 61