mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Move Color.h from modules/graphics/ to common/
--HG-- branch : minor
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
// LOVE
|
||||
#include "common/int.h"
|
||||
#include "Color.h"
|
||||
#include "common/Color.h"
|
||||
|
||||
// C
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user