Add representation of an image.

This commit is contained in:
Grant Paul 2016-07-17 15:29:40 -07:00
parent b4a4c49e03
commit 8c15c7d9ca
3 changed files with 89 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#
add_library(graphics SHARED
Sources/Image.cpp
Sources/PixelFormat.cpp
)

View File

@ -0,0 +1,64 @@
/**
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef __graphics_Image_h
#define __graphics_Image_h
#include <graphics/PixelFormat.h>
#include <cstddef>
#include <cstdint>
namespace graphics {
/*
* Contains an image data and metadata.
*/
class Image {
private:
size_t _width;
size_t _height;
private:
PixelFormat _format;
std::vector<uint8_t> _data;
public:
Image(size_t width, size_t height, PixelFormat format, std::vector<uint8_t> const &data);
public:
/*
* The width of the image, in pixels.
*/
size_t width() const
{ return _width; }
/*
* The height of the image, in pixels.
*/
size_t height() const
{ return _height; }
public:
/*
* The pixel format of the image data.
*/
PixelFormat const &format() const
{ return _format; }
/*
* The alpha channel.
*/
std::vector<uint8_t> const &data() const
{ return _data; }
};
}
#endif // !__graphics_Image_h

View File

@ -0,0 +1,24 @@
/**
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
*/
#include <graphics/Image.h>
#include <cassert>
using graphics::Image;
Image::
Image(size_t width, size_t height, PixelFormat format, std::vector<uint8_t> const &data) :
_width (width),
_height(height),
_format(format),
_data (data)
{
assert(data.size() == _width * _height * _format.bytesPerPixel());
}