Home | History | Annotate | Download | only in impl
      1 /*
      2  * Copyright (C) 2013 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 package android.hardware.camera2.impl;
     17 
     18 import android.graphics.Rect;
     19 
     20 import java.nio.ByteBuffer;
     21 
     22 public class MetadataMarshalRect implements MetadataMarshalClass<Rect> {
     23     private static final int SIZE = 16;
     24 
     25     @Override
     26     public int marshal(Rect value, ByteBuffer buffer, int nativeType, boolean sizeOnly) {
     27         if (sizeOnly) {
     28             return SIZE;
     29         }
     30 
     31         buffer.putInt(value.left);
     32         buffer.putInt(value.top);
     33         buffer.putInt(value.width());
     34         buffer.putInt(value.height());
     35 
     36         return SIZE;
     37     }
     38 
     39     @Override
     40     public Rect unmarshal(ByteBuffer buffer, int nativeType) {
     41 
     42         int left = buffer.getInt();
     43         int top = buffer.getInt();
     44         int width = buffer.getInt();
     45         int height = buffer.getInt();
     46 
     47         int right = left + width;
     48         int bottom = top + height;
     49 
     50         return new Rect(left, top, right, bottom);
     51     }
     52 
     53     @Override
     54     public Class<Rect> getMarshalingClass() {
     55         return Rect.class;
     56     }
     57 
     58     @Override
     59     public boolean isNativeTypeSupported(int nativeType) {
     60         return nativeType == CameraMetadataNative.TYPE_INT32;
     61     }
     62 
     63     @Override
     64     public int getNativeSize(int nativeType) {
     65         return SIZE;
     66     }
     67 }
     68