From 7558d0664aa4e87696b9520888d209ec8cfbbf59 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 13 Jun 2017 09:28:18 +0200 Subject: [PATCH] image: more method renaming for consistency. --- doc/samples/simplex.cpp | 10 +- doc/tutorial/14_lol_lua.cpp | 8 +- src/gpu/framebuffer.cpp | 22 ++-- src/image/codec/dummy-image.cpp | 20 ++-- src/image/codec/gdiplus-image.cpp | 14 +-- src/image/codec/imlib2-image.cpp | 14 +-- src/image/codec/oric-image.cpp | 46 ++++---- src/image/codec/sdl-image.cpp | 14 +-- src/image/codec/zed-image.cpp | 28 ++--- src/image/codec/zed-palette-image.cpp | 27 ++--- src/image/combine.cpp | 70 ++++++------ src/image/crop.cpp | 28 ++--- src/image/dither/dbs.cpp | 72 +++++++------ src/image/dither/ediff.cpp | 46 ++++---- src/image/dither/ordered.cpp | 54 +++++----- src/image/dither/ostromoukhov.cpp | 26 ++--- src/image/dither/random.cpp | 24 +++-- src/image/filter/colors.cpp | 98 ++++++++--------- src/image/filter/convolution.cpp | 104 +++++++++--------- src/image/filter/dilate.cpp | 150 +++++++++++++------------- src/image/filter/median.cpp | 106 +++++++++--------- src/image/filter/yuv.cpp | 34 +++--- src/image/image.cpp | 54 +++++----- src/image/kernel.cpp | 28 ++--- src/image/noise.cpp | 20 ++-- src/image/pixel.cpp | 66 ++++++------ src/image/resample.cpp | 34 +++--- src/lol/image/image.h | 66 ++++++------ src/lol/sys/file.h | 16 +-- src/sys/file.cpp | 20 ++-- src/sys/threadtypes.cpp | 4 +- src/t/image/image.cpp | 14 +-- src/textureimage.cpp | 43 ++++---- 33 files changed, 717 insertions(+), 663 deletions(-) diff --git a/doc/samples/simplex.cpp b/doc/samples/simplex.cpp index 1b7404fe..71c82c5f 100644 --- a/doc/samples/simplex.cpp +++ b/doc/samples/simplex.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Simplex Noise tutorial // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // © 2013-2014 Guillaume Bittoun // // Lol Engine is free software. It comes without any warranty, to @@ -31,8 +31,8 @@ int main(int argc, char **argv) srand(time(nullptr)); /* Create an image */ - Image img(size); - array2d &data = img.Lock2D(); + image img(size); + array2d &data = img.lock2d(); /* Declare plenty of allocators */ simplex_noise<2> s2; @@ -141,7 +141,7 @@ int main(int argc, char **argv) #endif /* Save image */ - img.Unlock2D(data); - img.Save("simplex.png"); + img.unlock2d(data); + img.save("simplex.png"); } diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index 412795e5..adbc9a12 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Lua tutorial // -// Copyright © 2014—2015 Benjamin “Touky” Huet +// Copyright © 2014—2017 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -36,14 +36,14 @@ public: //------------------------------------------------------------------------- static int AddFive(lua_State* l) { - auto stack = LuaStack::Begin(l); - int32_t i = stack.Get(); + auto stack = LuaStack::Begin(l); + int32_t i = stack.Get(); i += 5; return (stack << i).End(); } - + LOLUA_DECLARE_RETURN_METHOD_ARGS(AddTenInstance, GetPtr(), AddTenMethod, Get(), Get(), Get()); static int _AddTenInstance(lua_State* l) { diff --git a/src/gpu/framebuffer.cpp b/src/gpu/framebuffer.cpp index ab261ea2..e3094281 100644 --- a/src/gpu/framebuffer.cpp +++ b/src/gpu/framebuffer.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2013 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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. // #include @@ -343,14 +345,14 @@ ivec2 Framebuffer::GetSize() const return m_data->m_size; } -Image Framebuffer::GetImage() const +image Framebuffer::GetImage() const { - Image ret(m_data->m_size); + image ret(m_data->m_size); - u8vec4 *buffer = ret.Lock(); + u8vec4 *buffer = ret.lock(); glReadPixels(0, 0, m_data->m_size.x, m_data->m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - ret.Unlock(buffer); + ret.unlock(buffer); return ret; } diff --git a/src/image/codec/dummy-image.cpp b/src/image/codec/dummy-image.cpp index 12319dc0..bf1f6271 100644 --- a/src/image/codec/dummy-image.cpp +++ b/src/image/codec/dummy-image.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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. // #include @@ -39,9 +41,9 @@ ResourceCodecData* DummyImageCodec::Load(char const *path) if (strcmp("DUMMY", path)) return nullptr; - auto data = new ResourceImageData(new Image(ivec2(256))); + auto data = new ResourceImageData(new image(ivec2(256))); auto image = data->m_image; - u8vec4 *pixels = image->Lock(), *tmp = pixels; + u8vec4 *pixels = image->lock(), *tmp = pixels; for (int j = 0; j < 256; j++) for (int i = 0; i < 256; i++) { @@ -51,7 +53,7 @@ ResourceCodecData* DummyImageCodec::Load(char const *path) tmp->a = (((i >> 4) ^ (j >> 4)) & 1) * 0xff; ++tmp; } - image->Unlock(pixels); + image->unlock(pixels); return data; } diff --git a/src/image/codec/gdiplus-image.cpp b/src/image/codec/gdiplus-image.cpp index f8b2ae33..a4d94878 100644 --- a/src/image/codec/gdiplus-image.cpp +++ b/src/image/codec/gdiplus-image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -116,13 +116,13 @@ ResourceCodecData* GdiPlusImageCodec::Load(char 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 image(ivec2(size))); auto image = data->m_image; - u8vec4 *pdst = image->Lock(); + u8vec4 *pdst = image->lock(); u8vec4 *psrc = static_cast(bdata.Scan0); for (int n = 0; n < size.x * size.y; n++) pdst[n] = psrc[n].bgra; - image->Unlock(pdst); + image->unlock(pdst); bitmap->UnlockBits(&bdata); delete bitmap; @@ -184,7 +184,7 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data) } auto image = data_image->m_image; - ivec2 size = image->GetSize(); + ivec2 size = image->size(); Gdiplus::Bitmap *b = new Gdiplus::Bitmap(size.x, size.y, PixelFormat32bppARGB); @@ -201,13 +201,13 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data) return false; } - u8vec4 *psrc = image->Lock(); + u8vec4 *psrc = image->lock(); u8vec4 *psrc0 = psrc; u8vec4 *pdst = static_cast(bdata.Scan0); for (int y = 0; y < size.y; y++) for (int x = 0; x < size.x; x++) *pdst++ = (*psrc++).bgra; - image->Unlock(psrc0); + image->unlock(psrc0); b->UnlockBits(&bdata); if (b->Save(wpath, &clsid, nullptr) != Gdiplus::Ok) diff --git a/src/image/codec/imlib2-image.cpp b/src/image/codec/imlib2-image.cpp index 4896972c..d83f145c 100644 --- a/src/image/codec/imlib2-image.cpp +++ b/src/image/codec/imlib2-image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -74,10 +74,10 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path) } ivec2 size(imlib_image_get_width(), imlib_image_get_height()); - auto data = new ResourceImageData(new Image(size)); + auto data = new ResourceImageData(new image(size)); auto image = data->m_image; - u8vec4 *dstdata = image->Lock(); + u8vec4 *dstdata = image->lock(); for (int i = 0; i < size.x * size.y; i++) { @@ -86,7 +86,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path) else dstdata[i] = srcdata[i].bgra; } - image->Unlock(dstdata); + image->unlock(dstdata); imlib_free_image(); @@ -100,13 +100,13 @@ bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data) return false; auto image = data_image->m_image; - ivec2 size = image->GetSize(); + ivec2 size = image->size(); Imlib_Image priv = imlib_create_image(size.x, size.y); imlib_context_set_image(priv); imlib_image_set_has_alpha(1); - u8vec4 const *srcdata = image->Lock(); + u8vec4 const *srcdata = image->lock(); u8vec4 *dstdata = (u8vec4 *)imlib_image_get_data(); for (int i = 0; i < size.x * size.y; i++) @@ -118,7 +118,7 @@ bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data) } imlib_image_put_back_data((DATA32 *)dstdata); - image->Unlock(srcdata); + image->unlock(srcdata); imlib_save_image(path); imlib_free_image(); diff --git a/src/image/codec/oric-image.cpp b/src/image/codec/oric-image.cpp index 348b59fb..3cf79210 100644 --- a/src/image/codec/oric-image.cpp +++ b/src/image/codec/oric-image.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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. // #include @@ -36,7 +38,7 @@ public: private: static String ReadScreen(char const *name); - static void WriteScreen(Image &image, array &result); + static void WriteScreen(image &image, array &result); }; DECLARE_IMAGE_CODEC(OricImageCodec, 100) @@ -63,12 +65,12 @@ ResourceCodecData* OricImageCodec::Load(char const *path) if (screen.count() == 0) return nullptr; - auto data = new ResourceImageData(new Image(ivec2(WIDTH, screen.count() * 6 / WIDTH))); - auto image = data->m_image; + auto data = new ResourceImageData(new image(ivec2(WIDTH, screen.count() * 6 / WIDTH))); + auto img = data->m_image; - u8vec4 *pixels = image->Lock(); + u8vec4 *pixels = img->lock(); - for (int y = 0; y < image->GetSize().y; y++) + for (int y = 0; y < img->size().y; y++) { u8vec2 bgfg(0, 7); @@ -101,7 +103,7 @@ ResourceCodecData* OricImageCodec::Load(char const *path) } } - image->Unlock(pixels); + img->unlock(pixels); return data; } @@ -129,18 +131,18 @@ bool OricImageCodec::Save(char const *path, ResourceCodecData* data) result << (uint8_t)name[0]; result << 0; - auto image = data_image->m_image; - Image tmp; - ivec2 size = image->GetSize(); + auto img = data_image->m_image; + image tmp; + ivec2 size = img->size(); if (size.x != WIDTH) { size.y = (int)((float)size.y * WIDTH / size.x); size.x = WIDTH; - tmp = image->Resize(size, ResampleAlgorithm::Bresenham); - image = &tmp; + tmp = img->Resize(size, ResampleAlgorithm::Bresenham); + img = &tmp; } - WriteScreen(*image, result); + WriteScreen(*img, result); File f; f.Open(path, FileAccess::Write); @@ -469,10 +471,10 @@ static uint8_t bestmove(ivec3 const *in, u8vec2 bgfg, return bestcommand; } -void OricImageCodec::WriteScreen(Image &image, array &result) +void OricImageCodec::WriteScreen(image &img, array &result) { - ivec2 size = image.GetSize(); - vec4 *pixels = image.Lock(); + ivec2 size = img.size(); + vec4 *pixels = img.lock(); int stride = (size.x + 1); @@ -526,7 +528,7 @@ void OricImageCodec::WriteScreen(Image &image, array &result) } } - image.Unlock(pixels); + img.unlock(pixels); //fprintf(stderr, " done.\n"); } diff --git a/src/image/codec/sdl-image.cpp b/src/image/codec/sdl-image.cpp index 416bff2d..e24e6dcb 100644 --- a/src/image/codec/sdl-image.cpp +++ b/src/image/codec/sdl-image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -75,11 +75,11 @@ ResourceCodecData* SdlImageCodec::Load(char const *path) surface = tmp; } - auto data = new ResourceImageData(new Image(size)); + auto data = new ResourceImageData(new image(size)); auto image = data->m_image; - u8vec4 *pixel_data = image->Lock(); + u8vec4 *pixel_data = image->lock(); memcpy(pixel_data, surface->pixels, 4 * size.x * size.y); - image->Unlock(pixel_data); + image->unlock(pixel_data); SDL_FreeSurface(surface); @@ -93,12 +93,12 @@ bool SdlImageCodec::Save(char const *path, ResourceCodecData* data) return false; auto image = data_image->m_image; - ivec2 size = image->GetSize(); + ivec2 size = image->size(); SDL_Surface *surface = Create32BppSurface(size); - u8vec4 *pixel_data = image->Lock(); + u8vec4 *pixel_data = image->lock(); memcpy(surface->pixels, pixel_data, 4 * size.x * size.y); - image->Unlock(pixel_data); + image->unlock(pixel_data); int ret = SDL_SaveBMP(surface, path); SDL_FreeSurface(surface); diff --git a/src/image/codec/zed-image.cpp b/src/image/codec/zed-image.cpp index 91ee8c6b..0d8e00d7 100644 --- a/src/image/codec/zed-image.cpp +++ b/src/image/codec/zed-image.cpp @@ -1,12 +1,14 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2014 Benjamin Huet -// 2014 Sam Hocevar -// 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—2017 Sam Hocevar +// 2014 Benjamin Huet +// +// 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. // #include @@ -43,8 +45,8 @@ ResourceCodecData* ZedImageCodec::Load(char const *path) struct CompactSecondary { CompactSecondary(int32_t size) { m_size = size; } - int32_t m_size; - array m_tiles; + int32_t m_size; + array m_tiles; }; struct CompactMain { @@ -108,7 +110,7 @@ ResourceCodecData* ZedImageCodec::Load(char const *path) file.Open(path, FileAccess::Read, true); //Put file in memory - long file_size = file.GetSize(); + long file_size = file.size(); array file_buffer; file_buffer.resize(file_size); file.Read((uint8_t*)&file_buffer[0], file_size); @@ -227,9 +229,9 @@ ResourceCodecData* ZedImageCodec::Load(char const *path) tex_size <<= 1; //Prepare final image - auto data = new ResourceTilesetData(new Image(ivec2(tex_size))); + auto data = new ResourceTilesetData(new image(ivec2(tex_size))); auto image = data->m_image; - uint8_t *pixels = image->Lock(); + uint8_t *pixels = image->lock(); //Data refactor stage ivec2 pos = ivec2(0); @@ -284,7 +286,7 @@ ResourceCodecData* ZedImageCodec::Load(char const *path) j++; } } - image->Unlock(pixels); + image->unlock(pixels); data->m_tiles = tiles; diff --git a/src/image/codec/zed-palette-image.cpp b/src/image/codec/zed-palette-image.cpp index a0363962..e67e0788 100644 --- a/src/image/codec/zed-palette-image.cpp +++ b/src/image/codec/zed-palette-image.cpp @@ -1,11 +1,14 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar -// 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—2017 Sam Hocevar +// 2014 Benjamin Huet +// +// 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. // #include @@ -41,8 +44,8 @@ ResourceCodecData* ZedPaletteImageCodec::Load(char const *path) File file; file.Open(path, FileAccess::Read, true); - //Put file in memory - long file_size = file.GetSize(); + // Put file in memory + long file_size = file.size(); array file_buffer; file_buffer.resize(file_size); file.Read((uint8_t*)&file_buffer[0], file_size); @@ -53,18 +56,18 @@ ResourceCodecData* ZedPaletteImageCodec::Load(char const *path) int32_t tex_size = 2; while (tex_size < tex_sqrt) tex_size <<= 1; - auto data = new ResourceImageData(new Image(ivec2(tex_size))); + auto data = new ResourceImageData(new image(ivec2(tex_size))); auto image = data->m_image; #else int32_t tex_sqrt = file_size / 3; int32_t tex_size = 2; while (tex_size < tex_sqrt) tex_size <<= 1; - auto data = new ResourceImageData(new Image(ivec2(tex_size, 1))); + auto data = new ResourceImageData(new image(ivec2(tex_size, 1))); auto image = data->m_image; #endif - u8vec4 *pixels = image->Lock(); + u8vec4 *pixels = image->lock(); for (int i = 0; i < file_buffer.count();) { pixels->r = file_buffer[i++]; @@ -73,7 +76,7 @@ ResourceCodecData* ZedPaletteImageCodec::Load(char const *path) pixels->a = (i == 0) ? 0 : 255; ++pixels; } - image->Unlock(pixels); + image->unlock(pixels); return data; } diff --git a/src/image/combine.cpp b/src/image/combine.cpp index d52b302f..d37fc832 100644 --- a/src/image/combine.cpp +++ b/src/image/combine.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -33,18 +35,18 @@ enum class MergeMode }; template -static image GenericMerge(image &src1, image &src2, float alpha) +static image generic_merge(image &src1, image &src2, float alpha) { typedef typename PixelType::type pixel_t; - ASSERT(src1.GetSize() == src2.GetSize()); - int const count = src1.GetSize().x * src2.GetSize().y; + ASSERT(src1.size() == src2.size()); + int const count = src1.size().x * src2.size().y; - image dst(src1.GetSize()); + image dst(src1.size()); - pixel_t const *src1p = src1.Lock(); - pixel_t const *src2p = src2.Lock(); - pixel_t *dstp = dst.Lock(); + pixel_t const *src1p = src1.lock(); + pixel_t const *src2p = src2.lock(); + pixel_t *dstp = dst.lock(); for (int n = 0; n < count; ++n) { @@ -71,80 +73,80 @@ static image GenericMerge(image &src1, image &src2, float alpha) dstp[n] = lol::abs(src1p[n] - src2p[n]); } - src1.Unlock(src1p); - src2.Unlock(src2p); - dst.Unlock(dstp); + src1.unlock(src1p); + src2.unlock(src2p); + dst.unlock(dstp); return dst; } template -static image GenericMerge(image &src1, image &src2, float alpha) +static image generic_merge(image &src1, image &src2, float alpha) { - bool gray1 = src1.GetFormat() == PixelFormat::Y_8 - || src1.GetFormat() == PixelFormat::Y_F32; - bool gray2 = src2.GetFormat() == PixelFormat::Y_8 - || src2.GetFormat() == PixelFormat::Y_F32; + bool gray1 = src1.format() == PixelFormat::Y_8 + || src1.format() == PixelFormat::Y_F32; + bool gray2 = src2.format() == PixelFormat::Y_8 + || src2.format() == PixelFormat::Y_F32; if (gray1 && gray2) - return GenericMerge(src1, src2, alpha); + return generic_merge(src1, src2, alpha); else - return GenericMerge(src1, src2, alpha); + return generic_merge(src1, src2, alpha); } image image::Merge(image &src1, image &src2, float alpha) { - return GenericMerge(src1, src2, alpha); + return generic_merge(src1, src2, alpha); } image image::Mean(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.5f); + return generic_merge(src1, src2, 0.5f); } image image::Min(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Max(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Overlay(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Screen(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Divide(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Multiply(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Add(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Sub(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } image image::Difference(image &src1, image &src2) { - return GenericMerge(src1, src2, 0.0f); + return generic_merge(src1, src2, 0.0f); } } /* namespace lol */ diff --git a/src/image/crop.cpp b/src/image/crop.cpp index 9031187f..707ea85f 100644 --- a/src/image/crop.cpp +++ b/src/image/crop.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -21,18 +23,18 @@ namespace lol image image::Crop(ibox2 box) const { - ivec2 const srcsize = GetSize(); + ivec2 const srcsize = size(); ivec2 const dstsize = box.extent(); image dst(dstsize); - PixelFormat format = GetFormat(); + PixelFormat fmt = format(); - if (format != PixelFormat::Unknown) + if (fmt != PixelFormat::Unknown) { - dst.SetFormat(format); - uint8_t const *srcp = (uint8_t const *)m_data->m_pixels[(int)format]; - uint8_t *dstp = (uint8_t *)dst.m_data->m_pixels[(int)format]; - uint8_t bpp = BytesPerPixel(format); + dst.set_format(fmt); + uint8_t const *srcp = (uint8_t const *)m_data->m_pixels[(int)fmt]; + uint8_t *dstp = (uint8_t *)dst.m_data->m_pixels[(int)fmt]; + uint8_t bpp = BytesPerPixel(fmt); int len = dstsize.x; diff --git a/src/image/dither/dbs.cpp b/src/image/dither/dbs.cpp index 496ec023..b0fd5ea2 100644 --- a/src/image/dither/dbs.cpp +++ b/src/image/dither/dbs.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2015 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -24,44 +26,44 @@ namespace lol /* FIXME: though the algorithm is supposed to stop, we do not have a real, * guaranteed stop condition here. */ -Image Image::DitherDbs() const +image image::dither_dbs() const { - ivec2 size = GetSize(); + ivec2 isize = size(); /* Build our human visual system kernel. */ - array2d kernel; - kernel.resize(ivec2(NN, NN)); + array2d ker; + ker.resize(ivec2(NN, NN)); float t = 0.f; for (int j = 0; j < NN; j++) for (int i = 0; i < NN; i++) { vec2 v = vec2(i - N, j - N); - kernel[i][j] = exp(-sqlength(v / 1.6f) / 2.f) - + exp(-sqlength(v / 0.6f) / 2.f); - t += kernel[i][j]; + ker[i][j] = exp(-sqlength(v / 1.6f) / 2.f) + + exp(-sqlength(v / 0.6f) / 2.f); + t += ker[i][j]; } for (int j = 0; j < NN; j++) for (int i = 0; i < NN; i++) - kernel[i][j] /= t; + ker[i][j] /= t; /* 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 = (size + ivec2(CELL - 1)) / CELL; + ivec2 const csize = (isize + ivec2(CELL - 1)) / CELL; array2d changelist(csize); memset(changelist.data(), 0, changelist.bytes()); - Image dst = *this; - dst.SetFormat(PixelFormat::Y_F32); + image dst = *this; + dst.set_format(PixelFormat::Y_F32); - Image tmp1 = dst.Convolution(kernel); - array2d &tmp1data = tmp1.Lock2D(); + image tmp1 = dst.Convolution(ker); + array2d &tmp1data = tmp1.lock2d(); - dst = dst.DitherRandom(); - array2d &dstdata = dst.Lock2D(); + dst = dst.dither_random(); + array2d &dstdata = dst.lock2d(); - Image tmp2 = dst.Convolution(kernel); - array2d &tmp2data = tmp2.Lock2D(); + image tmp2 = dst.Convolution(ker); + array2d &tmp2data = tmp2.lock2d(); for (int run = 0, last_change = 0; ; ++run) { @@ -84,7 +86,7 @@ Image Image::DitherDbs() const ivec2 const pos(cx * CELL + pixel % CELL, cy * CELL + pixel / CELL); - if (!(pos >= ivec2(0)) || !(pos < size)) + if (!(pos >= ivec2(0)) || !(pos < isize)) continue; /* The best operation we can do */ @@ -103,7 +105,7 @@ Image Image::DitherDbs() const for (ivec2 const op : op_list) { - if (!(pos + op >= ivec2(0)) || !(pos + op < size)) + if (!(pos + op >= ivec2(0)) || !(pos + op < isize)) continue; bool flip = (op == ivec2(0)); @@ -115,9 +117,9 @@ Image Image::DitherDbs() const /* TODO: implement min/max for 3+ arguments */ int imin = max(max(-N, op.x - N), -pos.x); - int imax = min(min(N + 1, op.x + NN - N), size.x - pos.x); + int imax = min(min(N + 1, op.x + NN - N), isize.x - pos.x); int jmin = max(max(-N, op.y - N), -pos.y); - int jmax = min(min(N + 1, op.y + NN - N), size.y - pos.y); + int jmax = min(min(N + 1, op.y + NN - N), isize.y - pos.y); float error = 0.f; for (int j = jmin; j < jmax; j++) @@ -125,9 +127,9 @@ Image Image::DitherDbs() const { ivec2 pos2 = pos + ivec2(i, j); - float m = kernel[i + N][j + N]; + float m = ker[i + N][j + N]; if (!flip) - m -= kernel[i - op.x + N][j - op.y + N]; + m -= ker[i - op.x + N][j - op.y + N]; float p = tmp1data[pos2]; float q1 = tmp2data[pos2]; float q2 = q1 + m * (d2 - d); @@ -154,13 +156,13 @@ Image Image::DitherDbs() const for (int i = -N; i <= N; i++) { ivec2 off(i, j); - float delta = (d2 - d) * kernel[i + N][j + N]; + float delta = (d2 - d) * ker[i + N][j + N]; - if (pos + off >= ivec2(0) && pos + off < size) + if (pos + off >= ivec2(0) && pos + off < isize) tmp2data[pos + off] += delta; if (!flip && pos + off + best_op >= ivec2(0) - && pos + off + best_op < size) + && pos + off + best_op < isize) tmp2data[pos + off + best_op] -= delta; } @@ -173,9 +175,9 @@ Image Image::DitherDbs() const ++changelist[cx][cy]; } - tmp1.Unlock2D(tmp1data); - tmp2.Unlock2D(tmp2data); - dst.Unlock2D(dstdata); + tmp1.unlock2d(tmp1data); + tmp2.unlock2d(tmp2data); + dst.unlock2d(dstdata); return dst; } diff --git a/src/image/dither/ediff.cpp b/src/image/dither/ediff.cpp index 222b1b50..5ff69428 100644 --- a/src/image/dither/ediff.cpp +++ b/src/image/dither/ediff.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -23,49 +25,49 @@ 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::DitherEdiff(array2d const &kernel, ScanMode scan) const +image image::dither_ediff(array2d const &ker, ScanMode scan) const { - Image dst = *this; + image dst = *this; - ivec2 size = dst.GetSize(); - ivec2 ksize = kernel.size(); + ivec2 isize = dst.size(); + ivec2 ksize = ker.size(); int kx; for (kx = 0; kx < ksize.x; kx++) - if (kernel[kx][0] > 0.f) + if (ker[kx][0] > 0.f) break; - float *pixels = dst.Lock(); - for (int y = 0; y < size.y; y++) + float *pixels = dst.lock(); + for (int y = 0; y < isize.y; y++) { bool reverse = (y & 1) && (scan == ScanMode::Serpentine); - for (int x = 0; x < size.x; x++) + for (int x = 0; x < isize.x; x++) { - int x2 = reverse ? size.x - 1 - x : x; + int x2 = reverse ? isize.x - 1 - x : x; int s = reverse ? -1 : 1; - float p = pixels[y * size.x + x2]; + float p = pixels[y * isize.x + x2]; float q = p < 0.5f ? 0.f : 1.f; - pixels[y * size.x + x2] = q; + pixels[y * isize.x + x2] = q; float e = (p - q); - for (int j = 0; j < ksize.y && y < size.y - j; j++) + for (int j = 0; j < ksize.y && y < isize.y - j; j++) for (int i = 0; i < ksize.x; i++) { if (j == 0 && i <= kx) continue; - if (x + i - kx < 0 || x + i - kx >= size.x) + if (x + i - kx < 0 || x + i - kx >= isize.x) continue; - pixels[(y + j) * size.x + x2 + (i - kx) * s] - += e * kernel[i][j]; + pixels[(y + j) * isize.x + x2 + (i - kx) * s] + += e * ker[i][j]; } } } - dst.Unlock(pixels); + dst.unlock(pixels); return dst; } diff --git a/src/image/dither/ordered.cpp b/src/image/dither/ordered.cpp index d28cd369..3aeec6b1 100644 --- a/src/image/dither/ordered.cpp +++ b/src/image/dither/ordered.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,51 +19,51 @@ namespace lol { -static Image DitherHelper(Image const &image, array2d const &kernel, - float scale, float angle); +static image dither_helper(image const &img, array2d const &ker, + float scale, float angle); -Image Image::DitherOrdered(array2d const &kernel) const +image image::dither_ordered(array2d const &ker) const { - return DitherHelper(*this, kernel, 1.0f, 0.0f); + return dither_helper(*this, ker, 1.0f, 0.0f); } -Image Image::DitherHalftone(float radius, float angle) const +image 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 = (radius * PRECISION * lol::sqrt(2.f) + 0.5f); - array2d kernel = Image::HalftoneKernel(ivec2(k, k)); + array2d ker = image::kernel::halftone(ivec2(k, k)); - return DitherHelper(*this, kernel, 1.f / PRECISION, angle + F_PI / 4.f); + return dither_helper(*this, ker, 1.f / PRECISION, angle + F_PI / 4.f); } -static Image DitherHelper(Image const &image, array2d const &kernel, - float scale, float angle) +static image dither_helper(image const &img, array2d const &ker, + float scale, float angle) { - ivec2 size = image.GetSize(); - ivec2 ksize = kernel.size(); + ivec2 isize = img.size(); + ivec2 ksize = ker.size(); float cost = lol::cos(angle); float sint = lol::sin(angle); - Image ret = image; - float *dstp = ret.Lock(); + image ret = img; + float *dstp = ret.lock(); - for (int y = 0; y < size.y; y++) + for (int y = 0; y < isize.y; y++) { - for (int x = 0; x < size.x; x++) + for (int x = 0; x < isize.x; x++) { - int kx = (int)((cost * x - sint * y + 2 * size.x * size.y) / scale) % ksize.x; - int ky = (int)((cost * y + sint * x + 2 * size.x * size.y) / scale) % ksize.y; + int kx = (int)((cost * x - sint * y + 2 * isize.x * isize.y) / scale) % ksize.x; + int ky = (int)((cost * y + sint * x + 2 * isize.x * isize.y) / scale) % ksize.y; - float p = dstp[y * size.x + x]; - dstp[y * size.x + x] = (p > kernel[kx][ky]) ? 1.f : 0.f; + float p = dstp[y * isize.x + x]; + dstp[y * isize.x + x] = (p > ker[kx][ky]) ? 1.f : 0.f; } } - ret.Unlock(dstp); + ret.unlock(dstp); return ret; } diff --git a/src/image/dither/ostromoukhov.cpp b/src/image/dither/ostromoukhov.cpp index 613be14e..b392a867 100644 --- a/src/image/dither/ostromoukhov.cpp +++ b/src/image/dither/ostromoukhov.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -69,13 +71,13 @@ static inline vec3 GetDiffusion(float v) return ret; } -Image Image::DitherOstromoukhov(ScanMode scan) const +image image::dither_ostromoukhov(ScanMode scan) const { - Image dst = *this; + image dst = *this; - float *pixels = dst.Lock(); - int w = dst.GetSize().x; - int h = dst.GetSize().y; + float *pixels = dst.lock(); + int w = dst.size().x; + int h = dst.size().y; for (int y = 0; y < h; y++) { @@ -103,7 +105,7 @@ Image Image::DitherOstromoukhov(ScanMode scan) const } } - dst.Unlock(pixels); + dst.unlock(pixels); return dst; } diff --git a/src/image/dither/random.cpp b/src/image/dither/random.cpp index 967d408a..283f6e3b 100644 --- a/src/image/dither/random.cpp +++ b/src/image/dither/random.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,19 +19,19 @@ namespace lol { -Image Image::DitherRandom() const +image image::dither_random() const { - Image dst = *this; + image dst = *this; - float *pixels = dst.Lock(); - int count = GetSize().x * GetSize().y; + float *pixels = dst.lock(); + int count = size().x * size().y; for (int n = 0; n < count; ++n) { pixels[n] = (pixels[n] > lol::rand(0.5f)) ? 1.f : 0.f; } - dst.Unlock(pixels); + dst.unlock(pixels); return dst; } diff --git a/src/image/filter/colors.cpp b/src/image/filter/colors.cpp index 78088248..6ab1c4e6 100644 --- a/src/image/filter/colors.cpp +++ b/src/image/filter/colors.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,34 +19,34 @@ namespace lol { -Image Image::Brightness(float val) const +image image::Brightness(float val) const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { - float *pixels = ret.Lock(); + float *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = lol::clamp(pixels[n] + val, 0.f, 1.f); - ret.Unlock(pixels); + ret.unlock(pixels); } else { - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = vec4(lol::clamp(pixels[n].rgb + vec3(val), 0.f, 1.f), pixels[n].a); - ret.Unlock(pixels); + ret.unlock(pixels); } return ret; } -Image Image::Contrast(float val) const +image image::Contrast(float val) const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; if (val >= 0.f) { @@ -58,22 +60,22 @@ Image Image::Contrast(float val) const val = lol::clamp(1.f + val, 0.f, 1.f); } - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { float add = -0.5f * val + 0.5f; - float *pixels = ret.Lock(); + float *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = lol::clamp(pixels[n] * val + add, 0.f, 1.f); - ret.Unlock(pixels); + ret.unlock(pixels); } else { vec3 add = vec3(-0.5f * val + 0.5f); - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = vec4(lol::clamp(pixels[n].rgb * val + add, 0.f, 1.f), pixels[n].a); - ret.Unlock(pixels); + ret.unlock(pixels); } return ret; @@ -83,16 +85,16 @@ 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 +image image::AutoContrast() const { - Image ret = *this; + image ret = *this; float min_val = 1.f, max_val = 0.f; - int count = GetSize().x * GetSize().y; + int count = size().x * size().y; - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { - float *pixels = ret.Lock(); + float *pixels = ret.lock(); for (int n = 0; n < count; ++n) { min_val = lol::min(min_val, pixels[n]); @@ -103,11 +105,11 @@ Image Image::AutoContrast() const for (int n = 0; n < count; ++n) pixels[n] = (pixels[n] - min_val) * t; - ret.Unlock(pixels); + ret.unlock(pixels); } else { - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) { min_val = lol::min(min_val, pixels[n].r); @@ -125,60 +127,60 @@ Image Image::AutoContrast() const (pixels[n].b - min_val) * t, pixels[n].a);; - ret.Unlock(pixels); + ret.unlock(pixels); } return ret; } -Image Image::Invert() const +image image::Invert() const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { - float *pixels = ret.Lock(); + float *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = 1.f - pixels[n]; - ret.Unlock(pixels); + ret.unlock(pixels); } else { - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = vec4(vec3(1.f) -pixels[n].rgb, pixels[n].a); - ret.Unlock(pixels); + ret.unlock(pixels); } return ret; } -Image Image::Threshold(float val) const +image image::Threshold(float val) const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - float *pixels = ret.Lock(); + float *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = pixels[n] > val ? 1.f : 0.f; - ret.Unlock(pixels); + ret.unlock(pixels); return ret; } -Image Image::Threshold(vec3 val) const +image image::Threshold(vec3 val) const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = vec4(pixels[n].r > val.r ? 1.f : 0.f, pixels[n].g > val.g ? 1.f : 0.f, pixels[n].b > val.b ? 1.f : 0.f, pixels[n].a); - ret.Unlock(pixels); + ret.unlock(pixels); return ret; } diff --git a/src/image/filter/convolution.cpp b/src/image/filter/convolution.cpp index fd300569..08357e2c 100644 --- a/src/image/filter/convolution.cpp +++ b/src/image/filter/convolution.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,21 +19,21 @@ namespace lol { -static Image SepConv(Image &src, array const &hvec, +static image SepConv(image &src, array const &hvec, array const &vvec); -static Image NonSepConv(Image &src, array2d const &kernel); +static image NonSepConv(image &src, array2d const &in_kernel); -Image Image::Convolution(array2d const &kernel) +image image::Convolution(array2d const &in_kernel) { /* Find the cell with the largest value */ - ivec2 ksize = kernel.size(); + ivec2 ksize = in_kernel.size(); int bestx = -1, besty = -1; float tmp = 0.f; for (int dy = 0; dy < ksize.y; ++dy) for (int dx = 0; dx < ksize.x; ++dx) - if (lol::sq(kernel[dx][dy]) > tmp) + if (lol::sq(in_kernel[dx][dy]) > tmp) { - tmp = sq(kernel[dx][dy]); + tmp = sq(in_kernel[dx][dy]); bestx = dx; besty = dy; } @@ -52,8 +54,8 @@ Image Image::Convolution(array2d const &kernel) if (dx == bestx) continue; - float p = kernel[dx][dy] * kernel[bestx][besty]; - float q = kernel[dx][besty] * kernel[bestx][dy]; + float p = in_kernel[dx][dy] * in_kernel[bestx][besty]; + float q = in_kernel[dx][besty] * in_kernel[bestx][dy]; if (lol::abs(p - q) > 1.0e-8f) separable = false; @@ -65,29 +67,29 @@ Image Image::Convolution(array2d const &kernel) /* Matrix rank is 1! Separate the filter. */ array hvec, vvec; - float norm = 1.0f / lol::sqrt(lol::abs(kernel[bestx][besty])); + float norm = 1.0f / lol::sqrt(lol::abs(in_kernel[bestx][besty])); for (int dx = 0; dx < ksize.x; dx++) - hvec << norm * kernel[dx][besty]; + hvec << norm * in_kernel[dx][besty]; for (int dy = 0; dy < ksize.y; dy++) - vvec << norm * kernel[bestx][dy]; + vvec << norm * in_kernel[bestx][dy]; return SepConv(*this, hvec, vvec); } else { - return NonSepConv(*this, kernel); + return NonSepConv(*this, in_kernel); } } -Image Image::Sharpen(array2d const &kernel) +image image::Sharpen(array2d const &in_kernel) { - ivec2 ksize = kernel.size(); + ivec2 ksize = in_kernel.size(); array2d newkernel(ksize); for (int dy = 0; dy < ksize.y; ++dy) for (int dx = 0; dx < ksize.x; ++dx) { - newkernel[dx][dy] = - kernel[dx][dy]; + newkernel[dx][dy] = - in_kernel[dx][dy]; if (dx == ksize.x / 2 && dy == ksize.y / 2) newkernel[dx][dy] += 2.f; } @@ -96,16 +98,16 @@ Image Image::Sharpen(array2d const &kernel) } template -static Image NonSepConv(Image &src, array2d const &kernel) +static image NonSepConv(image &src, array2d const &in_kernel) { typedef typename PixelType::type pixel_t; - ivec2 const size = src.GetSize(); - ivec2 const ksize = kernel.size(); - Image dst(size); + ivec2 const size = src.size(); + ivec2 const ksize = in_kernel.size(); + image dst(size); - array2d const &srcp = src.Lock2D(); - array2d &dstp = dst.Lock2D(); + array2d const &srcp = src.lock2d(); + array2d &dstp = dst.lock2d(); for (int y = 0; y < size.y; y++) { @@ -123,7 +125,7 @@ static Image NonSepConv(Image &src, array2d const &kernel) for (int dx = 0; dx < ksize.x; dx++) { - float f = kernel[dx][dy]; + float f = in_kernel[dx][dy]; int x2 = x + dx - ksize.x / 2; if (x2 < 0) @@ -139,33 +141,33 @@ static Image NonSepConv(Image &src, array2d const &kernel) } } - src.Unlock2D(srcp); - dst.Unlock2D(dstp); + src.unlock2d(srcp); + dst.unlock2d(dstp); return dst; } -static Image NonSepConv(Image &src, array2d const &kernel) +static image NonSepConv(image &src, array2d const &in_kernel) { bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; bool const wrap_y = src.GetWrapY() == WrapMode::Repeat; - if (src.GetFormat() == PixelFormat::Y_8 - || src.GetFormat() == PixelFormat::Y_F32) + if (src.format() == PixelFormat::Y_8 + || src.format() == PixelFormat::Y_F32) { if (wrap_x) { if (wrap_y) - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); else - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); } else { if (wrap_y) - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); else - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); } } else @@ -173,32 +175,32 @@ static Image NonSepConv(Image &src, array2d const &kernel) if (wrap_x) { if (wrap_y) - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); else - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); } else { if (wrap_y) - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); else - return NonSepConv(src, kernel); + return NonSepConv(src, in_kernel); } } } template -static Image SepConv(Image &src, array const &hvec, +static image SepConv(image &src, array const &hvec, array const &vvec) { typedef typename PixelType::type pixel_t; - ivec2 const size = src.GetSize(); + ivec2 const size = src.size(); ivec2 const ksize(hvec.count(), vvec.count()); - Image dst(size); + image dst(size); - array2d const &srcp = src.Lock2D(); - array2d &dstp = dst.Lock2D(); + array2d const &srcp = src.lock2d(); + array2d &dstp = dst.lock2d(); array2d tmp(size); @@ -244,20 +246,20 @@ static Image SepConv(Image &src, array const &hvec, } } - src.Unlock2D(srcp); - dst.Unlock2D(dstp); + src.unlock2d(srcp); + dst.unlock2d(dstp); return dst; } -static Image SepConv(Image &src, array const &hvec, +static image SepConv(image &src, array const &hvec, array const &vvec) { bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; bool const wrap_y = src.GetWrapY() == WrapMode::Repeat; - if (src.GetFormat() == PixelFormat::Y_8 - || src.GetFormat() == PixelFormat::Y_F32) + if (src.format() == PixelFormat::Y_8 + || src.format() == PixelFormat::Y_F32) { if (wrap_x) { diff --git a/src/image/filter/dilate.cpp b/src/image/filter/dilate.cpp index 3c4cd040..a92f96b7 100644 --- a/src/image/filter/dilate.cpp +++ b/src/image/filter/dilate.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -22,115 +24,115 @@ namespace lol { -Image Image::Dilate() +image image::Dilate() { - ivec2 const size = GetSize(); - Image ret(size); + ivec2 isize = size(); + image ret(isize); - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { - float const *srcp = Lock(); - float *dstp = ret.Lock(); + float const *srcp = lock(); + float *dstp = ret.lock(); - for (int y = 0; y < size.y; ++y) - for (int x = 0; x < size.x; ++x) + for (int y = 0; y < isize.y; ++y) + for (int x = 0; x < isize.x; ++x) { int y2 = lol::max(y - 1, 0); int x2 = lol::max(x - 1, 0); - int y3 = lol::min(y + 1, size.y - 1); - int x3 = lol::min(x + 1, size.x - 1); - - float t = srcp[y * size.x + x]; - t = lol::max(t, srcp[y * size.x + x2]); - t = lol::max(t, srcp[y * size.x + x3]); - t = lol::max(t, srcp[y2 * size.x + x]); - t = lol::max(t, srcp[y3 * size.x + x]); - dstp[y * size.x + x] = t; + int y3 = lol::min(y + 1, isize.y - 1); + int x3 = lol::min(x + 1, isize.x - 1); + + float t = srcp[y * isize.x + x]; + t = lol::max(t, srcp[y * isize.x + x2]); + t = lol::max(t, srcp[y * isize.x + x3]); + t = lol::max(t, srcp[y2 * isize.x + x]); + t = lol::max(t, srcp[y3 * isize.x + x]); + dstp[y * isize.x + x] = t; } - Unlock(srcp); - ret.Unlock(dstp); + unlock(srcp); + ret.unlock(dstp); } else { - vec4 const *srcp = Lock(); - vec4 *dstp = ret.Lock(); + vec4 const *srcp = lock(); + vec4 *dstp = ret.lock(); - for (int y = 0; y < size.y; ++y) - for (int x = 0; x < size.x; ++x) + for (int y = 0; y < isize.y; ++y) + for (int x = 0; x < isize.x; ++x) { int y2 = lol::max(y - 1, 0); int x2 = lol::max(x - 1, 0); - int y3 = lol::min(y + 1, size.y - 1); - int x3 = lol::min(x + 1, size.x - 1); - - vec3 t = srcp[y * size.x + x].rgb; - t = lol::max(t, srcp[y * size.x + x2].rgb); - t = lol::max(t, srcp[y * size.x + x3].rgb); - t = lol::max(t, srcp[y2 * size.x + x].rgb); - t = lol::max(t, srcp[y3 * size.x + x].rgb); - dstp[y * size.x + x] = vec4(t, srcp[y * size.x + x].a); + int y3 = lol::min(y + 1, isize.y - 1); + int x3 = lol::min(x + 1, isize.x - 1); + + vec3 t = srcp[y * isize.x + x].rgb; + t = lol::max(t, srcp[y * isize.x + x2].rgb); + t = lol::max(t, srcp[y * isize.x + x3].rgb); + t = lol::max(t, srcp[y2 * isize.x + x].rgb); + t = lol::max(t, srcp[y3 * isize.x + x].rgb); + dstp[y * isize.x + x] = vec4(t, srcp[y * isize.x + x].a); } - Unlock(srcp); - ret.Unlock(dstp); + unlock(srcp); + ret.unlock(dstp); } return ret; } -Image Image::Erode() +image image::Erode() { - ivec2 const size = GetSize(); - Image ret(size); + ivec2 isize = size(); + image ret(isize); - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { - float const *srcp = Lock(); - float *dstp = ret.Lock(); + float const *srcp = lock(); + float *dstp = ret.lock(); - for (int y = 0; y < size.y; ++y) - for (int x = 0; x < size.x; ++x) + for (int y = 0; y < isize.y; ++y) + for (int x = 0; x < isize.x; ++x) { int y2 = lol::max(y - 1, 0); int x2 = lol::max(x - 1, 0); - int y3 = lol::min(y + 1, size.y - 1); - int x3 = lol::min(x + 1, size.x - 1); - - float t = srcp[y * size.x + x]; - t = lol::max(t, srcp[y * size.x + x2]); - t = lol::max(t, srcp[y * size.x + x3]); - t = lol::max(t, srcp[y2 * size.x + x]); - t = lol::max(t, srcp[y3 * size.x + x]); - dstp[y * size.x + x] = t; + int y3 = lol::min(y + 1, isize.y - 1); + int x3 = lol::min(x + 1, isize.x - 1); + + float t = srcp[y * isize.x + x]; + t = lol::max(t, srcp[y * isize.x + x2]); + t = lol::max(t, srcp[y * isize.x + x3]); + t = lol::max(t, srcp[y2 * isize.x + x]); + t = lol::max(t, srcp[y3 * isize.x + x]); + dstp[y * isize.x + x] = t; } - Unlock(srcp); - ret.Unlock(dstp); + unlock(srcp); + ret.unlock(dstp); } else { - vec4 const *srcp = Lock(); - vec4 *dstp = ret.Lock(); + vec4 const *srcp = lock(); + vec4 *dstp = ret.lock(); - for (int y = 0; y < size.y; ++y) - for (int x = 0; x < size.x; ++x) + for (int y = 0; y < isize.y; ++y) + for (int x = 0; x < isize.x; ++x) { int y2 = lol::max(y - 1, 0); int x2 = lol::max(x - 1, 0); - int y3 = lol::min(y + 1, size.y - 1); - int x3 = lol::min(x + 1, size.x - 1); - - vec3 t = srcp[y * size.x + x].rgb; - t = lol::min(t, srcp[y * size.x + x2].rgb); - t = lol::min(t, srcp[y * size.x + x3].rgb); - t = lol::min(t, srcp[y2 * size.x + x].rgb); - t = lol::min(t, srcp[y3 * size.x + x].rgb); - dstp[y * size.x + x] = vec4(t, srcp[y * size.x + x].a); + int y3 = lol::min(y + 1, isize.y - 1); + int x3 = lol::min(x + 1, isize.x - 1); + + vec3 t = srcp[y * isize.x + x].rgb; + t = lol::min(t, srcp[y * isize.x + x2].rgb); + t = lol::min(t, srcp[y * isize.x + x3].rgb); + t = lol::min(t, srcp[y2 * isize.x + x].rgb); + t = lol::min(t, srcp[y3 * isize.x + x].rgb); + dstp[y * isize.x + x] = vec4(t, srcp[y * isize.x + x].a); } - Unlock(srcp); - ret.Unlock(dstp); + unlock(srcp); + ret.unlock(dstp); } return ret; diff --git a/src/image/filter/median.cpp b/src/image/filter/median.cpp index 10cc5a9f..5f27109f 100644 --- a/src/image/filter/median.cpp +++ b/src/image/filter/median.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -33,38 +35,38 @@ static int cmpfloat(void const *i1, void const *i2) return (a > b) - (a < b); } -Image Image::Median(ivec2 ksize) const +image image::Median(ivec2 ksize) const { - ivec2 const size = GetSize(); - Image tmp = *this; - Image ret(size); + ivec2 const isize = size(); + image tmp = *this; + image ret(isize); - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { ivec2 const lsize = 2 * ksize + ivec2(1); array2d list(lsize); - float *srcp = tmp.Lock(); - float *dstp = ret.Lock(); + float *srcp = tmp.lock(); + float *dstp = ret.lock(); - for (int y = 0; y < size.y; y++) + for (int y = 0; y < isize.y; y++) { - for (int x = 0; x < size.x; x++) + for (int x = 0; x < isize.x; x++) { /* Make a list of neighbours */ for (int j = -ksize.y; j <= ksize.y; j++) { int y2 = y + j; - if (y2 < 0) y2 = size.y - 1 - ((-y2 - 1) % size.y); - else if (y2 > 0) y2 = y2 % size.y; + if (y2 < 0) y2 = isize.y - 1 - ((-y2 - 1) % isize.y); + else if (y2 > 0) y2 = y2 % isize.y; for (int i = -ksize.x; i <= ksize.x; i++) { int x2 = x + i; - if (x2 < 0) x2 = size.x - 1 - ((-x2 - 1) % size.x); - else if (x2 > 0) x2 = x2 % size.x; + if (x2 < 0) x2 = isize.x - 1 - ((-x2 - 1) % isize.x); + else if (x2 > 0) x2 = x2 % isize.x; - list[i + ksize.x][j + ksize.y] = srcp[y2 * size.x + x2]; + list[i + ksize.x][j + ksize.y] = srcp[y2 * isize.x + x2]; } } @@ -72,39 +74,39 @@ Image Image::Median(ivec2 ksize) const qsort(&list[0][0], lsize.x * lsize.y, sizeof(float), cmpfloat); /* Store the median value */ - dstp[y * size.x + x] = *(&list[0][0] + lsize.x * lsize.y / 2); + dstp[y * isize.x + x] = *(&list[0][0] + lsize.x * lsize.y / 2); } } - tmp.Unlock(srcp); - ret.Unlock(dstp); + tmp.unlock(srcp); + ret.unlock(dstp); } else { ivec2 const lsize = 2 * ksize + ivec2(1); array2d list(lsize); - vec4 *srcp = tmp.Lock(); - vec4 *dstp = ret.Lock(); + vec4 *srcp = tmp.lock(); + vec4 *dstp = ret.lock(); - for (int y = 0; y < size.y; y++) + for (int y = 0; y < isize.y; y++) { - for (int x = 0; x < size.x; x++) + for (int x = 0; x < isize.x; x++) { /* Make a list of neighbours */ for (int j = -ksize.y; j <= ksize.y; j++) { int y2 = y + j; - if (y2 < 0) y2 = size.y - 1 - ((-y2 - 1) % size.y); - else if (y2 > 0) y2 = y2 % size.y; + if (y2 < 0) y2 = isize.y - 1 - ((-y2 - 1) % isize.y); + else if (y2 > 0) y2 = y2 % isize.y; for (int i = -ksize.x; i <= ksize.x; i++) { int x2 = x + i; - if (x2 < 0) x2 = size.x - 1 - ((-x2 - 1) % size.x); - else if (x2 > 0) x2 = x2 % size.x; + if (x2 < 0) x2 = isize.x - 1 - ((-x2 - 1) % isize.x); + else if (x2 > 0) x2 = x2 % isize.x; - list[i + ksize.x][j + ksize.y] = srcp[y2 * size.x + x2].rgb; + list[i + ksize.x][j + ksize.y] = srcp[y2 * isize.x + x2].rgb; } } @@ -139,26 +141,26 @@ Image Image::Median(ivec2 ksize) const } /* Store the median value */ - dstp[y * size.x + x] = vec4(median, srcp[y * size.x + x].a); + dstp[y * isize.x + x] = vec4(median, srcp[y * isize.x + x].a); } } - tmp.Unlock(srcp); - ret.Unlock(dstp); + tmp.unlock(srcp); + ret.unlock(dstp); } return ret; } -Image Image::Median(array2d const &kernel) const +image image::Median(array2d const &kernel) const { - ivec2 const size = GetSize(); - Image tmp = *this; - Image ret(size); + ivec2 const isize = size(); + image tmp = *this; + image ret(isize); /* FIXME: TODO */ #if 0 - if (GetFormat() == PixelFormat::Y_8 || GetFormat() == PixelFormat::Y_F32) + if (format() == PixelFormat::Y_8 || format() == PixelFormat::Y_F32) { } else @@ -167,27 +169,27 @@ Image Image::Median(array2d const &kernel) const ivec2 const ksize = kernel.size(); array2d list(ksize); - vec4 *srcp = tmp.Lock(); - vec4 *dstp = ret.Lock(); + vec4 *srcp = tmp.lock(); + vec4 *dstp = ret.lock(); - for (int y = 0; y < size.y; y++) + for (int y = 0; y < isize.y; y++) { - for (int x = 0; x < size.x; x++) + for (int x = 0; x < isize.x; x++) { /* Make a list of neighbours */ for (int j = 0; j < ksize.y; j++) { int y2 = y + j - ksize.y / 2; - if (y2 < 0) y2 = size.y - 1 - ((-y2 - 1) % size.y); - else if (y2 > 0) y2 = y2 % size.y; + if (y2 < 0) y2 = isize.y - 1 - ((-y2 - 1) % isize.y); + else if (y2 > 0) y2 = y2 % isize.y; for (int i = 0; i < ksize.x; i++) { int x2 = x + i - ksize.x / 2; - if (x2 < 0) x2 = size.x - 1 - ((-x2 - 1) % size.x); - else if (x2 > 0) x2 = x2 % size.x; + if (x2 < 0) x2 = isize.x - 1 - ((-x2 - 1) % isize.x); + else if (x2 > 0) x2 = x2 % isize.x; - list[i][j] = srcp[y2 * size.x + x2].rgb; + list[i][j] = srcp[y2 * isize.x + x2].rgb; } } @@ -222,12 +224,12 @@ Image Image::Median(array2d const &kernel) const } /* Store the median value */ - dstp[y * size.x + x] = vec4(median, srcp[y * size.x + x].a); + dstp[y * isize.x + x] = vec4(median, srcp[y * isize.x + x].a); } } - tmp.Unlock(srcp); - ret.Unlock(dstp); + tmp.unlock(srcp); + ret.unlock(dstp); } return ret; diff --git a/src/image/filter/yuv.cpp b/src/image/filter/yuv.cpp index 063dc8d3..61a8b199 100644 --- a/src/image/filter/yuv.cpp +++ b/src/image/filter/yuv.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,28 +19,28 @@ namespace lol { -Image Image::YUVToRGB() const +image image::YUVToRGB() const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = Color::YUVToRGB(pixels[n]); - ret.Unlock(pixels); + ret.unlock(pixels); return ret; } -Image Image::RGBToYUV() const +image image::RGBToYUV() const { - Image ret = *this; - int count = GetSize().x * GetSize().y; + image ret = *this; + int count = size().x * size().y; - vec4 *pixels = ret.Lock(); + vec4 *pixels = ret.lock(); for (int n = 0; n < count; ++n) pixels[n] = Color::RGBToYUV(pixels[n]); - ret.Unlock(pixels); + ret.unlock(pixels); return ret; } diff --git a/src/image/image.cpp b/src/image/image.cpp index 20a99ade..7b283df5 100644 --- a/src/image/image.cpp +++ b/src/image/image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -20,7 +20,7 @@ namespace lol { /* - * Public Image class + * Public image class */ image::image() @@ -31,13 +31,13 @@ image::image() image::image(char const *path) : m_data(new image_data()) { - Load(path); + load(path); } image::image(ivec2 size) : m_data(new image_data()) { - SetSize(size); + resize(size); } image::image (image const &other) @@ -65,21 +65,21 @@ image::~image() void image::Copy(uint8_t* src_pixels, ivec2 const& size, PixelFormat fmt) { ASSERT(fmt != PixelFormat::Unknown); - SetSize(size); - SetFormat(fmt); + resize(size); + set_format(fmt); memcpy(m_data->m_pixels[(int)fmt]->data(), src_pixels, size.x * size.y * BytesPerPixel(fmt)); } void image::Copy(image const &src) { - ivec2 size = src.GetSize(); - PixelFormat fmt = src.GetFormat(); + ivec2 size = src.size(); + PixelFormat fmt = src.format(); - SetSize(size); + resize(size); if (fmt != PixelFormat::Unknown) { - SetFormat(fmt); + set_format(fmt); memcpy(m_data->m_pixels[(int)fmt]->data(), src.m_data->m_pixels[(int)fmt]->data(), size.x * size.y * BytesPerPixel(fmt)); @@ -88,10 +88,10 @@ void image::Copy(image const &src) void image::DummyFill() { - Load("DUMMY"); + load("DUMMY"); } -bool image::Load(char const *path) +bool image::load(char const *path) { auto resource = ResourceLoader::Load(path); if (resource == nullptr) @@ -109,7 +109,7 @@ bool image::Load(char const *path) return true; } -bool image::Save(char const *path) +bool image::save(char const *path) { auto data = new ResourceImageData(new image(*this)); auto result = ResourceLoader::Save(path, data); @@ -117,12 +117,12 @@ bool image::Save(char const *path) return result; } -ivec2 image::GetSize() const +ivec2 image::size() const { return m_data->m_size; } -void image::SetSize(ivec2 size) +void image::resize(ivec2 size) { ASSERT(size.x > 0); ASSERT(size.y > 0); @@ -158,24 +158,24 @@ void image::SetWrap(WrapMode wrap_x, WrapMode wrap_y) m_data->m_wrap_y = wrap_y; } -/* The Lock() method */ -template typename PixelType::type *image::Lock() +/* The lock() method */ +template typename PixelType::type *image::lock() { - SetFormat(T); + set_format(T); return (typename PixelType::type *)m_data->m_pixels[(int)T]->data(); } -/* The Lock2D() method */ -void *image::Lock2DHelper(PixelFormat T) +/* The lock2d() method */ +void *image::lock2d_helper(PixelFormat T) { - SetFormat(T); + set_format(T); return m_data->m_pixels[(int)T]->data2d(); } template -void image::Unlock2D(array2d const &array) +void image::unlock2d(array2d const &array) { ASSERT(m_data->m_pixels.has_key((int)m_data->m_format)); ASSERT(array.data() == m_data->m_pixels[(int)m_data->m_format]->data()); @@ -183,9 +183,9 @@ void image::Unlock2D(array2d const &array) /* Explicit specialisations for the above templates */ #define _T(T) \ - template PixelType::type *image::Lock(); \ - template array2d::type> &image::Lock2D(); \ - template void image::Unlock2D(array2d::type> const &array); + template PixelType::type *image::lock(); \ + template array2d::type> &image::lock2d(); \ + template void image::unlock2d(array2d::type> const &array); _T(PixelFormat::Y_8) _T(PixelFormat::RGB_8) _T(PixelFormat::RGBA_8) @@ -195,14 +195,14 @@ _T(PixelFormat::RGBA_F32) #undef _T /* Special case for the "any" format: return the last active buffer */ -void *image::Lock() +void *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 image::unlock(void const *pixels) { ASSERT(m_data->m_pixels.has_key((int)m_data->m_format)); ASSERT(pixels == m_data->m_pixels[(int)m_data->m_format]->data()); diff --git a/src/image/kernel.cpp b/src/image/kernel.cpp index 5b8ac465..483ab6cb 100644 --- a/src/image/kernel.cpp +++ b/src/image/kernel.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -17,7 +19,7 @@ namespace lol { -array2d image::BayerKernel(ivec2 size) +array2d image::kernel::bayer(ivec2 size) { array2d ret(size); @@ -46,7 +48,7 @@ array2d image::BayerKernel(ivec2 size) return ret; } -array2d image::HalftoneKernel(ivec2 size) +array2d image::kernel::halftone(ivec2 size) { array2d ret(size); @@ -72,10 +74,10 @@ array2d image::HalftoneKernel(ivec2 size) ret[x][y] = flip ? 10.f - r : r; } - return NormalizeKernel(ret); + return normalize(ret); } -array2d image::BlueNoiseKernel(ivec2 size, ivec2 gsize) +array2d image::kernel::blue_noise(ivec2 size, ivec2 gsize) { float const epsilon = 1.f / (size.x * size.y + 1); gsize = lol::min(size, gsize); @@ -180,7 +182,7 @@ static int cmpdot(const void *p1, const void *p2) return ((Dot const *)p1)->val > ((Dot const *)p2)->val; } -array2d image::NormalizeKernel(array2d const &kernel) +array2d image::kernel::normalize(array2d const &kernel) { ivec2 size = kernel.size(); @@ -209,7 +211,7 @@ array2d image::NormalizeKernel(array2d const &kernel) return dst; } -array2d image::EdiffKernel(EdiffAlgorithm algorithm) +array2d image::kernel::ediff(EdiffAlgorithm algorithm) { switch (algorithm) { @@ -270,7 +272,7 @@ array2d image::EdiffKernel(EdiffAlgorithm algorithm) * there is little chance that any value below 0.2 will be useful. */ #define BLUR_EPSILON 0.2f -array2d image::GaussianKernel(vec2 radius, float angle, vec2 delta) +array2d image::kernel::gaussian(vec2 radius, float angle, vec2 delta) { array2d kernel; diff --git a/src/image/noise.cpp b/src/image/noise.cpp index 2da3b314..408ea524 100644 --- a/src/image/noise.cpp +++ b/src/image/noise.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -19,8 +21,8 @@ namespace lol bool image::RenderRandom(ivec2 size) { - SetSize(size); - vec4 *pixels = Lock(); + resize(size); + vec4 *pixels = lock(); for (int n = 0; n < size.x * size.y; ++n) pixels[n] = vec4(lol::rand(1.f), @@ -28,7 +30,7 @@ bool image::RenderRandom(ivec2 size) lol::rand(1.f), 1.f); - Unlock(pixels); + unlock(pixels); return true; } diff --git a/src/image/pixel.cpp b/src/image/pixel.cpp index f6d3b2ef..db1feae7 100644 --- a/src/image/pixel.cpp +++ b/src/image/pixel.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2004—2015 Sam Hocevar +// Copyright © 2004—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -60,7 +60,7 @@ static u8vec4 f32tou8(vec4 pixel) * Pixel-level image manipulation */ -PixelFormat image::GetFormat() const +PixelFormat image::format() const { return m_data->m_format; } @@ -81,41 +81,41 @@ PixelFormat image::GetFormat() const * x lossless conversion (u8 to float) * # lossy conversion (dithering and/or convert color→gray) */ -void image::SetFormat(PixelFormat fmt) +void image::set_format(PixelFormat fmt) { PixelFormat old_fmt = m_data->m_format; /* Preliminary intermediate conversions */ if (old_fmt == PixelFormat::RGBA_8 && fmt == PixelFormat::Y_F32) - SetFormat(PixelFormat::RGBA_F32); + set_format(PixelFormat::RGBA_F32); else if (old_fmt == PixelFormat::RGB_8 && fmt == PixelFormat::Y_F32) - SetFormat(PixelFormat::RGBA_F32); + set_format(PixelFormat::RGBA_F32); else if (old_fmt == PixelFormat::Y_F32 && fmt == PixelFormat::RGBA_8) - SetFormat(PixelFormat::RGBA_F32); + set_format(PixelFormat::RGBA_F32); else if (old_fmt == PixelFormat::Y_F32 && fmt == PixelFormat::RGB_8) - SetFormat(PixelFormat::RGBA_F32); + set_format(PixelFormat::RGBA_F32); else if (old_fmt == PixelFormat::RGB_F32 && fmt == PixelFormat::RGBA_8) - SetFormat(PixelFormat::RGBA_F32); + set_format(PixelFormat::RGBA_F32); else if (old_fmt == PixelFormat::RGBA_F32 && fmt == PixelFormat::Y_F32) - SetFormat(PixelFormat::RGB_F32); + set_format(PixelFormat::RGB_F32); else if (old_fmt == PixelFormat::RGBA_F32 && fmt == PixelFormat::RGB_8) - SetFormat(PixelFormat::RGB_F32); + set_format(PixelFormat::RGB_F32); else if (old_fmt == PixelFormat::RGB_8 && fmt == PixelFormat::Y_8) - SetFormat(PixelFormat::RGB_F32); + set_format(PixelFormat::RGB_F32); else if (old_fmt == PixelFormat::RGBA_8 && fmt == PixelFormat::Y_8) - SetFormat(PixelFormat::RGB_F32); + set_format(PixelFormat::RGB_F32); else if (old_fmt == PixelFormat::RGB_F32 && fmt == PixelFormat::Y_8) - SetFormat(PixelFormat::Y_F32); + set_format(PixelFormat::Y_F32); else if (old_fmt == PixelFormat::RGBA_F32 && fmt == PixelFormat::Y_8) - SetFormat(PixelFormat::Y_F32); + set_format(PixelFormat::Y_F32); old_fmt = m_data->m_format; /* Set the new active pixel format */ m_data->m_format = fmt; - ivec2 size = GetSize(); - int count = size.x * size.y; + ivec2 isize = size(); + int count = isize.x * isize.y; /* If we never used this format, allocate a new buffer: we will * obviously need it. */ @@ -131,17 +131,17 @@ void image::SetFormat(PixelFormat fmt) case PixelFormat::Unknown: break; case PixelFormat::Y_8: - data = new PixelData(size); break; + data = new PixelData(isize); break; case PixelFormat::RGB_8: - data = new PixelData(size); break; + data = new PixelData(isize); break; case PixelFormat::RGBA_8: - data = new PixelData(size); break; + data = new PixelData(isize); break; case PixelFormat::Y_F32: - data = new PixelData(size); break; + data = new PixelData(isize); break; case PixelFormat::RGB_F32: - data = new PixelData(size); break; + data = new PixelData(isize); break; case PixelFormat::RGBA_F32: - data = new PixelData(size); break; + data = new PixelData(isize); break; } #if __GNUC__ #pragma GCC diagnostic pop @@ -314,31 +314,31 @@ void image::SetFormat(PixelFormat fmt) #if 0 init_tables(); - for (int y = 0; y < size.y; y++) - for (int x = 0; x < size.x; x++) + for (int y = 0; y < isize.y; y++) + for (int x = 0; x < isize.x; x++) for (i = 0; i < 4; i++) { double p, e; uint8_t d; - p = src[4 * (y * size.x + x) + i]; + p = src[4 * (y * isize.x + x) + i]; if (p < 0.) d = 0.; else if (p > 1.) d = 255; else d = (int)(255.999 * pow(p, 1. / global_gamma)); - dest[4 * (y * size.x + x) + i] = d; + dest[4 * (y * isize.x + x) + i] = d; e = (p - u8tof32(d)) / 16; - if (x < size.x - 1) - src[4 * (y * size.x + x + 1) + i] += e * 7; - if (y < size.y - 1) + if (x < isize.x - 1) + src[4 * (y * isize.x + x + 1) + i] += e * 7; + if (y < isize.y - 1) { if (x > 0) - src[4 * ((y + 1) * size.x + x - 1) + i] += e * 3; - src[4 * ((y + 1) * size.x + x) + i] += e * 5; - if (x < size.x - 1) - src[4 * ((y + 1) * size.x + x + 1) + i] += e; + src[4 * ((y + 1) * isize.x + x - 1) + i] += e * 3; + src[4 * ((y + 1) * isize.x + x) + i] += e * 5; + if (x < isize.x - 1) + src[4 * ((y + 1) * isize.x + x + 1) + i] += e; } } #endif diff --git a/src/image/resample.cpp b/src/image/resample.cpp index 55cad2d6..1d4f6437 100644 --- a/src/image/resample.cpp +++ b/src/image/resample.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2004-2014 Sam Hocevar -// 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 © 2004—2017 Sam Hocevar +// +// 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. // #include @@ -35,10 +37,10 @@ image image::Resize(ivec2 size, ResampleAlgorithm algorithm) static image ResizeBicubic(image &src, ivec2 size) { image dst(size); - ivec2 const oldsize = src.GetSize(); + ivec2 const oldsize = src.size(); - vec4 const *srcp = src.Lock(); - vec4 *dstp = dst.Lock(); + vec4 const *srcp = src.lock(); + vec4 *dstp = dst.lock(); float scalex = size.x > 1 ? (oldsize.x - 1.f) / (size.x - 1) : 1.f; float scaley = size.y > 1 ? (oldsize.y - 1.f) / (size.y - 1) : 1.f; @@ -121,8 +123,8 @@ static image ResizeBicubic(image &src, ivec2 size) } } - dst.Unlock(dstp); - src.Unlock(srcp); + dst.unlock(dstp); + src.unlock(srcp); return dst; } @@ -137,11 +139,11 @@ static image ResizeBicubic(image &src, ivec2 size) static image ResizeBresenham(image &src, ivec2 size) { image dst(size); - ivec2 const oldsize = src.GetSize(); + ivec2 const oldsize = src.size(); float const invswsh = 1.0f / (oldsize.x * oldsize.y); - vec4 const *srcp = src.Lock(); - vec4 *dstp = dst.Lock(); + vec4 const *srcp = src.lock(); + vec4 *dstp = dst.lock(); array aline, line; aline.resize(size.x); @@ -198,8 +200,8 @@ static image ResizeBresenham(image &src, ivec2 size) dstp[y * size.x + x] = aline[x] * invswsh; } - dst.Unlock(dstp); - src.Unlock(srcp); + dst.unlock(dstp); + src.unlock(srcp); return dst; } diff --git a/src/lol/image/image.h b/src/lol/image/image.h index 1ec2ffed..80391d76 100644 --- a/src/lol/image/image.h +++ b/src/lol/image/image.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -76,46 +76,52 @@ public: void DummyFill(); void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt); void Copy(image const &other); - bool Load(char const *path); - bool Save(char const *path); + bool load(char const *path); + bool save(char const *path); /* Low level access */ - ivec2 GetSize() const; - void SetSize(ivec2); + ivec2 size() const; + void resize(ivec2); - PixelFormat GetFormat() const; - void SetFormat(PixelFormat fmt); + PixelFormat format() const; + void set_format(PixelFormat fmt); WrapMode GetWrapX() const; WrapMode GetWrapY() const; void SetWrap(WrapMode wrap_x, WrapMode wrap_y); /* Lock continuous arrays of pixels for writing */ - template typename PixelType::type *Lock(); - void *Lock(); - void Unlock(void const *pixels); + template typename PixelType::type *lock(); + void *lock(); + void unlock(void const *pixels); /* Lock 2D arrays of pixels for writing */ template - inline array2d::type> &Lock2D() + inline array2d::type> &lock2d() { /* Hack: this indirection is needed because of a Visual Studio ICE */ - return *(array2d::type> *)Lock2DHelper(T); + return *(array2d::type> *)lock2d_helper(T); } template - void Unlock2D(array2d const &); + void unlock2d(array2d const &); /* Image processing kernels */ - static array2d BayerKernel(ivec2 size); - static array2d HalftoneKernel(ivec2 size); - static array2d BlueNoiseKernel(ivec2 size, - ivec2 gsize = ivec2(7, 7)); - static array2d EdiffKernel(EdiffAlgorithm algorithm); - static array2d NormalizeKernel(array2d const &kernel); - static array2d GaussianKernel(vec2 radius, - float angle = 0.f, - vec2 delta = vec2(0.f, 0.f)); + struct kernel + { + kernel() = delete; + + static array2d normalize(array2d const &kernel); + + static array2d bayer(ivec2 size); + static array2d halftone(ivec2 size); + static array2d blue_noise(ivec2 size, + ivec2 gsize = ivec2(7, 7)); + static array2d ediff(EdiffAlgorithm algorithm); + static array2d gaussian(vec2 radius, + float angle = 0.f, + vec2 delta = vec2(0.f, 0.f)); + }; /* Rendering */ bool RenderRandom(ivec2 size); @@ -141,13 +147,13 @@ public: image YUVToRGB() const; /* Dithering */ - image DitherRandom() const; - image DitherEdiff(array2d const &kernel, - ScanMode scan = ScanMode::Raster) const; - image DitherOstromoukhov(ScanMode scan = ScanMode::Raster) const; - image DitherOrdered(array2d const &kernel) const; - image DitherHalftone(float radius, float angle) const; - image DitherDbs() const; + image dither_random() const; + image dither_ediff(array2d const &kernel, + ScanMode scan = ScanMode::Raster) const; + image dither_ostromoukhov(ScanMode scan = ScanMode::Raster) const; + image dither_ordered(array2d const &kernel) const; + image dither_halftone(float radius, float angle) const; + image dither_dbs() const; /* Combine images */ static image Merge(image &src1, image &src2, float alpha); @@ -163,7 +169,7 @@ public: static image Difference(image &src1, image &src2); private: - void *Lock2DHelper(PixelFormat T); + void *lock2d_helper(PixelFormat T); class image_data *m_data; }; diff --git a/src/lol/sys/file.h b/src/lol/sys/file.h index 1d0e2bd6..4800eb66 100644 --- a/src/lol/sys/file.h +++ b/src/lol/sys/file.h @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2013 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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 @@ -81,7 +83,7 @@ public: int WriteString(const String &buf); long int GetPosFromStart(); void SetPosFromStart(long int pos); - long int GetSize(); + long int size(); long int GetModificationTime(); private: diff --git a/src/sys/file.cpp b/src/sys/file.cpp index 1c97425f..182dd9a4 100644 --- a/src/sys/file.cpp +++ b/src/sys/file.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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. // #include @@ -182,7 +184,7 @@ class FileData #endif } - long int GetSize() + long int size() { #if __ANDROID__ return 0; @@ -321,9 +323,9 @@ void File::SetPosFromStart(long int pos) } //-- -long int File::GetSize() +long int File::size() { - return m_data->GetSize(); + return m_data->size(); } //-- diff --git a/src/sys/threadtypes.cpp b/src/sys/threadtypes.cpp index fb729fc5..10b37bab 100644 --- a/src/sys/threadtypes.cpp +++ b/src/sys/threadtypes.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // © 2014—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -175,7 +175,7 @@ public: protected: virtual bool DoWork() { - return m_image.Load(m_path.C()); + return m_image.load(m_path.C()); } String m_path; diff --git a/src/t/image/image.cpp b/src/t/image/image.cpp index ee8edbaa..92015075 100644 --- a/src/t/image/image.cpp +++ b/src/t/image/image.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Unit tests // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -23,13 +23,13 @@ lolunit_declare_fixture(image_test) { lolunit_declare_test(open_image) { - Image image("data/gradient.png"); + image img("data/gradient.png"); - ivec2 size = image.GetSize(); - lolunit_assert_equal(size.x, 256); - lolunit_assert_equal(size.y, 16); + ivec2 isize = img.size(); + lolunit_assert_equal(isize.x, 256); + lolunit_assert_equal(isize.y, 16); - u8vec4 *data = image.Lock(); + u8vec4 *data = img.lock(); lolunit_assert(data); lolunit_assert_equal((int)data[0].r, 0x00); @@ -40,7 +40,7 @@ lolunit_declare_fixture(image_test) lolunit_assert_equal((int)data[255].g, 0xff); lolunit_assert_equal((int)data[255].b, 0xff); - image.Unlock(data); + img.unlock(data); } }; diff --git a/src/textureimage.cpp b/src/textureimage.cpp index 1ef46289..e87beeb0 100644 --- a/src/textureimage.cpp +++ b/src/textureimage.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// 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—2017 Sam Hocevar +// +// 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. // #include @@ -44,10 +46,10 @@ TextureImage::TextureImage(char const *path) Init(path); } -TextureImage::TextureImage(char const *path, Image* image) +TextureImage::TextureImage(char const *path, image* img) : m_data(GetNewData()) { - Init(path, image); + Init(path, img); } TextureImage::~TextureImage() @@ -66,19 +68,19 @@ void TextureImage::Init(char const *path, ResourceCodecData* loaded_data) auto image_data = dynamic_cast(loaded_data); if (image_data != nullptr) { - Init(path, new Image(*image_data->m_image)); + Init(path, new image(*image_data->m_image)); } delete image_data; } -void TextureImage::Init(char const *path, Image* image) +void TextureImage::Init(char const *path, image* img) { m_data->m_name = String(" ") + path; m_data->m_texture = nullptr; - m_data->m_image = image; - m_data->m_image_size = m_data->m_image->GetSize(); + m_data->m_image = img; + m_data->m_image_size = m_data->m_image->size(); m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), PotUp(m_data->m_image_size.y)); @@ -111,13 +113,13 @@ void TextureImage::TickDraw(float seconds, Scene &scene) m_data->m_texture = nullptr; } - PixelFormat format = m_data->m_image->GetFormat(); + PixelFormat format = m_data->m_image->format(); int planes = BytesPerPixel(format); int w = m_data->m_texture_size.x; int h = m_data->m_texture_size.y; - uint8_t *pixels = (uint8_t *)m_data->m_image->Lock(); + uint8_t *pixels = (uint8_t *)m_data->m_image->lock(); bool resized = false; if (w != m_data->m_image_size.x || h != m_data->m_image_size.y) { @@ -129,6 +131,7 @@ void TextureImage::TickDraw(float seconds, Scene &scene) pixels = tmp; resized = false; } + /* FIXME: no unlock? */ m_data->m_texture = new Texture(ivec2(w, h), format); m_data->m_texture->SetData(pixels); @@ -146,12 +149,12 @@ char const *TextureImage::GetName() return m_data->m_name.C(); } -void TextureImage::UpdateTexture(Image* image) +void TextureImage::UpdateTexture(image* img) { - m_data->m_image = image; - m_data->m_image_size = m_data->m_image->GetSize(); + m_data->m_image = img; + m_data->m_image_size = m_data->m_image->size(); m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), - PotUp(m_data->m_image_size.y)); + PotUp(m_data->m_image_size.y)); } Texture * TextureImage::GetTexture() @@ -164,12 +167,12 @@ Texture const * TextureImage::GetTexture() const return m_data->m_texture; } -Image * TextureImage::GetImage() +image * TextureImage::GetImage() { return m_data->m_image; } -Image const * TextureImage::GetImage() const +image const * TextureImage::GetImage() const { return m_data->m_image; }