Marius Renn | 65953da | 2012-03-27 10:44:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "core/native_frame.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace filterfw { |
| 21 | |
| 22 | NativeFrame::NativeFrame(int size) : data_(NULL), size_(size), capacity_(size) { |
| 23 | data_ = capacity_ == 0 ? NULL : new uint8_t[capacity_]; |
| 24 | } |
| 25 | |
| 26 | NativeFrame::~NativeFrame() { |
| 27 | delete[] data_; |
| 28 | } |
| 29 | |
| 30 | bool NativeFrame::WriteData(const uint8_t* data, int offset, int size) { |
| 31 | if (size_ >= (offset + size)) { |
| 32 | memcpy(data_ + offset, data, size); |
| 33 | return true; |
| 34 | } |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | bool NativeFrame::SetData(uint8_t* data, int size) { |
| 39 | delete[] data_; |
| 40 | size_ = capacity_ = size; |
| 41 | data_ = data; |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | NativeFrame* NativeFrame::Clone() const { |
| 46 | NativeFrame* result = new NativeFrame(size_); |
| 47 | if (data_) |
| 48 | result->WriteData(data_, 0, size_); |
| 49 | return result; |
| 50 | } |
| 51 | |
| 52 | bool NativeFrame::Resize(int newSize) { |
| 53 | if (newSize <= capacity_ && newSize >= 0) { |
| 54 | size_ = newSize; |
| 55 | return true; |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | } // namespace filterfw |
| 61 | } // namespace android |