I would like lol::image to be accessible in the header-only section of the framework, which means rethinking the locking mechanism and the way codecs are exposed to the image class.wip/kinc
| @@ -21,10 +21,10 @@ using namespace lol; | |||
| int main(int, char **) | |||
| { | |||
| ivec2 const size(64); | |||
| auto const &kernel = image::kernel::blue_noise(size, ivec2(8)); | |||
| auto const &kernel = old_image::kernel::blue_noise(size, ivec2(8)); | |||
| image im(size.xy); | |||
| array2d<vec4> &data = im.lock2d<PixelFormat::RGBA_F32>(); | |||
| old_image im(size.xy); | |||
| old_array2d<vec4> &data = im.lock2d<PixelFormat::RGBA_F32>(); | |||
| for (int j = 0; j < size.y; ++j) | |||
| for (int i = 0; i < size.x; ++i) | |||
| @@ -30,8 +30,8 @@ int main(int, char **) | |||
| srand(time(nullptr)); | |||
| /* Create an image */ | |||
| image img(size); | |||
| array2d<vec4> &data = img.lock2d<PixelFormat::RGBA_F32>(); | |||
| old_image img(size); | |||
| old_array2d<vec4> &data = img.lock2d<PixelFormat::RGBA_F32>(); | |||
| /* Declare plenty of allocators */ | |||
| simplex_noise<2> s2; | |||
| @@ -33,9 +33,9 @@ int main(int, char **) | |||
| for (int i = 0; i < 256; ++i) | |||
| { | |||
| lol::image im(size); | |||
| lol::old_image im(size); | |||
| lol::array2d<lol::u8vec3> &data = im.lock2d<lol::PixelFormat::RGB_8>(); | |||
| lol::old_array2d<lol::u8vec3> &data = im.lock2d<lol::PixelFormat::RGB_8>(); | |||
| for (int y = 0; y < size.y; ++y) | |||
| for (int x = 0; x < size.x; ++x) | |||
| { | |||
| @@ -1 +1 @@ | |||
| Subproject commit c54b4cbe07377e92df59dfb920951c8d72240e3f | |||
| Subproject commit e0730821501436dee4056a4a17f7e312ac9df249 | |||
| @@ -283,9 +283,9 @@ ivec2 Framebuffer::GetSize() const | |||
| return m_data->m_size; | |||
| } | |||
| image Framebuffer::GetImage() const | |||
| old_image Framebuffer::GetImage() const | |||
| { | |||
| image ret(m_data->m_size); | |||
| old_image ret(m_data->m_size); | |||
| u8vec4 *buffer = ret.lock<PixelFormat::RGBA_8>(); | |||
| glReadPixels(0, 0, m_data->m_size.x, m_data->m_size.y, | |||
| @@ -94,7 +94,7 @@ ResourceCodecData* AndroidImageCodec::Load(std::string const &path) | |||
| int height = env->CallIntMethod(g_activity->clazz, mid, m_bmp); | |||
| ivec2 size(width, height); | |||
| auto data = new ResourceImageData(new image(size)); | |||
| auto data = new ResourceImageData(new old_image(size)); | |||
| // Get pixels | |||
| m_array = env->NewIntArray(size.x * size.y); | |||
| @@ -43,9 +43,9 @@ ResourceCodecData* DummyImageCodec::Load(std::string const &path) | |||
| if (path == "DUMMY") | |||
| return nullptr; | |||
| auto data = new ResourceImageData(new image(ivec2(256))); | |||
| auto image = data->m_image; | |||
| u8vec4 *pixels = image->lock<PixelFormat::RGBA_8>(), *tmp = pixels; | |||
| auto data = new ResourceImageData(new old_image(ivec2(256))); | |||
| auto old_image = data->m_image; | |||
| u8vec4 *pixels = old_image->lock<PixelFormat::RGBA_8>(), *tmp = pixels; | |||
| for (int j = 0; j < 256; j++) | |||
| for (int i = 0; i < 256; i++) | |||
| { | |||
| @@ -55,7 +55,7 @@ ResourceCodecData* DummyImageCodec::Load(std::string const &path) | |||
| tmp->a = (((i >> 4) ^ (j >> 4)) & 1) * 0xff; | |||
| ++tmp; | |||
| } | |||
| image->unlock(pixels); | |||
| old_image->unlock(pixels); | |||
| return data; | |||
| } | |||
| @@ -108,7 +108,7 @@ ResourceCodecData* GdiPlusImageCodec::Load(std::string const &path) | |||
| /* FIXME: GDI+ doesn't know about RGBA, only ARGB. And OpenGL doesn't | |||
| * know about ARGB, only RGBA. So we swap bytes. We could also fix | |||
| * this in the shader. */ | |||
| auto data = new ResourceImageData(new image(ivec2(size))); | |||
| auto data = new ResourceImageData(new old_image(ivec2(size))); | |||
| auto image = data->m_image; | |||
| u8vec4 *pdst = image->lock<PixelFormat::RGBA_8>(); | |||
| u8vec4 *psrc = static_cast<u8vec4 *>(bdata.Scan0); | |||
| @@ -70,7 +70,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(std::string const &path) | |||
| } | |||
| ivec2 size(imlib_image_get_width(), imlib_image_get_height()); | |||
| auto data = new ResourceImageData(new image(size)); | |||
| auto data = new ResourceImageData(new old_image(size)); | |||
| auto image = data->m_image; | |||
| u8vec4 *dstdata = image->lock<PixelFormat::RGBA_8>(); | |||
| @@ -40,7 +40,7 @@ public: | |||
| private: | |||
| static std::string ReadScreen(std::string const &name); | |||
| static void WriteScreen(image &image, std::vector<uint8_t> &result); | |||
| static void WriteScreen(old_image &old_image, std::vector<uint8_t> &result); | |||
| }; | |||
| DECLARE_IMAGE_CODEC(OricImageCodec, 100) | |||
| @@ -67,7 +67,7 @@ ResourceCodecData* OricImageCodec::Load(std::string const &path) | |||
| if (screen.length() == 0) | |||
| return nullptr; | |||
| auto data = new ResourceImageData(new image(ivec2(WIDTH, (int)screen.length() * 6 / WIDTH))); | |||
| auto data = new ResourceImageData(new old_image(ivec2(WIDTH, (int)screen.length() * 6 / WIDTH))); | |||
| auto img = data->m_image; | |||
| u8vec4 *pixels = img->lock<PixelFormat::RGBA_8>(); | |||
| @@ -135,7 +135,7 @@ bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||
| result.push_back(0); | |||
| auto img = data_image->m_image; | |||
| image tmp; | |||
| old_image tmp; | |||
| ivec2 size = img->size(); | |||
| if (size.x != WIDTH) | |||
| { | |||
| @@ -467,14 +467,14 @@ static uint8_t bestmove(ivec3 const *in, u8vec2 bgfg, | |||
| return bestcommand; | |||
| } | |||
| void OricImageCodec::WriteScreen(image &img, std::vector<uint8_t> &result) | |||
| void OricImageCodec::WriteScreen(old_image &img, std::vector<uint8_t> &result) | |||
| { | |||
| ivec2 size = img.size(); | |||
| vec4 *pixels = img.lock<PixelFormat::RGBA_F32>(); | |||
| int stride = (size.x + 1); | |||
| array2d<ivec3> src, dst; | |||
| old_array2d<ivec3> src, dst; | |||
| src.resize(size + ivec2(1)); | |||
| dst.resize(size + ivec2(1)); | |||
| @@ -53,7 +53,7 @@ ResourceCodecData* SdlImageCodec::Load(std::string const &path) | |||
| if (!surface) | |||
| { | |||
| #if !LOL_BUILD_RELEASE | |||
| msg::error("could not load image %s\n", path.c_str()); | |||
| msg::error("could not load old_image %s\n", path.c_str()); | |||
| #endif | |||
| return nullptr; | |||
| } | |||
| @@ -68,11 +68,11 @@ ResourceCodecData* SdlImageCodec::Load(std::string const &path) | |||
| surface = tmp; | |||
| } | |||
| auto data = new ResourceImageData(new image(size)); | |||
| auto image = data->m_image; | |||
| u8vec4 *pixel_data = image->lock<PixelFormat::RGBA_8>(); | |||
| auto data = new ResourceImageData(new old_image(size)); | |||
| auto old_image = data->m_image; | |||
| u8vec4 *pixel_data = old_image->lock<PixelFormat::RGBA_8>(); | |||
| memcpy((void *)pixel_data, surface->pixels, sizeof(*pixel_data) * size.x * size.y); | |||
| image->unlock(pixel_data); | |||
| old_image->unlock(pixel_data); | |||
| SDL_FreeSurface(surface); | |||
| @@ -85,13 +85,13 @@ bool SdlImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||
| if (data_image == nullptr) | |||
| return false; | |||
| auto image = data_image->m_image; | |||
| ivec2 size = image->size(); | |||
| auto old_image = data_image->m_image; | |||
| ivec2 size = old_image->size(); | |||
| SDL_Surface *surface = Create32BppSurface(size); | |||
| u8vec4 *pixel_data = image->lock<PixelFormat::RGBA_8>(); | |||
| u8vec4 *pixel_data = old_image->lock<PixelFormat::RGBA_8>(); | |||
| memcpy(surface->pixels, pixel_data, 4 * size.x * size.y); | |||
| image->unlock(pixel_data); | |||
| old_image->unlock(pixel_data); | |||
| int ret = SDL_SaveBMP(surface, path.c_str()); | |||
| SDL_FreeSurface(surface); | |||
| @@ -36,7 +36,7 @@ enum class MergeMode | |||
| }; | |||
| template<PixelFormat FORMAT, MergeMode MODE> | |||
| static image generic_merge(image &src1, image &src2, float alpha) | |||
| static old_image generic_merge(old_image &src1, old_image &src2, float alpha) | |||
| { | |||
| using std::min, std::max, std::fabs; | |||
| @@ -45,7 +45,7 @@ static image generic_merge(image &src1, image &src2, float alpha) | |||
| assert(src1.size() == src2.size()); | |||
| int const count = src1.size().x * src2.size().y; | |||
| image dst(src1.size()); | |||
| old_image dst(src1.size()); | |||
| pixel_t const *src1p = src1.lock<FORMAT>(); | |||
| pixel_t const *src2p = src2.lock<FORMAT>(); | |||
| @@ -84,7 +84,7 @@ static image generic_merge(image &src1, image &src2, float alpha) | |||
| } | |||
| template<MergeMode MODE> | |||
| static image generic_merge(image &src1, image &src2, float alpha) | |||
| static old_image generic_merge(old_image &src1, old_image &src2, float alpha) | |||
| { | |||
| bool gray1 = src1.format() == PixelFormat::Y_8 | |||
| || src1.format() == PixelFormat::Y_F32; | |||
| @@ -97,57 +97,57 @@ static image generic_merge(image &src1, image &src2, float alpha) | |||
| } | |||
| image image::Merge(image &src1, image &src2, float alpha) | |||
| old_image old_image::Merge(old_image &src1, old_image &src2, float alpha) | |||
| { | |||
| return generic_merge<MergeMode::Mix>(src1, src2, alpha); | |||
| } | |||
| image image::Mean(image &src1, image &src2) | |||
| old_image old_image::Mean(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Mix>(src1, src2, 0.5f); | |||
| } | |||
| image image::Min(image &src1, image &src2) | |||
| old_image old_image::Min(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Min>(src1, src2, 0.0f); | |||
| } | |||
| image image::Max(image &src1, image &src2) | |||
| old_image old_image::Max(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Max>(src1, src2, 0.0f); | |||
| } | |||
| image image::Overlay(image &src1, image &src2) | |||
| old_image old_image::Overlay(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Overlay>(src1, src2, 0.0f); | |||
| } | |||
| image image::Screen(image &src1, image &src2) | |||
| old_image old_image::Screen(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Screen>(src1, src2, 0.0f); | |||
| } | |||
| image image::Divide(image &src1, image &src2) | |||
| old_image old_image::Divide(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Divide>(src1, src2, 0.0f); | |||
| } | |||
| image image::Multiply(image &src1, image &src2) | |||
| old_image old_image::Multiply(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Multiply>(src1, src2, 0.0f); | |||
| } | |||
| image image::Add(image &src1, image &src2) | |||
| old_image old_image::Add(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Add>(src1, src2, 0.0f); | |||
| } | |||
| image image::Sub(image &src1, image &src2) | |||
| old_image old_image::Sub(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Sub>(src1, src2, 0.0f); | |||
| } | |||
| image image::Difference(image &src1, image &src2) | |||
| old_image old_image::Difference(old_image &src1, old_image &src2) | |||
| { | |||
| return generic_merge<MergeMode::Difference>(src1, src2, 0.0f); | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -21,12 +21,12 @@ | |||
| namespace lol | |||
| { | |||
| image image::Crop(ibox2 box) const | |||
| old_image old_image::Crop(ibox2 box) const | |||
| { | |||
| ivec2 const srcsize = size(); | |||
| ivec2 const dstsize = box.extent(); | |||
| image dst(dstsize); | |||
| old_image dst(dstsize); | |||
| PixelFormat fmt = format(); | |||
| if (fmt != PixelFormat::Unknown) | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -26,12 +26,12 @@ namespace lol | |||
| /* FIXME: though the algorithm is supposed to stop, we do not have a real, | |||
| * guaranteed stop condition here. */ | |||
| image image::dither_dbs() const | |||
| old_image old_image::dither_dbs() const | |||
| { | |||
| ivec2 isize = size(); | |||
| /* Build our human visual system kernel. */ | |||
| array2d<float> ker; | |||
| old_array2d<float> ker; | |||
| ker.resize(ivec2(NN, NN)); | |||
| float t = 0.f; | |||
| for (int j = 0; j < NN; j++) | |||
| @@ -50,20 +50,20 @@ image image::dither_dbs() const | |||
| /* A list of cells in our picture. If no change is done to a cell | |||
| * for two iterations, we stop considering changes to it. */ | |||
| ivec2 const csize = (isize + ivec2(CELL - 1)) / CELL; | |||
| array2d<int> changelist(csize); | |||
| old_array2d<int> changelist(csize); | |||
| memset(changelist.data(), 0, changelist.bytes()); | |||
| image dst = *this; | |||
| old_image dst = *this; | |||
| dst.set_format(PixelFormat::Y_F32); | |||
| image tmp1 = dst.Convolution(ker); | |||
| array2d<float> &tmp1data = tmp1.lock2d<PixelFormat::Y_F32>(); | |||
| old_image tmp1 = dst.Convolution(ker); | |||
| old_array2d<float> &tmp1data = tmp1.lock2d<PixelFormat::Y_F32>(); | |||
| dst = dst.dither_random(); | |||
| array2d<float> &dstdata = dst.lock2d<PixelFormat::Y_F32>(); | |||
| old_array2d<float> &dstdata = dst.lock2d<PixelFormat::Y_F32>(); | |||
| image tmp2 = dst.Convolution(ker); | |||
| array2d<float> &tmp2data = tmp2.lock2d<PixelFormat::Y_F32>(); | |||
| old_image tmp2 = dst.Convolution(ker); | |||
| old_array2d<float> &tmp2data = tmp2.lock2d<PixelFormat::Y_F32>(); | |||
| for (int run = 0, last_change = 0; ; ++run) | |||
| { | |||
| @@ -71,7 +71,7 @@ image image::dither_dbs() const | |||
| int const cx = cell % csize.x; | |||
| int const cy = cell / csize.x; | |||
| /* Bail out if no change was done for the last full image run */ | |||
| /* Bail out if no change was done for the last full old_image run */ | |||
| if (run > last_change + csize.x * csize.y) | |||
| break; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -25,9 +25,9 @@ namespace lol | |||
| * Making the matrix generic is not terribly slower: the performance | |||
| * hit is around 4% for Floyd-Steinberg and 13% for JaJuNi, with the | |||
| * benefit of a lot less code. */ | |||
| image image::dither_ediff(array2d<float> const &ker, ScanMode scan) const | |||
| old_image old_image::dither_ediff(old_array2d<float> const &ker, ScanMode scan) const | |||
| { | |||
| image dst = *this; | |||
| old_image dst = *this; | |||
| ivec2 isize = dst.size(); | |||
| ivec2 ksize = ker.sizes(); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -19,27 +19,27 @@ | |||
| namespace lol | |||
| { | |||
| static image dither_helper(image const &img, array2d<float> const &ker, | |||
| static old_image dither_helper(old_image const &img, old_array2d<float> const &ker, | |||
| float scale, float angle); | |||
| image image::dither_ordered(array2d<float> const &ker) const | |||
| old_image old_image::dither_ordered(old_array2d<float> const &ker) const | |||
| { | |||
| return dither_helper(*this, ker, 1.0f, 0.0f); | |||
| } | |||
| image image::dither_halftone(float radius, float angle) const | |||
| old_image old_image::dither_halftone(float radius, float angle) const | |||
| { | |||
| /* Increasing the precision is necessary or the rotation will look | |||
| * like crap. So we create a kernel PRECISION times larger, and ask | |||
| * the ditherer to scale it by 1/PRECISION. */ | |||
| float const PRECISION = 4.f; | |||
| int k = (int)std::round(radius * PRECISION * lol::sqrt(2.f)); | |||
| array2d<float> ker = image::kernel::halftone(ivec2(k, k)); | |||
| old_array2d<float> ker = old_image::kernel::halftone(ivec2(k, k)); | |||
| return dither_helper(*this, ker, 1.f / PRECISION, angle + F_PI / 4.f); | |||
| } | |||
| static image dither_helper(image const &img, array2d<float> const &ker, | |||
| static old_image dither_helper(old_image const &img, old_array2d<float> const &ker, | |||
| float scale, float angle) | |||
| { | |||
| ivec2 isize = img.size(); | |||
| @@ -48,7 +48,7 @@ static image dither_helper(image const &img, array2d<float> const &ker, | |||
| float cost = lol::cos(angle); | |||
| float sint = lol::sin(angle); | |||
| image ret = img; | |||
| old_image ret = img; | |||
| float *dstp = ret.lock<PixelFormat::Y_F32>(); | |||
| for (int y = 0; y < isize.y; y++) | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -71,9 +71,9 @@ static inline vec3 GetDiffusion(float v) | |||
| return ret; | |||
| } | |||
| image image::dither_ostromoukhov(ScanMode scan) const | |||
| old_image old_image::dither_ostromoukhov(ScanMode scan) const | |||
| { | |||
| image dst = *this; | |||
| old_image dst = *this; | |||
| float *pixels = dst.lock<PixelFormat::Y_F32>(); | |||
| int w = dst.size().x; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -19,9 +19,9 @@ | |||
| namespace lol | |||
| { | |||
| image image::dither_random() const | |||
| old_image old_image::dither_random() const | |||
| { | |||
| image dst = *this; | |||
| old_image dst = *this; | |||
| float *pixels = dst.lock<PixelFormat::Y_F32>(); | |||
| int count = size().x * size().y; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -19,9 +19,9 @@ | |||
| namespace lol | |||
| { | |||
| image image::Brightness(float val) const | |||
| old_image old_image::Brightness(float val) const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) | |||
| @@ -43,9 +43,9 @@ image image::Brightness(float val) const | |||
| return ret; | |||
| } | |||
| image image::Contrast(float val) const | |||
| old_image old_image::Contrast(float val) const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| if (val >= 0.f) | |||
| @@ -85,9 +85,9 @@ image image::Contrast(float val) const | |||
| * TODO: the current approach is naive; we should use the histogram in order | |||
| * to decide how to change the contrast. | |||
| */ | |||
| image image::AutoContrast() const | |||
| old_image old_image::AutoContrast() const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| float min_val = 1.f, max_val = 0.f; | |||
| int count = size().x * size().y; | |||
| @@ -133,9 +133,9 @@ image image::AutoContrast() const | |||
| return ret; | |||
| } | |||
| image image::Invert() const | |||
| old_image old_image::Invert() const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) | |||
| @@ -156,9 +156,9 @@ image image::Invert() const | |||
| return ret; | |||
| } | |||
| image image::Threshold(float val) const | |||
| old_image old_image::Threshold(float val) const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| float *pixels = ret.lock<PixelFormat::Y_F32>(); | |||
| @@ -169,9 +169,9 @@ image image::Threshold(float val) const | |||
| return ret; | |||
| } | |||
| image image::Threshold(vec3 val) const | |||
| old_image old_image::Threshold(vec3 val) const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| vec4 *pixels = ret.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -21,11 +21,11 @@ | |||
| namespace lol | |||
| { | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| static old_image SepConv(old_image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec); | |||
| static image NonSepConv(image &src, array2d<float> const &in_kernel); | |||
| static old_image NonSepConv(old_image &src, old_array2d<float> const &in_kernel); | |||
| image image::Convolution(array2d<float> const &in_kernel) | |||
| old_image old_image::Convolution(old_array2d<float> const &in_kernel) | |||
| { | |||
| /* Find the cell with the largest value */ | |||
| ivec2 ksize = in_kernel.sizes(); | |||
| @@ -83,10 +83,10 @@ image image::Convolution(array2d<float> const &in_kernel) | |||
| } | |||
| } | |||
| image image::Sharpen(array2d<float> const &in_kernel) | |||
| old_image old_image::Sharpen(old_array2d<float> const &in_kernel) | |||
| { | |||
| ivec2 ksize = in_kernel.sizes(); | |||
| array2d<float> newkernel(ksize); | |||
| old_array2d<float> newkernel(ksize); | |||
| for (int dy = 0; dy < ksize.y; ++dy) | |||
| for (int dx = 0; dx < ksize.x; ++dx) | |||
| @@ -100,16 +100,16 @@ image image::Sharpen(array2d<float> const &in_kernel) | |||
| } | |||
| template<PixelFormat FORMAT, int WRAP_X, int WRAP_Y> | |||
| static image NonSepConv(image &src, array2d<float> const &in_kernel) | |||
| static old_image NonSepConv(old_image &src, old_array2d<float> const &in_kernel) | |||
| { | |||
| typedef typename PixelType<FORMAT>::type pixel_t; | |||
| ivec2 const size = src.size(); | |||
| ivec2 const ksize = in_kernel.sizes(); | |||
| image dst(size); | |||
| old_image dst(size); | |||
| array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | |||
| array2d<pixel_t> &dstp = dst.lock2d<FORMAT>(); | |||
| old_array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | |||
| old_array2d<pixel_t> &dstp = dst.lock2d<FORMAT>(); | |||
| for (int y = 0; y < size.y; y++) | |||
| { | |||
| @@ -149,7 +149,7 @@ static image NonSepConv(image &src, array2d<float> const &in_kernel) | |||
| return dst; | |||
| } | |||
| static image NonSepConv(image &src, array2d<float> const &in_kernel) | |||
| static old_image NonSepConv(old_image &src, old_array2d<float> const &in_kernel) | |||
| { | |||
| bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; | |||
| bool const wrap_y = src.GetWrapY() == WrapMode::Repeat; | |||
| @@ -192,19 +192,19 @@ static image NonSepConv(image &src, array2d<float> const &in_kernel) | |||
| } | |||
| template<PixelFormat FORMAT, int WRAP_X, int WRAP_Y> | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| static old_image SepConv(old_image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec) | |||
| { | |||
| typedef typename PixelType<FORMAT>::type pixel_t; | |||
| ivec2 const size = src.size(); | |||
| ivec2 const ksize(int(hvec.size()), int(vvec.size())); | |||
| image dst(size); | |||
| old_image dst(size); | |||
| array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | |||
| array2d<pixel_t> &dstp = dst.lock2d<FORMAT>(); | |||
| old_array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | |||
| old_array2d<pixel_t> &dstp = dst.lock2d<FORMAT>(); | |||
| array2d<pixel_t> tmp(size); | |||
| old_array2d<pixel_t> tmp(size); | |||
| for (int y = 0; y < size.y; y++) | |||
| { | |||
| @@ -254,7 +254,7 @@ static image SepConv(image &src, std::vector<float> const &hvec, | |||
| return dst; | |||
| } | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| static old_image SepConv(old_image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec) | |||
| { | |||
| bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -24,10 +24,10 @@ | |||
| namespace lol | |||
| { | |||
| image image::Dilate() | |||
| old_image old_image::Dilate() | |||
| { | |||
| ivec2 isize = size(); | |||
| image ret(isize); | |||
| old_image ret(isize); | |||
| if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) | |||
| { | |||
| @@ -81,10 +81,10 @@ image image::Dilate() | |||
| return ret; | |||
| } | |||
| image image::Erode() | |||
| old_image old_image::Erode() | |||
| { | |||
| ivec2 isize = size(); | |||
| image ret(isize); | |||
| old_image ret(isize); | |||
| if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) | |||
| { | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -35,16 +35,16 @@ static int cmpfloat(void const *i1, void const *i2) | |||
| return (a > b) - (a < b); | |||
| } | |||
| image image::Median(ivec2 ksize) const | |||
| old_image old_image::Median(ivec2 ksize) const | |||
| { | |||
| ivec2 const isize = size(); | |||
| image tmp = *this; | |||
| image ret(isize); | |||
| old_image tmp = *this; | |||
| old_image ret(isize); | |||
| if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) | |||
| { | |||
| ivec2 const lsize = 2 * ksize + ivec2(1); | |||
| array2d<float> list(lsize); | |||
| old_array2d<float> list(lsize); | |||
| float *srcp = tmp.lock<PixelFormat::Y_F32>(); | |||
| float *dstp = ret.lock<PixelFormat::Y_F32>(); | |||
| @@ -84,7 +84,7 @@ image image::Median(ivec2 ksize) const | |||
| else | |||
| { | |||
| ivec2 const lsize = 2 * ksize + ivec2(1); | |||
| array2d<vec3> list(lsize); | |||
| old_array2d<vec3> list(lsize); | |||
| vec4 *srcp = tmp.lock<PixelFormat::RGBA_F32>(); | |||
| vec4 *dstp = ret.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -152,11 +152,11 @@ image image::Median(ivec2 ksize) const | |||
| return ret; | |||
| } | |||
| image image::Median(array2d<float> const &ker) const | |||
| old_image old_image::Median(old_array2d<float> const &ker) const | |||
| { | |||
| ivec2 const isize = size(); | |||
| image tmp = *this; | |||
| image ret(isize); | |||
| old_image tmp = *this; | |||
| old_image ret(isize); | |||
| /* FIXME: TODO */ | |||
| #if 0 | |||
| @@ -167,7 +167,7 @@ image image::Median(array2d<float> const &ker) const | |||
| #endif | |||
| { | |||
| ivec2 const ksize = ker.sizes(); | |||
| array2d<vec3> list(ksize); | |||
| old_array2d<vec3> list(ksize); | |||
| vec4 *srcp = tmp.lock<PixelFormat::RGBA_F32>(); | |||
| vec4 *dstp = ret.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -20,9 +20,9 @@ | |||
| namespace lol | |||
| { | |||
| image image::YUVToRGB() const | |||
| old_image old_image::YUVToRGB() const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| vec4 *pixels = ret.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -33,9 +33,9 @@ image image::YUVToRGB() const | |||
| return ret; | |||
| } | |||
| image image::RGBToYUV() const | |||
| old_image old_image::RGBToYUV() const | |||
| { | |||
| image ret = *this; | |||
| old_image ret = *this; | |||
| int count = size().x * size().y; | |||
| vec4 *pixels = ret.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -44,12 +44,12 @@ public: | |||
| virtual void *data2d() { return &m_array2d; } | |||
| virtual void const *data2d() const { return &m_array2d; } | |||
| array2d<typename PixelType<T>::type> m_array2d; | |||
| old_array2d<typename PixelType<T>::type> m_array2d; | |||
| }; | |||
| class image_data | |||
| { | |||
| friend class image; | |||
| friend class old_image; | |||
| public: | |||
| image_data() | |||
| @@ -21,33 +21,33 @@ namespace lol | |||
| { | |||
| /* | |||
| * Public image class | |||
| * Public old_image class | |||
| */ | |||
| image::image() | |||
| old_image::old_image() | |||
| : m_data(new image_data()) | |||
| { | |||
| } | |||
| image::image(std::string const &path) | |||
| old_image::old_image(std::string const &path) | |||
| : m_data(new image_data()) | |||
| { | |||
| load(path); | |||
| } | |||
| image::image(ivec2 size) | |||
| old_image::old_image(ivec2 size) | |||
| : m_data(new image_data()) | |||
| { | |||
| resize(size); | |||
| } | |||
| image::image (image const &other) | |||
| old_image::old_image (old_image const &other) | |||
| : m_data(new image_data()) | |||
| { | |||
| Copy(other); | |||
| } | |||
| image & image::operator =(image other) | |||
| old_image & old_image::operator =(old_image other) | |||
| { | |||
| /* Since the argument is passed by value, we’re assured it’s a new | |||
| * object and we can safely swap our m_data pointers. */ | |||
| @@ -55,7 +55,7 @@ image & image::operator =(image other) | |||
| return *this; | |||
| } | |||
| image::~image() | |||
| old_image::~old_image() | |||
| { | |||
| for (auto &kv : m_data->m_pixels) | |||
| delete kv.second; | |||
| @@ -63,7 +63,7 @@ image::~image() | |||
| delete m_data; | |||
| } | |||
| void image::Copy(uint8_t* src_pixels, ivec2 const& size, PixelFormat fmt) | |||
| void old_image::Copy(uint8_t* src_pixels, ivec2 const& size, PixelFormat fmt) | |||
| { | |||
| assert(fmt != PixelFormat::Unknown); | |||
| resize(size); | |||
| @@ -72,7 +72,7 @@ void image::Copy(uint8_t* src_pixels, ivec2 const& size, PixelFormat fmt) | |||
| size.x * size.y * BytesPerPixel(fmt)); | |||
| } | |||
| void image::Copy(image const &src) | |||
| void old_image::Copy(old_image const &src) | |||
| { | |||
| ivec2 size = src.size(); | |||
| PixelFormat fmt = src.format(); | |||
| @@ -87,12 +87,12 @@ void image::Copy(image const &src) | |||
| } | |||
| } | |||
| void image::DummyFill() | |||
| void old_image::DummyFill() | |||
| { | |||
| load("DUMMY"); | |||
| } | |||
| bool image::load(std::string const &path) | |||
| bool old_image::load(std::string const &path) | |||
| { | |||
| auto resource = ResourceLoader::Load(path); | |||
| if (resource == nullptr) | |||
| @@ -110,20 +110,20 @@ bool image::load(std::string const &path) | |||
| return true; | |||
| } | |||
| bool image::save(std::string const &path) | |||
| bool old_image::save(std::string const &path) | |||
| { | |||
| auto data = new ResourceImageData(new image(*this)); | |||
| auto data = new ResourceImageData(new old_image(*this)); | |||
| auto result = ResourceLoader::Save(path, data); | |||
| delete data; | |||
| return result; | |||
| } | |||
| ivec2 image::size() const | |||
| ivec2 old_image::size() const | |||
| { | |||
| return m_data->m_size; | |||
| } | |||
| void image::resize(ivec2 size) | |||
| void old_image::resize(ivec2 size) | |||
| { | |||
| assert(size.x > 0); | |||
| assert(size.y > 0); | |||
| @@ -140,24 +140,24 @@ void image::resize(ivec2 size) | |||
| } | |||
| /* Wrap-around mode for some operations */ | |||
| WrapMode image::GetWrapX() const | |||
| WrapMode old_image::GetWrapX() const | |||
| { | |||
| return m_data->m_wrap_x; | |||
| } | |||
| WrapMode image::GetWrapY() const | |||
| WrapMode old_image::GetWrapY() const | |||
| { | |||
| return m_data->m_wrap_y; | |||
| } | |||
| void image::SetWrap(WrapMode wrap_x, WrapMode wrap_y) | |||
| void old_image::SetWrap(WrapMode wrap_x, WrapMode wrap_y) | |||
| { | |||
| m_data->m_wrap_x = wrap_x; | |||
| m_data->m_wrap_y = wrap_y; | |||
| } | |||
| /* The lock() method */ | |||
| template<PixelFormat T> typename PixelType<T>::type *image::lock() | |||
| template<PixelFormat T> typename PixelType<T>::type *old_image::lock() | |||
| { | |||
| set_format(T); | |||
| @@ -165,7 +165,7 @@ template<PixelFormat T> typename PixelType<T>::type *image::lock() | |||
| } | |||
| /* The lock2d() method */ | |||
| void *image::lock2d_helper(PixelFormat T) | |||
| void *old_image::lock2d_helper(PixelFormat T) | |||
| { | |||
| set_format(T); | |||
| @@ -173,7 +173,7 @@ void *image::lock2d_helper(PixelFormat T) | |||
| } | |||
| template<typename T> | |||
| void image::unlock2d(array2d<T> const &array) | |||
| void old_image::unlock2d(old_array2d<T> const &array) | |||
| { | |||
| assert(has_key(m_data->m_pixels, (int)m_data->m_format)); | |||
| assert(array.data() == m_data->m_pixels[(int)m_data->m_format]->data()); | |||
| @@ -181,9 +181,9 @@ void image::unlock2d(array2d<T> const &array) | |||
| /* Explicit specialisations for the above templates */ | |||
| #define _T(T) \ | |||
| template PixelType<T>::type *image::lock<T>(); \ | |||
| template array2d<PixelType<T>::type> &image::lock2d<T>(); \ | |||
| template void image::unlock2d(array2d<PixelType<T>::type> const &array); | |||
| template PixelType<T>::type *old_image::lock<T>(); \ | |||
| template old_array2d<PixelType<T>::type> &old_image::lock2d<T>(); \ | |||
| template void old_image::unlock2d(old_array2d<PixelType<T>::type> const &array); | |||
| _T(PixelFormat::Y_8) | |||
| _T(PixelFormat::RGB_8) | |||
| _T(PixelFormat::RGBA_8) | |||
| @@ -193,14 +193,14 @@ _T(PixelFormat::RGBA_F32) | |||
| #undef _T | |||
| /* Special case for the "any" format: return the last active buffer */ | |||
| void *image::lock() | |||
| void *old_image::lock() | |||
| { | |||
| assert(m_data->m_format != PixelFormat::Unknown); | |||
| return m_data->m_pixels[(int)m_data->m_format]->data(); | |||
| } | |||
| void image::unlock(void const *pixels) | |||
| void old_image::unlock(void const *pixels) | |||
| { | |||
| assert(has_key(m_data->m_pixels, (int)m_data->m_format)); | |||
| assert(pixels == m_data->m_pixels[(int)m_data->m_format]->data()); | |||
| @@ -19,9 +19,9 @@ | |||
| namespace lol | |||
| { | |||
| array2d<float> image::kernel::bayer(ivec2 size) | |||
| old_array2d<float> old_image::kernel::bayer(ivec2 size) | |||
| { | |||
| array2d<float> ret(size); | |||
| old_array2d<float> ret(size); | |||
| int n = 1; | |||
| while (n < size.x || n < size.y) | |||
| @@ -48,9 +48,9 @@ array2d<float> image::kernel::bayer(ivec2 size) | |||
| return ret; | |||
| } | |||
| array2d<float> image::kernel::halftone(ivec2 size) | |||
| old_array2d<float> old_image::kernel::halftone(ivec2 size) | |||
| { | |||
| array2d<float> ret(size); | |||
| old_array2d<float> ret(size); | |||
| for (int y = 0; y < size.y; y++) | |||
| for (int x = 0; x < size.x; x++) | |||
| @@ -77,16 +77,16 @@ array2d<float> image::kernel::halftone(ivec2 size) | |||
| return normalize(ret); | |||
| } | |||
| array2d<float> image::kernel::blue_noise(ivec2 size, ivec2 gsize) | |||
| old_array2d<float> old_image::kernel::blue_noise(ivec2 size, ivec2 gsize) | |||
| { | |||
| float const epsilon = 1.f / (size.x * size.y + 1); | |||
| gsize = lol::min(size, gsize); | |||
| array2d<float> ret(size); | |||
| array2d<vec2> dots(size); | |||
| old_array2d<float> ret(size); | |||
| old_array2d<vec2> dots(size); | |||
| /* Create a small Gaussian kernel for filtering */ | |||
| array2d<float> gaussian(gsize); | |||
| old_array2d<float> gaussian(gsize); | |||
| for (int j = 0; j < gsize.y; ++j) | |||
| for (int i = 0; i < gsize.x; ++i) | |||
| { | |||
| @@ -182,7 +182,7 @@ static int cmpdot(const void *p1, const void *p2) | |||
| return ((Dot const *)p1)->val > ((Dot const *)p2)->val; | |||
| } | |||
| array2d<float> image::kernel::normalize(array2d<float> const &kernel) | |||
| old_array2d<float> old_image::kernel::normalize(old_array2d<float> const &kernel) | |||
| { | |||
| ivec2 size = kernel.sizes(); | |||
| @@ -199,7 +199,7 @@ array2d<float> image::kernel::normalize(array2d<float> const &kernel) | |||
| // FIXME: get rid of qsort and use proper C++ algorithms | |||
| std::qsort(tmp.data(), size.x * size.y, sizeof(Dot), cmpdot); | |||
| array2d<float> dst(size); | |||
| old_array2d<float> dst(size); | |||
| float const epsilon = 1.f / (size.x * size.y + 1); | |||
| for (int n = 0; n < size.x * size.y; n++) | |||
| @@ -212,7 +212,7 @@ array2d<float> image::kernel::normalize(array2d<float> const &kernel) | |||
| return dst; | |||
| } | |||
| array2d<float> image::kernel::ediff(EdiffAlgorithm algorithm) | |||
| old_array2d<float> old_image::kernel::ediff(EdiffAlgorithm algorithm) | |||
| { | |||
| switch (algorithm) | |||
| { | |||
| @@ -273,9 +273,9 @@ array2d<float> image::kernel::ediff(EdiffAlgorithm algorithm) | |||
| * there is little chance that any value below 0.2 will be useful. */ | |||
| #define BLUR_EPSILON 0.2f | |||
| array2d<float> image::kernel::gaussian(vec2 radius, float angle, vec2 delta) | |||
| old_array2d<float> old_image::kernel::gaussian(vec2 radius, float angle, vec2 delta) | |||
| { | |||
| array2d<float> kernel; | |||
| old_array2d<float> kernel; | |||
| if (radius.x < BLUR_EPSILON) | |||
| radius.x = BLUR_EPSILON; | |||
| @@ -106,7 +106,7 @@ bool movie::open_file(std::string const &filename) | |||
| #endif | |||
| } | |||
| bool movie::push_image(image &im) | |||
| bool movie::push_image(old_image &im) | |||
| { | |||
| #if LOL_USE_FFMPEG | |||
| // Make sure the encoder does not hold a reference on our | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2004—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -19,7 +19,7 @@ | |||
| namespace lol | |||
| { | |||
| bool image::RenderRandom(ivec2 size) | |||
| bool old_image::RenderRandom(ivec2 size) | |||
| { | |||
| resize(size); | |||
| vec4 *pixels = lock<PixelFormat::RGBA_F32>(); | |||
| @@ -63,7 +63,7 @@ static u8vec4 f32tou8(vec4 pixel) | |||
| * Pixel-level image manipulation | |||
| */ | |||
| PixelFormat image::format() const | |||
| PixelFormat old_image::format() const | |||
| { | |||
| return m_data->m_format; | |||
| } | |||
| @@ -84,7 +84,7 @@ PixelFormat image::format() const | |||
| * x lossless conversion (u8 to float) | |||
| * # lossy conversion (dithering and/or convert color→gray) | |||
| */ | |||
| void image::set_format(PixelFormat fmt) | |||
| void old_image::set_format(PixelFormat fmt) | |||
| { | |||
| PixelFormat old_fmt = m_data->m_format; | |||
| @@ -350,7 +350,7 @@ void image::set_format(PixelFormat fmt) | |||
| } | |||
| else | |||
| { | |||
| msg::error("Unable to find image conversion from %d to %d", | |||
| msg::error("Unable to find old_image conversion from %d to %d", | |||
| (int)old_fmt, (int)fmt); | |||
| } | |||
| } | |||
| @@ -21,10 +21,10 @@ | |||
| namespace lol | |||
| { | |||
| static image ResizeBicubic(image &src, ivec2 size); | |||
| static image ResizeBresenham(image &src, ivec2 size); | |||
| static old_image ResizeBicubic(old_image &src, ivec2 size); | |||
| static old_image ResizeBresenham(old_image &src, ivec2 size); | |||
| image image::Resize(ivec2 size, ResampleAlgorithm algorithm) | |||
| old_image old_image::Resize(ivec2 size, ResampleAlgorithm algorithm) | |||
| { | |||
| switch (algorithm) | |||
| { | |||
| @@ -36,9 +36,9 @@ image image::Resize(ivec2 size, ResampleAlgorithm algorithm) | |||
| } | |||
| } | |||
| static image ResizeBicubic(image &src, ivec2 size) | |||
| static old_image ResizeBicubic(old_image &src, ivec2 size) | |||
| { | |||
| image dst(size); | |||
| old_image dst(size); | |||
| ivec2 const oldsize = src.size(); | |||
| vec4 const *srcp = src.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -138,9 +138,9 @@ static image ResizeBicubic(image &src, ivec2 size) | |||
| /* FIXME: the algorithm does not handle alpha components properly. Resulting | |||
| * alpha should be the mean alpha value of the neightbouring pixels, but | |||
| * the colour components should be weighted with the alpha value. */ | |||
| static image ResizeBresenham(image &src, ivec2 size) | |||
| static old_image ResizeBresenham(old_image &src, ivec2 size) | |||
| { | |||
| image dst(size); | |||
| old_image dst(size); | |||
| ivec2 const oldsize = src.size(); | |||
| float const invswsh = 1.0f / (oldsize.x * oldsize.y); | |||
| @@ -38,7 +38,7 @@ namespace lol | |||
| #define REGISTER_IMAGE_CODEC(name) \ | |||
| extern ResourceCodec *Register##name(); \ | |||
| { \ | |||
| /* Insert image codecs in a sorted list */ \ | |||
| /* Insert old_image codecs in a sorted list */ \ | |||
| ResourceCodec *codec = Register##name(); \ | |||
| size_t i = 0, prio = codec->m_priority; \ | |||
| for ( ; i < codeclist.size(); ++i) \ | |||
| @@ -56,7 +56,7 @@ static bool RegisterAllCodecs(std::vector<ResourceCodec *> &codeclist) | |||
| } | |||
| /* | |||
| * Our static image loader | |||
| * Our static old_image loader | |||
| */ | |||
| static class StaticResourceLoader | |||
| @@ -87,14 +87,14 @@ ResourceCodecData* ResourceLoader::Load(std::string const &path) | |||
| auto data = codec->Load(path); | |||
| if (data != nullptr) | |||
| { | |||
| msg::debug("image::load: codec %s succesfully loaded %s.\n", | |||
| msg::debug("old_image::load: codec %s succesfully loaded %s.\n", | |||
| codec->GetName().c_str(), path.c_str()); | |||
| return data; | |||
| } | |||
| } | |||
| //Log error, because we shouldn't be here | |||
| msg::error("image::load: last codec %s, error loading resource %s.\n", | |||
| msg::error("old_image::load: last codec %s, error loading resource %s.\n", | |||
| last_codec->GetName().c_str(), path.c_str()); | |||
| return nullptr; | |||
| } | |||
| @@ -107,14 +107,14 @@ bool ResourceLoader::Save(std::string const &path, ResourceCodecData* data) | |||
| last_codec = codec; | |||
| if (codec->Save(path, data)) | |||
| { | |||
| msg::debug("image::save: codec %s succesfully saved %s.\n", | |||
| msg::debug("old_image::save: codec %s succesfully saved %s.\n", | |||
| codec->GetName().c_str(), path.c_str()); | |||
| return true; | |||
| } | |||
| } | |||
| //Log error, because we shouldn't be here | |||
| msg::error("image::save: last codec %s, error saving resource %s.\n", | |||
| msg::error("old_image::save: last codec %s, error saving resource %s.\n", | |||
| last_codec->GetName().c_str(), path.c_str()); | |||
| return false; | |||
| } | |||
| @@ -1,11 +1,13 @@ | |||
| // | |||
| // Lol Engine | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| @@ -103,7 +105,7 @@ public: | |||
| TextureUniform GetTextureUniform() const; | |||
| ivec2 GetSize() const; | |||
| class image GetImage() const; | |||
| class old_image GetImage() const; | |||
| void Bind(); | |||
| void Unbind(); | |||
| @@ -13,8 +13,8 @@ | |||
| #pragma once | |||
| // | |||
| // The image class | |||
| // --------------- | |||
| // The old image class | |||
| // ------------------- | |||
| // | |||
| #include <../legacy/lol/math/arraynd.h> | |||
| @@ -60,24 +60,24 @@ enum class EdiffAlgorithm : uint8_t | |||
| Lite, | |||
| }; | |||
| // image ----------------------------------------------------------------------- | |||
| class image | |||
| // old_image ----------------------------------------------------------------------- | |||
| class old_image | |||
| { | |||
| public: | |||
| image(); | |||
| image(ivec2 size); | |||
| old_image(); | |||
| old_image(ivec2 size); | |||
| /* XXX: use of this ctor should be discouraged, as it will not | |||
| * return information about a possible error. */ | |||
| image(std::string const &path); | |||
| old_image(std::string const &path); | |||
| /* Rule of three */ | |||
| image(image const &other); | |||
| image & operator =(image other); | |||
| ~image(); | |||
| old_image(old_image const &other); | |||
| old_image & operator =(old_image other); | |||
| ~old_image(); | |||
| void DummyFill(); | |||
| void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt); | |||
| void Copy(image const &other); | |||
| void Copy(old_image const &other); | |||
| bool load(std::string const &path); | |||
| bool save(std::string const &path); | |||
| @@ -99,28 +99,28 @@ public: | |||
| /* Lock 2D arrays of pixels for writing */ | |||
| template<PixelFormat T> | |||
| [[nodiscard]] inline array2d<typename PixelType<T>::type> &lock2d() | |||
| [[nodiscard]] inline old_array2d<typename PixelType<T>::type> &lock2d() | |||
| { | |||
| /* Hack: this indirection is needed because of a Visual Studio ICE */ | |||
| return *(array2d<typename PixelType<T>::type> *)lock2d_helper(T); | |||
| return *(old_array2d<typename PixelType<T>::type> *)lock2d_helper(T); | |||
| } | |||
| template<typename T> | |||
| void unlock2d(array2d<T> const &); | |||
| void unlock2d(old_array2d<T> const &); | |||
| /* Image processing kernels */ | |||
| struct kernel | |||
| { | |||
| kernel() = delete; | |||
| static array2d<float> normalize(array2d<float> const &kernel); | |||
| static old_array2d<float> normalize(old_array2d<float> const &kernel); | |||
| static array2d<float> bayer(ivec2 size); | |||
| static array2d<float> halftone(ivec2 size); | |||
| static array2d<float> blue_noise(ivec2 size, | |||
| static old_array2d<float> bayer(ivec2 size); | |||
| static old_array2d<float> halftone(ivec2 size); | |||
| static old_array2d<float> blue_noise(ivec2 size, | |||
| ivec2 gsize = ivec2(7, 7)); | |||
| static array2d<float> ediff(EdiffAlgorithm algorithm); | |||
| static array2d<float> gaussian(vec2 radius, | |||
| static old_array2d<float> ediff(EdiffAlgorithm algorithm); | |||
| static old_array2d<float> gaussian(vec2 radius, | |||
| float angle = 0.f, | |||
| vec2 delta = vec2(0.f, 0.f)); | |||
| }; | |||
| @@ -129,46 +129,46 @@ public: | |||
| bool RenderRandom(ivec2 size); | |||
| /* Resize and crop */ | |||
| image Resize(ivec2 size, ResampleAlgorithm algorithm); | |||
| image Crop(ibox2 box) const; | |||
| old_image Resize(ivec2 size, ResampleAlgorithm algorithm); | |||
| old_image Crop(ibox2 box) const; | |||
| /* Image processing */ | |||
| image AutoContrast() const; | |||
| image Brightness(float val) const; | |||
| image Contrast(float val) const; | |||
| image Convolution(array2d<float> const &kernel); | |||
| image Dilate(); | |||
| image Erode(); | |||
| image Invert() const; | |||
| image Median(ivec2 radii) const; | |||
| image Median(array2d<float> const &kernel) const; | |||
| image Sharpen(array2d<float> const &kernel); | |||
| image Threshold(float val) const; | |||
| image Threshold(vec3 val) const; | |||
| image RGBToYUV() const; | |||
| image YUVToRGB() const; | |||
| old_image AutoContrast() const; | |||
| old_image Brightness(float val) const; | |||
| old_image Contrast(float val) const; | |||
| old_image Convolution(old_array2d<float> const &kernel); | |||
| old_image Dilate(); | |||
| old_image Erode(); | |||
| old_image Invert() const; | |||
| old_image Median(ivec2 radii) const; | |||
| old_image Median(old_array2d<float> const &kernel) const; | |||
| old_image Sharpen(old_array2d<float> const &kernel); | |||
| old_image Threshold(float val) const; | |||
| old_image Threshold(vec3 val) const; | |||
| old_image RGBToYUV() const; | |||
| old_image YUVToRGB() const; | |||
| /* Dithering */ | |||
| image dither_random() const; | |||
| image dither_ediff(array2d<float> const &kernel, | |||
| ScanMode scan = ScanMode::Raster) const; | |||
| image dither_ostromoukhov(ScanMode scan = ScanMode::Raster) const; | |||
| image dither_ordered(array2d<float> const &kernel) const; | |||
| image dither_halftone(float radius, float angle) const; | |||
| image dither_dbs() const; | |||
| old_image dither_random() const; | |||
| old_image dither_ediff(old_array2d<float> const &kernel, | |||
| ScanMode scan = ScanMode::Raster) const; | |||
| old_image dither_ostromoukhov(ScanMode scan = ScanMode::Raster) const; | |||
| old_image dither_ordered(old_array2d<float> const &kernel) const; | |||
| old_image dither_halftone(float radius, float angle) const; | |||
| old_image dither_dbs() const; | |||
| /* Combine images */ | |||
| static image Merge(image &src1, image &src2, float alpha); | |||
| static image Mean(image &src1, image &src2); | |||
| static image Min(image &src1, image &src2); | |||
| static image Max(image &src1, image &src2); | |||
| static image Overlay(image &src1, image &src2); | |||
| static image Screen(image &src1, image &src2); | |||
| static image Multiply(image &src1, image &src2); | |||
| static image Divide(image &src1, image &src2); | |||
| static image Add(image &src1, image &src2); | |||
| static image Sub(image &src1, image &src2); | |||
| static image Difference(image &src1, image &src2); | |||
| static old_image Merge(old_image &src1, old_image &src2, float alpha); | |||
| static old_image Mean(old_image &src1, old_image &src2); | |||
| static old_image Min(old_image &src1, old_image &src2); | |||
| static old_image Max(old_image &src1, old_image &src2); | |||
| static old_image Overlay(old_image &src1, old_image &src2); | |||
| static old_image Screen(old_image &src1, old_image &src2); | |||
| static old_image Multiply(old_image &src1, old_image &src2); | |||
| static old_image Divide(old_image &src1, old_image &src2); | |||
| static old_image Add(old_image &src1, old_image &src2); | |||
| static old_image Sub(old_image &src1, old_image &src2); | |||
| static old_image Difference(old_image &src1, old_image &src2); | |||
| private: | |||
| void *lock2d_helper(PixelFormat T); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -34,7 +34,7 @@ public: | |||
| movie(ivec2 size); | |||
| bool open_file(std::string const &filename); | |||
| bool push_image(image &im); | |||
| bool push_image(old_image &im); | |||
| void close(); | |||
| private: | |||
| @@ -40,7 +40,7 @@ namespace lol | |||
| class ResourceImageData : public ResourceCodecData | |||
| { | |||
| public: | |||
| ResourceImageData(image* img) | |||
| ResourceImageData(old_image* img) | |||
| { | |||
| m_image = img; | |||
| } | |||
| @@ -51,14 +51,14 @@ namespace lol | |||
| delete m_image; | |||
| } | |||
| image* m_image = nullptr; | |||
| old_image* m_image = nullptr; | |||
| }; | |||
| //ResourceImageData ----------------------------------------------------------- | |||
| class ResourceTilesetData : public ResourceImageData | |||
| { | |||
| public: | |||
| ResourceTilesetData(image* img) | |||
| ResourceTilesetData(old_image* img) | |||
| : ResourceImageData(img) | |||
| { } | |||
| @@ -544,7 +544,7 @@ void Scene::post_render(float) | |||
| rc.clear_depth(1.f); | |||
| m_renderer->clear(ClearMask::Color | ClearMask::Depth); | |||
| /* Blit final image to screen */ | |||
| /* Blit final old_image to screen */ | |||
| m_pp.blit_shader->SetUniform(m_pp.m_buffer_uni[0][0], m_renderbuffer[3]->GetTextureUniform(), 3); | |||
| m_pp.quad_vdecl->Bind(); | |||
| m_pp.quad_vdecl->SetStream(m_pp.quad_vbo, m_pp.blit_pos_attr); | |||
| @@ -32,7 +32,7 @@ test_base_SOURCES = test-common.cpp \ | |||
| test_base_DEPENDENCIES = @LOL_DEPS@ | |||
| test_math_SOURCES = test-common.cpp \ | |||
| math/array2d.cpp math/array3d.cpp math/arraynd.cpp math/box.cpp \ | |||
| math/array2d.cpp math/array3d.cpp math/narray.cpp math/box.cpp \ | |||
| math/cmplx.cpp math/half.cpp math/matrix.cpp math/quat.cpp \ | |||
| math/rand.cpp math/real.cpp math/rotation.cpp math/trig.cpp \ | |||
| math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \ | |||
| @@ -25,7 +25,7 @@ lolunit_declare_fixture(image_test) | |||
| { | |||
| lolunit_declare_test(open_image) | |||
| { | |||
| image img("data/gradient.png"); | |||
| old_image img("data/gradient.png"); | |||
| ivec2 isize = img.size(); | |||
| lolunit_assert_equal(isize.x, 256); | |||
| @@ -15,7 +15,7 @@ | |||
| #endif | |||
| #include <lol/unit_test> | |||
| #include <../legacy/lol/math/arraynd.h> | |||
| #include <lol/narray> // lol::array2d | |||
| namespace lol | |||
| { | |||
| @@ -24,26 +24,46 @@ lolunit_declare_fixture(array2d_test) | |||
| { | |||
| lolunit_declare_test(array2d_create) | |||
| { | |||
| array2d<int> a(ivec2(10, 10)); | |||
| array2d<int> a(10, 10); | |||
| a[0][0] = 2; | |||
| a[9][0] = 4; | |||
| a[0][9] = 6; | |||
| a[9][9] = 8; | |||
| a(0, 0) = 2; | |||
| a(9, 0) = 4; | |||
| a(0, 9) = 6; | |||
| a(9, 9) = 8; | |||
| lolunit_assert_equal(a[0][0], 2); | |||
| lolunit_assert_equal(a[9][0], 4); | |||
| lolunit_assert_equal(a[0][9], 6); | |||
| lolunit_assert_equal(a[9][9], 8); | |||
| lolunit_assert_equal(a(0, 0), 2); | |||
| lolunit_assert_equal(a(9, 0), 4); | |||
| lolunit_assert_equal(a(0, 9), 6); | |||
| lolunit_assert_equal(a(9, 9), 8); | |||
| array2d<int> const &b = a; | |||
| lolunit_assert_equal(b[0][0], 2); | |||
| lolunit_assert_equal(b[9][0], 4); | |||
| lolunit_assert_equal(b[0][9], 6); | |||
| lolunit_assert_equal(b[9][9], 8); | |||
| lolunit_assert_equal(b(0, 0), 2); | |||
| lolunit_assert_equal(b(9, 0), 4); | |||
| lolunit_assert_equal(b(0, 9), 6); | |||
| lolunit_assert_equal(b(9, 9), 8); | |||
| } | |||
| lolunit_declare_test(array2d_layout) | |||
| { | |||
| array2d<int> a(3, 2); | |||
| // Check that the first element points to the array data | |||
| lolunit_assert_equal(&a(0, 0), a.data()); | |||
| // Check that the layout is row-major | |||
| for (int i = 0; i < 6; ++i) | |||
| a.data()[i] = i; | |||
| lolunit_assert_equal(a(0, 0), 0); | |||
| lolunit_assert_equal(a(1, 0), 1); | |||
| lolunit_assert_equal(a(2, 0), 2); | |||
| lolunit_assert_equal(a(0, 1), 3); | |||
| lolunit_assert_equal(a(1, 1), 4); | |||
| lolunit_assert_equal(a(2, 1), 5); | |||
| } | |||
| #if 0 | |||
| lolunit_declare_test(array2d_init) | |||
| { | |||
| array2d<int> a = { { 1, 2, 3, 4 }, | |||
| @@ -53,22 +73,23 @@ lolunit_declare_fixture(array2d_test) | |||
| lolunit_assert_equal(a.sizes().x, 4); | |||
| lolunit_assert_equal(a.sizes().y, 3); | |||
| lolunit_assert_equal(a[0][0], 1); | |||
| lolunit_assert_equal(a[1][0], 2); | |||
| lolunit_assert_equal(a[2][0], 3); | |||
| lolunit_assert_equal(a[3][0], 4); | |||
| lolunit_assert_equal(a(0, 0), 1); | |||
| lolunit_assert_equal(a(1, 0), 2); | |||
| lolunit_assert_equal(a(2, 0), 3); | |||
| lolunit_assert_equal(a(3, 0), 4); | |||
| lolunit_assert_equal(a[0][1], 5); | |||
| lolunit_assert_equal(a[1][1], 6); | |||
| lolunit_assert_equal(a[2][1], 7); | |||
| lolunit_assert_equal(a[3][1], 8); | |||
| lolunit_assert_equal(a(0, 1), 5); | |||
| lolunit_assert_equal(a(1, 1), 6); | |||
| lolunit_assert_equal(a(2, 1), 7); | |||
| lolunit_assert_equal(a(3, 1), 8); | |||
| lolunit_assert_equal(a[0][2], 9); | |||
| lolunit_assert_equal(a[1][2], 8); | |||
| lolunit_assert_equal(a[2][2], 7); | |||
| lolunit_assert_equal(a[3][2], 6); | |||
| lolunit_assert_equal(a(0, 2), 9); | |||
| lolunit_assert_equal(a(1, 2), 8); | |||
| lolunit_assert_equal(a(2, 2), 7); | |||
| lolunit_assert_equal(a(3, 2), 6); | |||
| } | |||
| #endif | |||
| }; | |||
| } /* namespace lol */ | |||
| } // namespace lol | |||
| @@ -15,7 +15,7 @@ | |||
| #endif | |||
| #include <lol/unit_test> | |||
| #include <../legacy/lol/math/arraynd.h> | |||
| #include <lol/narray> // lol::array3d | |||
| namespace lol | |||
| { | |||
| @@ -24,26 +24,27 @@ lolunit_declare_fixture(array3d_test) | |||
| { | |||
| lolunit_declare_test(array3d_create) | |||
| { | |||
| array3d<int> a(ivec3(10, 10, 10)); | |||
| array3d<int> a(10, 10, 10); | |||
| a[0][0][0] = 2; | |||
| a[9][0][0] = 4; | |||
| a[0][9][9] = 6; | |||
| a[9][9][9] = 8; | |||
| a(0, 0, 0) = 2; | |||
| a(9, 0, 0) = 4; | |||
| a(0, 9, 9) = 6; | |||
| a(9, 9, 9) = 8; | |||
| lolunit_assert_equal(a[0][0][0], 2); | |||
| lolunit_assert_equal(a[9][0][0], 4); | |||
| lolunit_assert_equal(a[0][9][9], 6); | |||
| lolunit_assert_equal(a[9][9][9], 8); | |||
| lolunit_assert_equal(a(0, 0, 0), 2); | |||
| lolunit_assert_equal(a(9, 0, 0), 4); | |||
| lolunit_assert_equal(a(0, 9, 9), 6); | |||
| lolunit_assert_equal(a(9, 9, 9), 8); | |||
| array3d<int> const &b = a; | |||
| lolunit_assert_equal(b[0][0][0], 2); | |||
| lolunit_assert_equal(b[9][0][0], 4); | |||
| lolunit_assert_equal(b[0][9][9], 6); | |||
| lolunit_assert_equal(b[9][9][9], 8); | |||
| lolunit_assert_equal(b(0, 0, 0), 2); | |||
| lolunit_assert_equal(b(9, 0, 0), 4); | |||
| lolunit_assert_equal(b(0, 9, 9), 6); | |||
| lolunit_assert_equal(b(9, 9, 9), 8); | |||
| } | |||
| #if 0 | |||
| lolunit_declare_test(array3d_init) | |||
| { | |||
| array3d<int> a = { { { 1, 2, 3, 4 }, | |||
| @@ -57,37 +58,38 @@ lolunit_declare_fixture(array3d_test) | |||
| lolunit_assert_equal(a.sizes().y, 3); | |||
| lolunit_assert_equal(a.sizes().z, 2); | |||
| lolunit_assert_equal(a[0][0][0], 1); | |||
| lolunit_assert_equal(a[1][0][0], 2); | |||
| lolunit_assert_equal(a[2][0][0], 3); | |||
| lolunit_assert_equal(a[3][0][0], 4); | |||
| lolunit_assert_equal(a[0][1][0], 5); | |||
| lolunit_assert_equal(a[1][1][0], 6); | |||
| lolunit_assert_equal(a[2][1][0], 7); | |||
| lolunit_assert_equal(a[3][1][0], 8); | |||
| lolunit_assert_equal(a[0][2][0], 9); | |||
| lolunit_assert_equal(a[1][2][0], 8); | |||
| lolunit_assert_equal(a[2][2][0], 7); | |||
| lolunit_assert_equal(a[3][2][0], 6); | |||
| lolunit_assert_equal(a[0][0][1], -1); | |||
| lolunit_assert_equal(a[1][0][1], -2); | |||
| lolunit_assert_equal(a[2][0][1], -3); | |||
| lolunit_assert_equal(a[3][0][1], -4); | |||
| lolunit_assert_equal(a[0][1][1], -5); | |||
| lolunit_assert_equal(a[1][1][1], -6); | |||
| lolunit_assert_equal(a[2][1][1], -7); | |||
| lolunit_assert_equal(a[3][1][1], -8); | |||
| lolunit_assert_equal(a[0][2][1], -9); | |||
| lolunit_assert_equal(a[1][2][1], -8); | |||
| lolunit_assert_equal(a[2][2][1], -7); | |||
| lolunit_assert_equal(a[3][2][1], -6); | |||
| lolunit_assert_equal(a(0, 0, 0), 1); | |||
| lolunit_assert_equal(a(1, 0, 0), 2); | |||
| lolunit_assert_equal(a(2, 0, 0), 3); | |||
| lolunit_assert_equal(a(3, 0, 0), 4); | |||
| lolunit_assert_equal(a(0, 1, 0), 5); | |||
| lolunit_assert_equal(a(1, 1, 0), 6); | |||
| lolunit_assert_equal(a(2, 1, 0), 7); | |||
| lolunit_assert_equal(a(3, 1, 0), 8); | |||
| lolunit_assert_equal(a(0, 2, 0), 9); | |||
| lolunit_assert_equal(a(1, 2, 0), 8); | |||
| lolunit_assert_equal(a(2, 2, 0), 7); | |||
| lolunit_assert_equal(a(3, 2, 0), 6); | |||
| lolunit_assert_equal(a(0, 0, 1), -1); | |||
| lolunit_assert_equal(a(1, 0, 1), -2); | |||
| lolunit_assert_equal(a(2, 0, 1), -3); | |||
| lolunit_assert_equal(a(3, 0, 1), -4); | |||
| lolunit_assert_equal(a(0, 1, 1), -5); | |||
| lolunit_assert_equal(a(1, 1, 1), -6); | |||
| lolunit_assert_equal(a(2, 1, 1), -7); | |||
| lolunit_assert_equal(a(3, 1, 1), -8); | |||
| lolunit_assert_equal(a(0, 2, 1), -9); | |||
| lolunit_assert_equal(a(1, 2, 1), -8); | |||
| lolunit_assert_equal(a(2, 2, 1), -7); | |||
| lolunit_assert_equal(a(3, 2, 1), -6); | |||
| } | |||
| #endif | |||
| }; | |||
| } /* namespace lol */ | |||
| } // namespace lol | |||
| @@ -1,119 +0,0 @@ | |||
| // | |||
| // Lol Engine — Unit tests | |||
| // | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #if HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <lol/unit_test> | |||
| #include <../legacy/lol/math/arraynd.h> | |||
| namespace lol | |||
| { | |||
| lolunit_declare_fixture(arraynd_test) | |||
| { | |||
| lolunit_declare_test(array2d_accessors) | |||
| { | |||
| arraynd<2, int> a; | |||
| a.resize(vec_t<int, 2>(2, 2)); | |||
| /* Non-const accessors */ | |||
| a[0][0] = 1; | |||
| a[0][1] = 2; | |||
| a[1][0] = 3; | |||
| a[1][1] = 4; | |||
| lolunit_assert_equal(a[0][0], 1); | |||
| lolunit_assert_equal(a[0][1], 2); | |||
| lolunit_assert_equal(a[1][0], 3); | |||
| lolunit_assert_equal(a[1][1], 4); | |||
| /* Const accessors */ | |||
| arraynd<2, int> const &b = a; | |||
| lolunit_assert_equal(b[0][0], 1); | |||
| lolunit_assert_equal(b[0][1], 2); | |||
| lolunit_assert_equal(b[1][0], 3); | |||
| lolunit_assert_equal(b[1][1], 4); | |||
| } | |||
| lolunit_declare_test(arraynd_create) | |||
| { | |||
| arraynd<10, int> a; | |||
| arraynd<20, float> b; | |||
| arraynd<30, uint8_t> c; | |||
| arraynd<40, double> d; | |||
| arraynd<3, int> e = { { {1, 2}, {3, 4} }, { {5, 6}, {7, 8} } }; | |||
| lolunit_assert_equal(e.sizes()[0], 2); | |||
| lolunit_assert_equal(e.sizes()[1], 2); | |||
| lolunit_assert_equal(e.sizes()[2], 2); | |||
| lolunit_assert_equal(e[0][0][0], 1); | |||
| lolunit_assert_equal(e[1][0][0], 2); | |||
| lolunit_assert_equal(e[0][1][0], 3); | |||
| lolunit_assert_equal(e[1][1][0], 4); | |||
| lolunit_assert_equal(e[0][0][1], 5); | |||
| lolunit_assert_equal(e[1][0][1], 6); | |||
| lolunit_assert_equal(e[0][1][1], 7); | |||
| lolunit_assert_equal(e[1][1][1], 8); | |||
| arraynd<3, int> f = { { {1, 2, 3, 4}, {5, 6, 7} }, { {8, 9}, {10} } }; | |||
| lolunit_assert_equal(f.sizes()[0], 4); | |||
| lolunit_assert_equal(f.sizes()[1], 2); | |||
| lolunit_assert_equal(f.sizes()[2], 2); | |||
| lolunit_assert_equal(f[0][0][0], 1); | |||
| lolunit_assert_equal(f[1][0][0], 2); | |||
| lolunit_assert_equal(f[2][0][0], 3); | |||
| lolunit_assert_equal(f[3][0][0], 4); | |||
| lolunit_assert_equal(f[0][1][0], 5); | |||
| lolunit_assert_equal(f[1][1][0], 6); | |||
| lolunit_assert_equal(f[2][1][0], 7); | |||
| lolunit_assert_equal(f[3][1][0], 0); | |||
| lolunit_assert_equal(f[0][0][1], 8); | |||
| lolunit_assert_equal(f[1][0][1], 9); | |||
| lolunit_assert_equal(f[2][0][1], 0); | |||
| lolunit_assert_equal(f[3][0][1], 0); | |||
| lolunit_assert_equal(f[0][1][1], 10); | |||
| lolunit_assert_equal(f[1][1][1], 0); | |||
| lolunit_assert_equal(f[2][1][1], 0); | |||
| lolunit_assert_equal(f[3][1][1], 0); | |||
| } | |||
| lolunit_declare_test(arraynd_init) | |||
| { | |||
| int const NDIM = 8; | |||
| vec_t<int, NDIM> size; | |||
| for (int i = 0; i < NDIM; ++i) | |||
| size[i] = 5; | |||
| arraynd<NDIM, uint8_t> a(size); | |||
| memset(a.data(), 0, a.bytes()); | |||
| lolunit_assert_equal(a[2][3][2][0][1][4][0][1], 0x00); | |||
| vec_t<int, NDIM> v = { 2, 3, 2, 0, 1, 4, 0, 1 }; | |||
| lolunit_assert_equal(a[v], 0x00); | |||
| a[2][3][2][0][1][4][0][1] = 0xcd; | |||
| lolunit_assert_equal(a[2][3][2][0][1][4][0][1], 0xcd); | |||
| lolunit_assert_equal(a[v], 0xcd); | |||
| arraynd<NDIM, uint8_t> const &b = a; | |||
| lolunit_assert_equal(b[2][3][2][0][1][4][0][1], 0xcd); | |||
| lolunit_assert_equal(b[v], 0xcd); | |||
| } | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -0,0 +1,120 @@ | |||
| // | |||
| // Lol Engine — Unit tests | |||
| // | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #if HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <lol/unit_test> | |||
| #include <lol/narray> // lol::narray | |||
| #include <cstring> // memset | |||
| namespace lol | |||
| { | |||
| lolunit_declare_fixture(narray_test) | |||
| { | |||
| lolunit_declare_test(narray_2d_accessors) | |||
| { | |||
| narray<int, 2> a; | |||
| a.resize(vec_t<int, 2>(2, 2)); | |||
| // Non-const accessors | |||
| a(0, 0) = 1; | |||
| a(0, 1) = 2; | |||
| a(1, 0) = 3; | |||
| a(1, 1) = 4; | |||
| lolunit_assert_equal(a(0, 0), 1); | |||
| lolunit_assert_equal(a(0, 1), 2); | |||
| lolunit_assert_equal(a(1, 0), 3); | |||
| lolunit_assert_equal(a(1, 1), 4); | |||
| // Const accessors | |||
| narray<int, 2> const &b = a; | |||
| lolunit_assert_equal(b(0, 0), 1); | |||
| lolunit_assert_equal(b(0, 1), 2); | |||
| lolunit_assert_equal(b(1, 0), 3); | |||
| lolunit_assert_equal(b(1, 1), 4); | |||
| } | |||
| lolunit_declare_test(narray_create) | |||
| { | |||
| narray<int, 10> a; | |||
| narray<float, 20> b; | |||
| narray<uint8_t, 30> c; | |||
| narray<double, 30> d; | |||
| #if 0 | |||
| narray<int, 3> e = { { {1, 2}, {3, 4} }, { {5, 6}, {7, 8} } }; | |||
| lolunit_assert_equal(e.sizes()(0), 2); | |||
| lolunit_assert_equal(e.sizes()(1), 2); | |||
| lolunit_assert_equal(e.sizes()(2), 2); | |||
| lolunit_assert_equal(e(0, 0, 0), 1); | |||
| lolunit_assert_equal(e(1, 0, 0), 2); | |||
| lolunit_assert_equal(e(0, 1, 0), 3); | |||
| lolunit_assert_equal(e(1, 1, 0), 4); | |||
| lolunit_assert_equal(e(0, 0, 1), 5); | |||
| lolunit_assert_equal(e(1, 0, 1), 6); | |||
| lolunit_assert_equal(e(0, 1, 1), 7); | |||
| lolunit_assert_equal(e(1, 1, 1), 8); | |||
| narray<int, 3> f = { { {1, 2, 3, 4}, {5, 6, 7} }, { {8, 9}, {10} } }; | |||
| lolunit_assert_equal(f.sizes()(0), 4); | |||
| lolunit_assert_equal(f.sizes()(1), 2); | |||
| lolunit_assert_equal(f.sizes()(2), 2); | |||
| lolunit_assert_equal(f(0, 0, 0), 1); | |||
| lolunit_assert_equal(f(1, 0, 0), 2); | |||
| lolunit_assert_equal(f(2, 0, 0), 3); | |||
| lolunit_assert_equal(f(3, 0, 0), 4); | |||
| lolunit_assert_equal(f(0, 1, 0), 5); | |||
| lolunit_assert_equal(f(1, 1, 0), 6); | |||
| lolunit_assert_equal(f(2, 1, 0), 7); | |||
| lolunit_assert_equal(f(3, 1, 0), 0); | |||
| lolunit_assert_equal(f(0, 0, 1), 8); | |||
| lolunit_assert_equal(f(1, 0, 1), 9); | |||
| lolunit_assert_equal(f(2, 0, 1), 0); | |||
| lolunit_assert_equal(f(3, 0, 1), 0); | |||
| lolunit_assert_equal(f(0, 1, 1), 10); | |||
| lolunit_assert_equal(f(1, 1, 1), 0); | |||
| lolunit_assert_equal(f(2, 1, 1), 0); | |||
| lolunit_assert_equal(f(3, 1, 1), 0); | |||
| #endif | |||
| } | |||
| lolunit_declare_test(narray_init) | |||
| { | |||
| int const NDIM = 8; | |||
| vec_t<int, NDIM> size(5); | |||
| narray<uint8_t, NDIM> a(size); | |||
| memset(a.data(), 0, a.bytes()); | |||
| lolunit_assert_equal(a(2, 3, 2, 0, 1, 4, 0, 1), 0x00); | |||
| vec_t<int, NDIM> v = { 2, 3, 2, 0, 1, 4, 0, 1 }; | |||
| lolunit_assert_equal(a(v), 0x00); | |||
| a(2, 3, 2, 0, 1, 4, 0, 1) = 0xcd; | |||
| lolunit_assert_equal(a(2, 3, 2, 0, 1, 4, 0, 1), 0xcd); | |||
| lolunit_assert_equal(a(v), 0xcd); | |||
| narray<uint8_t, NDIM> const &b = a; | |||
| lolunit_assert_equal(b(2, 3, 2, 0, 1, 4, 0, 1), 0xcd); | |||
| lolunit_assert_equal(b(v), 0xcd); | |||
| } | |||
| }; | |||
| } // namespace lol | |||
| @@ -42,12 +42,12 @@ | |||
| <ClCompile Include="test-common.cpp" /> | |||
| <ClCompile Include="math\array2d.cpp" /> | |||
| <ClCompile Include="math\array3d.cpp" /> | |||
| <ClCompile Include="math\arraynd.cpp" /> | |||
| <ClCompile Include="math\box.cpp" /> | |||
| <ClCompile Include="math\bigint.cpp" /> | |||
| <ClCompile Include="math\cmplx.cpp" /> | |||
| <ClCompile Include="math\half.cpp" /> | |||
| <ClCompile Include="math\matrix.cpp" /> | |||
| <ClCompile Include="math\narray.cpp" /> | |||
| <ClCompile Include="math\noise\simplex.cpp" /> | |||
| <ClCompile Include="math\numbers.cpp" /> | |||
| <ClCompile Include="math\polynomial.cpp" /> | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -34,7 +34,7 @@ public: | |||
| /* Pixels, then texture coordinates */ | |||
| ivec2 m_image_size, m_texture_size; | |||
| image *m_image = nullptr; | |||
| old_image *m_image = nullptr; | |||
| Texture *m_texture = nullptr; | |||
| }; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -46,7 +46,7 @@ TextureImage::TextureImage(std::string const &path) | |||
| Init(path); | |||
| } | |||
| TextureImage::TextureImage(std::string const &path, image* img) | |||
| TextureImage::TextureImage(std::string const &path, old_image* img) | |||
| : m_data(GetNewData()) | |||
| { | |||
| Init(path, img); | |||
| @@ -68,13 +68,13 @@ void TextureImage::Init(std::string const &path, ResourceCodecData* loaded_data) | |||
| auto image_data = dynamic_cast<ResourceImageData*>(loaded_data); | |||
| if (image_data != nullptr) | |||
| { | |||
| Init(path, new image(*image_data->m_image)); | |||
| Init(path, new old_image(*image_data->m_image)); | |||
| } | |||
| delete image_data; | |||
| } | |||
| void TextureImage::Init(std::string const &path, image* img) | |||
| void TextureImage::Init(std::string const &path, old_image* img) | |||
| { | |||
| m_data->m_name = "<textureimage> " + path; | |||
| @@ -149,7 +149,7 @@ std::string TextureImage::GetName() const | |||
| return m_data->m_name; | |||
| } | |||
| void TextureImage::UpdateTexture(image* img) | |||
| void TextureImage::UpdateTexture(old_image* img) | |||
| { | |||
| m_data->m_image = img; | |||
| m_data->m_image_size = m_data->m_image->size(); | |||
| @@ -167,12 +167,12 @@ Texture const * TextureImage::GetTexture() const | |||
| return m_data->m_texture; | |||
| } | |||
| image * TextureImage::GetImage() | |||
| old_image * TextureImage::GetImage() | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| image const * TextureImage::GetImage() const | |||
| old_image const * TextureImage::GetImage() const | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -41,13 +41,13 @@ protected: | |||
| public: | |||
| TextureImage(std::string const &path); | |||
| TextureImage(std::string const &path, image* img); | |||
| TextureImage(std::string const &path, old_image* img); | |||
| virtual ~TextureImage(); | |||
| protected: | |||
| void Init(std::string const &path); | |||
| virtual void Init(std::string const &path, ResourceCodecData* loaded_data); | |||
| virtual void Init(std::string const &path, image* img); | |||
| virtual void Init(std::string const &path, old_image* img); | |||
| protected: | |||
| virtual void tick_draw(float seconds, Scene &scene); | |||
| @@ -56,11 +56,11 @@ public: | |||
| /* Inherited from entity */ | |||
| virtual std::string GetName() const; | |||
| void UpdateTexture(image* img); | |||
| void UpdateTexture(old_image* img); | |||
| Texture * GetTexture(); | |||
| Texture const * GetTexture() const; | |||
| image * GetImage(); | |||
| image const * GetImage() const; | |||
| old_image * GetImage(); | |||
| old_image const * GetImage() const; | |||
| ivec2 GetImageSize() const; | |||
| ivec2 GetTextureSize() const; | |||
| void Bind(); | |||
| @@ -61,13 +61,13 @@ TileSet *TileSet::create(std::string const &path) | |||
| return ret ? ret : tileset_cache.set(path, new TileSet(path)); | |||
| } | |||
| TileSet *TileSet::create(std::string const &path, image* img) | |||
| TileSet *TileSet::create(std::string const &path, old_image* img) | |||
| { | |||
| auto ret = tileset_cache.get(path); | |||
| return ret ? ret : tileset_cache.set(path, new TileSet(path, img)); | |||
| } | |||
| TileSet *TileSet::create(std::string const &path, image* img, std::vector<ibox2>& tiles) | |||
| TileSet *TileSet::create(std::string const &path, old_image* img, std::vector<ibox2>& tiles) | |||
| { | |||
| auto ret = tileset_cache.get(path); | |||
| if (!ret) | |||
| @@ -108,7 +108,7 @@ TileSet *TileSet::create(std::string const &path, ivec2 size, ivec2 count) | |||
| return ret; | |||
| } | |||
| TileSet *TileSet::create(std::string const &path, image* img, ivec2 size, ivec2 count) | |||
| TileSet *TileSet::create(std::string const &path, old_image* img, ivec2 size, ivec2 count) | |||
| { | |||
| auto ret = tileset_cache.get(path); | |||
| if (!ret) | |||
| @@ -151,7 +151,7 @@ TileSet::TileSet(std::string const &path) | |||
| { | |||
| } | |||
| TileSet::TileSet(std::string const &path, image *img) | |||
| TileSet::TileSet(std::string const &path, old_image *img) | |||
| : TextureImage(path, img), | |||
| m_tileset_data(new TileSetData()), | |||
| m_palette(nullptr) | |||
| @@ -177,7 +177,7 @@ void TileSet::Init(std::string const &path, ResourceCodecData* loaded_data) | |||
| super::Init(path, loaded_data); | |||
| } | |||
| void TileSet::Init(std::string const &path, image* img) | |||
| void TileSet::Init(std::string const &path, old_image* img) | |||
| { | |||
| super::Init(path, img); | |||
| @@ -44,12 +44,12 @@ class TileSet : public TextureImage | |||
| public: | |||
| static TileSet *create(std::string const &path); | |||
| static TileSet *create(std::string const &path, image* img); | |||
| static TileSet *create(std::string const &path, image* img, std::vector<ibox2>& tiles); | |||
| static TileSet *create(std::string const &path, old_image* img); | |||
| static TileSet *create(std::string const &path, old_image* img, std::vector<ibox2>& tiles); | |||
| /* Old style: path to PNG file */ | |||
| static TileSet *create(std::string const &path, ivec2 size, ivec2 count); | |||
| static TileSet *create(std::string const &path, image* img, ivec2 size, ivec2 count); | |||
| static TileSet *create(std::string const &path, old_image* img, ivec2 size, ivec2 count); | |||
| static void destroy(TileSet *); | |||
| @@ -57,11 +57,11 @@ public: | |||
| private: | |||
| TileSet(std::string const &path); | |||
| TileSet(std::string const &path, image *img); | |||
| TileSet(std::string const &path, old_image *img); | |||
| protected: | |||
| virtual void Init(std::string const &path, ResourceCodecData* loaded_data); | |||
| virtual void Init(std::string const &path, image* img); | |||
| virtual void Init(std::string const &path, old_image* img); | |||
| public: | |||
| /* Inherited from entity */ | |||
| @@ -143,7 +143,7 @@ void gui::refresh_fonts() | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| io.Fonts->GetTexDataAsRGBA32(&pixels, &size.x, &size.y); | |||
| image* img = new image(); | |||
| old_image* img = new old_image(); | |||
| img->Copy(pixels, size, PixelFormat::RGBA_8); | |||
| Ticker::Ref(g_gui->m_font = new TextureImage("", img)); | |||