2014-10-21 09:21:31 +08:00
|
|
|
// Aseprite Document Library
|
2023-08-08 02:12:11 +08:00
|
|
|
// Copyright (c) 2023 Igara Studio S.A.
|
2015-06-12 05:59:51 +08:00
|
|
|
// Copyright (c) 2001-2015 David Capello
|
2014-10-21 09:21:31 +08:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifndef DOC_PRIMITIVES_FAST_H_INCLUDED
|
|
|
|
#define DOC_PRIMITIVES_FAST_H_INCLUDED
|
2014-03-30 06:40:17 +08:00
|
|
|
#pragma once
|
2013-11-10 06:59:05 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/color.h"
|
2024-12-19 20:36:27 +08:00
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/image_impl.h"
|
2023-08-08 02:12:11 +08:00
|
|
|
#include "doc/image_traits.h"
|
2013-11-10 06:59:05 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
namespace doc {
|
2024-12-19 20:36:27 +08:00
|
|
|
|
2015-06-13 00:56:18 +08:00
|
|
|
template<typename ImageTraits>
|
|
|
|
class ImageImpl;
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2015-06-12 05:59:51 +08:00
|
|
|
template<class Traits>
|
|
|
|
inline typename Traits::address_t get_pixel_address_fast(const Image* image, int x, int y)
|
|
|
|
{
|
|
|
|
ASSERT(x >= 0 && x < image->width());
|
|
|
|
ASSERT(y >= 0 && y < image->height());
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2015-06-12 05:59:51 +08:00
|
|
|
return (((ImageImpl<Traits>*)image)->address(x, y));
|
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
template<class Traits>
|
|
|
|
inline typename Traits::pixel_t get_pixel_fast(const Image* image, int x, int y)
|
|
|
|
{
|
2014-07-30 12:28:15 +08:00
|
|
|
ASSERT(x >= 0 && x < image->width());
|
|
|
|
ASSERT(y >= 0 && y < image->height());
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-11 01:49:06 +08:00
|
|
|
return *(((ImageImpl<Traits>*)image)->address(x, y));
|
2013-11-10 06:59:05 +08:00
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
template<class Traits>
|
|
|
|
inline void put_pixel_fast(Image* image, int x, int y, typename Traits::pixel_t color)
|
|
|
|
{
|
2014-07-30 12:28:15 +08:00
|
|
|
ASSERT(x >= 0 && x < image->width());
|
|
|
|
ASSERT(y >= 0 && y < image->height());
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-11 01:49:06 +08:00
|
|
|
*(((ImageImpl<Traits>*)image)->address(x, y)) = color;
|
2013-11-10 06:59:05 +08:00
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Bitmap specialization
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2024-12-21 09:39:42 +08:00
|
|
|
#if DOC_USE_BITMAP_AS_1BPP
|
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
template<>
|
|
|
|
inline BitmapTraits::pixel_t get_pixel_fast<BitmapTraits>(const Image* image, int x, int y)
|
|
|
|
{
|
2014-07-30 12:28:15 +08:00
|
|
|
ASSERT(x >= 0 && x < image->width());
|
|
|
|
ASSERT(y >= 0 && y < image->height());
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
return (*image->getPixelAddress(x, y)) & (1 << (x % 8)) ? 1 : 0;
|
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
template<>
|
|
|
|
inline void put_pixel_fast<BitmapTraits>(Image* image, int x, int y, BitmapTraits::pixel_t color)
|
|
|
|
{
|
2014-07-30 12:28:15 +08:00
|
|
|
ASSERT(x >= 0 && x < image->width());
|
|
|
|
ASSERT(y >= 0 && y < image->height());
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
if (color)
|
|
|
|
*image->getPixelAddress(x, y) |= (1 << (x % 8));
|
|
|
|
else
|
|
|
|
*image->getPixelAddress(x, y) &= ~(1 << (x % 8));
|
|
|
|
}
|
|
|
|
|
2024-12-21 09:39:42 +08:00
|
|
|
#endif // DOC_USE_BITMAP_AS_1BPP
|
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
} // namespace doc
|
2013-11-10 06:59:05 +08:00
|
|
|
|
|
|
|
#endif
|