Canola  0.8.D001
lib/image/format.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/ac/string.h>
00019 
00020 #include <lib/image/format.h>
00021 
00022 
00023 image_format::~image_format()
00024 {
00025     delete [] data;
00026 }
00027 
00028 
00029 image_format::image_format(int a_width, int a_height, data_t *a_data) :
00030     width(a_width),
00031     height(a_height),
00032     data(a_data)
00033 {
00034     assert(width >= 1);
00035     assert(height >= 1);
00036     assert(!!data);
00037 }
00038 
00039 
00040 image_format::image_format(int a_width, int a_height) :
00041     width(a_width),
00042     height(a_height),
00043     data(0)
00044 {
00045     size_t nbytes = 4 * width * height;
00046     data = new unsigned char [nbytes];
00047     memset(data, 0, nbytes);
00048 }
00049 
00050 
00051 image_format &
00052 image_format::operator=(const image_format &arg)
00053 {
00054     if (this != &arg)
00055     {
00056         delete [] data;
00057         width = arg.width;
00058         height = arg.height;
00059         size_t nbytes = 4 * width * height;
00060         data = new unsigned char [nbytes];
00061         memcpy(data, arg.data, nbytes);
00062     }
00063     return *this;
00064 }
00065 
00066 
00067 unsigned
00068 image_format::get_width(void)
00069     const
00070 {
00071     return width;
00072 }
00073 
00074 
00075 unsigned
00076 image_format::get_height(void)
00077     const
00078 {
00079     return height;
00080 }