Move Color.h from modules/graphics/ to common/

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-08-01 23:53:44 -03:00
parent c11a4250e8
commit b129d49a6c
15 changed files with 41 additions and 49 deletions
+1 -1
View File
@@ -255,6 +255,7 @@ endfunction()
set(LOVE_SRC_COMMON
src/common/b64.cpp
src/common/b64.h
src/common/Color.h
src/common/config.h
src/common/Data.cpp
src/common/Data.h
@@ -474,7 +475,6 @@ set(LOVE_SRC_MODULE_GRAPHICS_ROOT
src/modules/graphics/Buffer.h
src/modules/graphics/Canvas.cpp
src/modules/graphics/Canvas.h
src/modules/graphics/Color.h
src/modules/graphics/depthstencil.cpp
src/modules/graphics/depthstencil.h
src/modules/graphics/Drawable.cpp
@@ -415,7 +415,6 @@
FA0B7D2B1A95902C000E1D17 /* wrap_Rasterizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B851A95902C000E1D17 /* wrap_Rasterizer.cpp */; };
FA0B7D2C1A95902C000E1D17 /* wrap_Rasterizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B851A95902C000E1D17 /* wrap_Rasterizer.cpp */; };
FA0B7D2D1A95902C000E1D17 /* wrap_Rasterizer.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B861A95902C000E1D17 /* wrap_Rasterizer.h */; };
FA0B7D2E1A95902C000E1D17 /* Color.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B881A95902C000E1D17 /* Color.h */; };
FA0B7D2F1A95902C000E1D17 /* Drawable.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B891A95902C000E1D17 /* Drawable.h */; };
FA0B7D301A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
FA0B7D311A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
@@ -925,6 +924,7 @@
FA620A371AA2F8DB005DB4C2 /* wrap_Texture.h in Headers */ = {isa = PBXBuildFile; fileRef = FA620A311AA2F8DB005DB4C2 /* wrap_Texture.h */; };
FA620A3A1AA305F6005DB4C2 /* types.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA620A391AA305F6005DB4C2 /* types.cpp */; };
FA620A3B1AA305F6005DB4C2 /* types.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA620A391AA305F6005DB4C2 /* types.cpp */; };
FA6BDE5C1F31725300786805 /* Color.h in Headers */ = {isa = PBXBuildFile; fileRef = FA6BDE5B1F31725300786805 /* Color.h */; };
FA7550A81AEBE276003E311E /* libluajit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA7550A71AEBE276003E311E /* libluajit.a */; };
FA76344A1E28722A0066EF9E /* StreamBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA7634481E28722A0066EF9E /* StreamBuffer.cpp */; };
FA76344B1E28722A0066EF9E /* StreamBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA7634481E28722A0066EF9E /* StreamBuffer.cpp */; };
@@ -1439,7 +1439,6 @@
FA0B7B841A95902C000E1D17 /* wrap_GlyphData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_GlyphData.h; sourceTree = "<group>"; };
FA0B7B851A95902C000E1D17 /* wrap_Rasterizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Rasterizer.cpp; sourceTree = "<group>"; };
FA0B7B861A95902C000E1D17 /* wrap_Rasterizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Rasterizer.h; sourceTree = "<group>"; };
FA0B7B881A95902C000E1D17 /* Color.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Color.h; sourceTree = "<group>"; };
FA0B7B891A95902C000E1D17 /* Drawable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Drawable.h; sourceTree = "<group>"; };
FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Graphics.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
FA0B7B8B1A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
@@ -1785,6 +1784,7 @@
FA620A301AA2F8DB005DB4C2 /* wrap_Texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Texture.cpp; sourceTree = "<group>"; };
FA620A311AA2F8DB005DB4C2 /* wrap_Texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Texture.h; sourceTree = "<group>"; };
FA620A391AA305F6005DB4C2 /* types.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = types.cpp; sourceTree = "<group>"; };
FA6BDE5B1F31725300786805 /* Color.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Color.h; sourceTree = "<group>"; };
FA7550A71AEBE276003E311E /* libluajit.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libluajit.a; sourceTree = "<group>"; };
FA7634481E28722A0066EF9E /* StreamBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamBuffer.cpp; sourceTree = "<group>"; };
FA7634491E28722A0066EF9E /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
@@ -2019,6 +2019,7 @@
FAA3A9AD1B7D465A00CED060 /* android.h */,
FA0B78F71A958E3B000E1D17 /* b64.cpp */,
FA0B78F81A958E3B000E1D17 /* b64.h */,
FA6BDE5B1F31725300786805 /* Color.h */,
FA0B78F91A958E3B000E1D17 /* config.h */,
FA9D8DD41DEF8411002CD881 /* Data.cpp */,
FA0B78FA1A958E3B000E1D17 /* Data.h */,
@@ -2650,7 +2651,6 @@
FADF53F71E3C7ACD00012CC0 /* Buffer.h */,
FA1BA0A51E16F20600AA2803 /* Canvas.cpp */,
FA1BA0A61E16F20600AA2803 /* Canvas.h */,
FA0B7B881A95902C000E1D17 /* Color.h */,
FAF1889E1E9DBC4B008C1479 /* depthstencil.cpp */,
FAF1889D1E9DBBC8008C1479 /* depthstencil.h */,
FA9D8DDC1DEF842A002CD881 /* Drawable.cpp */,
@@ -3655,6 +3655,7 @@
FA0B7E771A95902C000E1D17 /* wrap_WeldJoint.h in Headers */,
FA0B7A911A958EA3000E1D17 /* b2FrictionJoint.h in Headers */,
FA0B7E291A95902C000E1D17 /* PulleyJoint.h in Headers */,
FA6BDE5C1F31725300786805 /* Color.h in Headers */,
FA0B7D471A95902C000E1D17 /* ParticleSystem.h in Headers */,
FA0B7E231A95902C000E1D17 /* PolygonShape.h in Headers */,
FA0B791E1A958E3B000E1D17 /* config.h in Headers */,
@@ -3861,7 +3862,6 @@
FA9D8DD31DEB56C3002CD881 /* pixelformat.h in Headers */,
FAF140A61E20934C00F898D2 /* ScanContext.h in Headers */,
FA0B7E4A1A95902C000E1D17 /* wrap_DistanceJoint.h in Headers */,
FA0B7D2E1A95902C000E1D17 /* Color.h in Headers */,
FA0B7A6A1A958EA3000E1D17 /* b2TimeStep.h in Headers */,
FA0B7A281A958EA3000E1D17 /* Box2D.h in Headers */,
FA0B7DE41A95902C000E1D17 /* wrap_RandomGenerator.h in Headers */,
@@ -18,13 +18,11 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_COLOR_H
#define LOVE_GRAPHICS_COLOR_H
#ifndef LOVE_COLOR_H
#define LOVE_COLOR_H
namespace love
{
namespace graphics
{
template <typename T>
struct ColorT
@@ -153,7 +151,6 @@ inline Colorf toColorf(Color c)
return Colorf(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f);
}
} // graphics
} // love
#endif // LOVE_GRAPHICS_COLOR_H
#endif // LOVE_COLOR_H
+11 -9
View File
@@ -146,7 +146,12 @@ BMFontRasterizer::BMFontRasterizer(love::filesystem::FileData *fontdef, const st
// The parseConfig function will try to load any missing page images.
for (int i = 0; i < (int) imagelist.size(); i++)
{
if (imagelist[i]->getFormat() != PIXELFORMAT_RGBA8)
throw love::Exception("Only 32-bit RGBA images are supported in BMFonts.");
images[i] = imagelist[i];
}
std::string configtext((const char *) fontdef->getData(), fontdef->getSize());
@@ -296,29 +301,26 @@ GlyphData *BMFontRasterizer::getGlyphData(uint32 glyph) const
return new GlyphData(glyph, GlyphMetrics(), PIXELFORMAT_RGBA8);
const BMFontCharacter &c = it->second;
GlyphData *g = new GlyphData(glyph, c.metrics, PIXELFORMAT_RGBA8);
const auto &imagepair = images.find(c.page);
if (imagepair == images.end())
{
g->release();
return new GlyphData(glyph, GlyphMetrics(), PIXELFORMAT_RGBA8);
}
image::ImageData *imagedata = imagepair->second.get();
GlyphData *g = new GlyphData(glyph, c.metrics, PIXELFORMAT_RGBA8);
size_t pixelsize = imagedata->getPixelSize();
image::pixel *pixels = (image::pixel *) g->getData();
const image::pixel *ipixels = (const image::pixel *) imagedata->getData();
uint8 *pixels = (uint8 *) g->getData();
const uint8 *ipixels = (const uint8 *) imagedata->getData();
love::thread::Lock lock(imagedata->getMutex());
// Copy the subsection of the texture from the ImageData to the GlyphData.
for (int y = 0; y < c.metrics.height; y++)
{
size_t idindex = (c.y + y) * imagedata->getWidth() + c.x;
memcpy(&pixels[y * c.metrics.width], &ipixels[idindex], pixelsize * c.metrics.width);
size_t idindex = ((c.y + y) * imagedata->getWidth() + c.x) * pixelsize;
memcpy(&pixels[y * c.metrics.width * pixelsize], &ipixels[idindex], pixelsize * c.metrics.width);
}
return g;
+9 -12
View File
@@ -29,10 +29,7 @@ namespace love
namespace font
{
inline bool equal(const love::image::pixel &a, const love::image::pixel &b)
{
return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a);
}
static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!");
ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float pixeldensity)
: imageData(data)
@@ -79,17 +76,17 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const
// We don't want another thread modifying our ImageData mid-copy.
love::thread::Lock lock(imageData->getMutex());
love::image::pixel *gdpixels = (love::image::pixel *) g->getData();
love::image::pixel *imagepixels = (love::image::pixel *) imageData->getData();
Color *gdpixels = (Color *) g->getData();
const Color *imagepixels = (const Color *) imageData->getData();
// copy glyph pixels from imagedata to glyphdata
for (int i = 0; i < g->getWidth() * g->getHeight(); i++)
{
love::image::pixel p = imagepixels[it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width))];
Color p = imagepixels[it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width))];
// Use transparency instead of the spacer color
if (equal(p, spacer))
gdpixels[i].r = gdpixels[i].g = gdpixels[i].b = gdpixels[i].a = 0;
if (p == spacer)
gdpixels[i] = Color(0, 0, 0, 0);
else
gdpixels[i] = p;
}
@@ -99,7 +96,7 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const
void ImageRasterizer::load()
{
love::image::pixel *pixels = (love::image::pixel *) imageData->getData();
const Color *pixels = (const Color *) imageData->getData();
int imgw = imageData->getWidth();
int imgh = imageData->getHeight();
@@ -121,13 +118,13 @@ void ImageRasterizer::load()
start = end;
// Finds out where the first character starts
while (start < imgw && equal(pixels[start], spacer))
while (start < imgw && pixels[start] == spacer)
++start;
end = start;
// Find where glyph ends.
while (end < imgw && !equal(pixels[end], spacer))
while (end < imgw && pixels[end] != spacer)
++end;
if (start >= end)
+2 -2
View File
@@ -22,9 +22,9 @@
#define LOVE_FONT_IMAGE_RASTERIZER_H
// LOVE
#include "filesystem/File.h"
#include "font/Rasterizer.h"
#include "image/ImageData.h"
#include "common/Color.h"
#include <map>
@@ -76,7 +76,7 @@ private:
std::map<uint32, ImageGlyphData> imageGlyphs;
// Color used to identify glyph separation in the source ImageData
love::image::pixel spacer;
Color spacer;
}; // ImageRasterizer
+1 -1
View File
@@ -28,9 +28,9 @@
#include "common/Vector.h"
#include "common/Optional.h"
#include "common/int.h"
#include "common/Color.h"
#include "StreamBuffer.h"
#include "vertex.h"
#include "Color.h"
#include "Texture.h"
#include "Canvas.h"
#include "Font.h"
+1 -1
View File
@@ -25,8 +25,8 @@
#include "common/int.h"
#include "common/math.h"
#include "common/Vector.h"
#include "common/Color.h"
#include "Drawable.h"
#include "Color.h"
#include "Quad.h"
#include "Texture.h"
#include "Buffer.h"
+1 -1
View File
@@ -29,8 +29,8 @@
// LOVE
#include "common/math.h"
#include "common/Matrix.h"
#include "common/Color.h"
#include "Drawable.h"
#include "Color.h"
#include "Mesh.h"
#include "vertex.h"
+1 -1
View File
@@ -22,7 +22,7 @@
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
#include "common/config.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "common/int.h"
#include "graphics/Canvas.h"
#include "graphics/Volatile.h"
+1 -1
View File
@@ -31,7 +31,7 @@
// LOVE
#include "graphics/Graphics.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "image/Image.h"
#include "image/ImageData.h"
+1 -1
View File
@@ -25,7 +25,7 @@
#include "common/config.h"
#include "common/int.h"
#include "common/math.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "graphics/Texture.h"
#include "graphics/vertex.h"
#include "graphics/depthstencil.h"
+1 -1
View File
@@ -22,7 +22,7 @@
// LOVE
#include "common/int.h"
#include "Color.h"
#include "common/Color.h"
// C
#include <stddef.h>
-7
View File
@@ -38,13 +38,6 @@ namespace love
namespace image
{
// Pixel format structure.
struct pixel
{
// Red, green, blue, alpha.
unsigned char r, g, b, a;
};
union Pixel
{
uint8 rgba8[4];
+4 -1
View File
@@ -21,6 +21,7 @@
// LOVE
#include "STBHandler.h"
#include "image/ImageData.h"
#include "common/Color.h"
static void loveSTBIAssert(bool test, const char *teststr)
{
@@ -49,6 +50,8 @@ namespace image
namespace magpie
{
static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!");
bool STBHandler::canDecode(love::filesystem::FileData *data)
{
int w = 0;
@@ -144,7 +147,7 @@ FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, EncodedF
memcpy(encimg.data + headerlen, img.data, img.width * img.height * bpp);
// convert the pixels from RGBA to BGRA.
pixel *encodedpixels = (pixel *) (encimg.data + headerlen);
Color *encodedpixels = (Color *) (encimg.data + headerlen);
for (int y = 0; y < img.height; y++)
{
for (int x = 0; x < img.width; x++)