mirror of
https://github.com/darlinghq/xcbuild.git
synced 2025-02-19 08:08:18 +00:00
Add representation of an image.
This commit is contained in:
parent
b4a4c49e03
commit
8c15c7d9ca
@ -8,6 +8,7 @@
|
||||
#
|
||||
|
||||
add_library(graphics SHARED
|
||||
Sources/Image.cpp
|
||||
Sources/PixelFormat.cpp
|
||||
)
|
||||
|
||||
|
64
Libraries/graphics/Headers/graphics/Image.h
Normal file
64
Libraries/graphics/Headers/graphics/Image.h
Normal 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
|
24
Libraries/graphics/Sources/Image.cpp
Normal file
24
Libraries/graphics/Sources/Image.cpp
Normal 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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user