aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/3rdparty/base64/base64.h186
-rw-r--r--src/libjin/3rdparty/stb/stb_image.h1
-rw-r--r--src/libjin/Graphics/Bitmap.cpp11
-rw-r--r--src/libjin/Graphics/Bitmap.h5
-rw-r--r--src/libjin/Graphics/Graphics.h1
-rw-r--r--src/libjin/Graphics/Image.cpp11
-rw-r--r--src/libjin/Graphics/Image.h1
-rw-r--r--src/libjin/Graphics/Sprite.h4
-rw-r--r--src/libjin/Graphics/Texture.h6
9 files changed, 217 insertions, 9 deletions
diff --git a/src/libjin/3rdparty/base64/base64.h b/src/libjin/3rdparty/base64/base64.h
new file mode 100644
index 0000000..2519797
--- /dev/null
+++ b/src/libjin/3rdparty/base64/base64.h
@@ -0,0 +1,186 @@
+#ifndef BASE64_H
+#define BASE64_H
+
+#define BASE64_ENCODE_OUT_SIZE(s) ((unsigned int)((((s) + 2) / 3) * 4 + 1))
+#define BASE64_DECODE_OUT_SIZE(s) ((unsigned int)(((s) / 4) * 3))
+
+/*
+* out is null-terminated encode string.
+* return values is out length, exclusive terminating `\0'
+*/
+unsigned int
+base64_encode(const unsigned char *in, unsigned int inlen, char *out);
+
+/*
+* return values is out length
+*/
+unsigned int
+base64_decode(const char *in, unsigned int inlen, unsigned char *out);
+
+#endif /* BASE64_H */
+
+#ifdef BASE64_IMPLEMENT
+
+/* This is a public domain base64 implementation written by WEI Zhicheng. */
+
+#define BASE64_PAD '='
+
+/* BASE 64 encode table */
+static const char base64en[] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/',
+};
+
+/* ASCII order for BASE 64 decode, 255 in unused character */
+static const unsigned char base64de[] = {
+ /* nul, soh, stx, etx, eot, enq, ack, bel, */
+ 255, 255, 255, 255, 255, 255, 255, 255,
+
+ /* bs, ht, nl, vt, np, cr, so, si, */
+ 255, 255, 255, 255, 255, 255, 255, 255,
+
+ /* dle, dc1, dc2, dc3, dc4, nak, syn, etb, */
+ 255, 255, 255, 255, 255, 255, 255, 255,
+
+ /* can, em, sub, esc, fs, gs, rs, us, */
+ 255, 255, 255, 255, 255, 255, 255, 255,
+
+ /* sp, '!', '"', '#', '$', '%', '&', ''', */
+ 255, 255, 255, 255, 255, 255, 255, 255,
+
+ /* '(', ')', '*', '+', ',', '-', '.', '/', */
+ 255, 255, 255, 62, 255, 255, 255, 63,
+
+ /* '0', '1', '2', '3', '4', '5', '6', '7', */
+ 52, 53, 54, 55, 56, 57, 58, 59,
+
+ /* '8', '9', ':', ';', '<', '=', '>', '?', */
+ 60, 61, 255, 255, 255, 255, 255, 255,
+
+ /* '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', */
+ 255, 0, 1, 2, 3, 4, 5, 6,
+
+ /* 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', */
+ 7, 8, 9, 10, 11, 12, 13, 14,
+
+ /* 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', */
+ 15, 16, 17, 18, 19, 20, 21, 22,
+
+ /* 'X', 'Y', 'Z', '[', '\', ']', '^', '_', */
+ 23, 24, 25, 255, 255, 255, 255, 255,
+
+ /* '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', */
+ 255, 26, 27, 28, 29, 30, 31, 32,
+
+ /* 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', */
+ 33, 34, 35, 36, 37, 38, 39, 40,
+
+ /* 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', */
+ 41, 42, 43, 44, 45, 46, 47, 48,
+
+ /* 'x', 'y', 'z', '{', '|', '}', '~', del, */
+ 49, 50, 51, 255, 255, 255, 255, 255
+};
+
+unsigned int
+base64_encode(const unsigned char *in, unsigned int inlen, char *out)
+{
+ int s;
+ unsigned int i;
+ unsigned int j;
+ unsigned char c;
+ unsigned char l;
+
+ s = 0;
+ l = 0;
+ for (i = j = 0; i < inlen; i++) {
+ c = in[i];
+
+ switch (s) {
+ case 0:
+ s = 1;
+ out[j++] = base64en[(c >> 2) & 0x3F];
+ break;
+ case 1:
+ s = 2;
+ out[j++] = base64en[((l & 0x3) << 4) | ((c >> 4) & 0xF)];
+ break;
+ case 2:
+ s = 0;
+ out[j++] = base64en[((l & 0xF) << 2) | ((c >> 6) & 0x3)];
+ out[j++] = base64en[c & 0x3F];
+ break;
+ }
+ l = c;
+ }
+
+ switch (s) {
+ case 1:
+ out[j++] = base64en[(l & 0x3) << 4];
+ out[j++] = BASE64_PAD;
+ out[j++] = BASE64_PAD;
+ break;
+ case 2:
+ out[j++] = base64en[(l & 0xF) << 2];
+ out[j++] = BASE64_PAD;
+ break;
+ }
+
+ out[j] = 0;
+
+ return j;
+}
+
+unsigned int
+base64_decode(const char *in, unsigned int inlen, unsigned char *out)
+{
+ unsigned int i;
+ unsigned int j;
+ unsigned char c;
+
+ if (inlen & 0x3) {
+ return 0;
+ }
+
+ for (i = j = 0; i < inlen; i++) {
+ if (in[i] == BASE64_PAD) {
+ break;
+ }
+ if (in[i] < 0) {
+ return 0;
+ }
+
+ c = base64de[in[i]];
+ if (c == 255) {
+ return 0;
+ }
+
+ switch (i & 0x3) {
+ case 0:
+ out[j] = (c << 2) & 0xFF;
+ break;
+ case 1:
+ out[j++] |= (c >> 4) & 0x3;
+ out[j] = (c & 0xF) << 4;
+ break;
+ case 2:
+ out[j++] |= (c >> 2) & 0xF;
+ out[j] = (c & 0x3) << 6;
+ break;
+ case 3:
+ out[j++] |= c;
+ break;
+ }
+ }
+ out[j] = '\0';
+
+ return j;
+}
+
+#endif
diff --git a/src/libjin/3rdparty/stb/stb_image.h b/src/libjin/3rdparty/stb/stb_image.h
index 9624869..9938309 100644
--- a/src/libjin/3rdparty/stb/stb_image.h
+++ b/src/libjin/3rdparty/stb/stb_image.h
@@ -100,7 +100,6 @@ RECENT REVISION HISTORY:
Blazej Dariusz Roszkowski Gregory Mullen github:phprus
*/
-#define STB_IMAGE_IMPLEMENTATION
#ifndef STBI_INCLUDE_STB_IMAGE_H
#define STBI_INCLUDE_STB_IMAGE_H
diff --git a/src/libjin/Graphics/Bitmap.cpp b/src/libjin/Graphics/Bitmap.cpp
index acfde58..160fda2 100644
--- a/src/libjin/Graphics/Bitmap.cpp
+++ b/src/libjin/Graphics/Bitmap.cpp
@@ -1,4 +1,5 @@
#include "Bitmap.h"
+#define STB_IMAGE_IMPLEMENTATION
#include "../3rdparty/stb/stb_image.h"
#include "../Math/math.h"
@@ -9,6 +10,14 @@ namespace jin
namespace graphics
{
+ /* pixelbitmap */
+ Bitmap* Bitmap::createBitmap(const void* pixel, unsigned width, unsigned height)
+ {
+ Bitmap* bitmap = new Bitmap(width, height);
+ memcpy(bitmap->pixels, pixel, width*height * sizeof(Color));
+ return bitmap;
+ }
+
/*static*/ Bitmap* Bitmap::createBitmap(const void* imgData, size_t size)
{
if (imgData == nullptr)
@@ -48,7 +57,7 @@ namespace graphics
{
}
- Bitmap::Bitmap(int w, int h)
+ Bitmap::Bitmap(unsigned w, unsigned h)
{
width = w;
height = h;
diff --git a/src/libjin/Graphics/Bitmap.h b/src/libjin/Graphics/Bitmap.h
index 553d999..6264c37 100644
--- a/src/libjin/Graphics/Bitmap.h
+++ b/src/libjin/Graphics/Bitmap.h
@@ -15,6 +15,7 @@ namespace graphics
class Bitmap
{
public:
+ static Bitmap* createBitmap(const void* pixel, unsigned width, unsigned height);
static Bitmap* createBitmap(const void* imgData, size_t size);
static Bitmap* createBitmap(int w, int h, Color color = Color::BLACK);
static Bitmap* clone(const Bitmap* bitmap);
@@ -37,10 +38,10 @@ namespace graphics
protected:
Bitmap();
- Bitmap(int w, int h);
+ Bitmap(unsigned w, unsigned h);
Color * pixels;
- int width, height;
+ unsigned width, height;
};
diff --git a/src/libjin/Graphics/Graphics.h b/src/libjin/Graphics/Graphics.h
index 54889f9..199d2aa 100644
--- a/src/libjin/Graphics/Graphics.h
+++ b/src/libjin/Graphics/Graphics.h
@@ -10,6 +10,7 @@
#include "Shader.h"
#include "window.h"
#include "Bitmap.h"
+#include "Image.h"
#include "./Font/TTF.h"
#include "./Font/Text.h"
diff --git a/src/libjin/Graphics/Image.cpp b/src/libjin/Graphics/Image.cpp
index 6203395..5700f60 100644
--- a/src/libjin/Graphics/Image.cpp
+++ b/src/libjin/Graphics/Image.cpp
@@ -1,4 +1,5 @@
#include "../3rdparty/stb/stb_image.h"
+#include "../Filesystem/Filesystem.h"
#include "Image.h"
namespace jin
@@ -6,6 +7,8 @@ namespace jin
namespace graphics
{
+ using namespace filesystem;
+
/*static*/ Image* Image::createImage(const void* imgData, size_t size)
{
if (imgData == nullptr)
@@ -21,6 +24,14 @@ namespace graphics
return image;
}
+ Image* Image::createImage(const char* path)
+ {
+ Filesystem* fs = Filesystem::get();
+ Buffer buffer;
+ fs->read(path, &buffer);
+ return createImage(buffer.data, buffer.size);
+ }
+
Image::Image()
: Bitmap()
{
diff --git a/src/libjin/Graphics/Image.h b/src/libjin/Graphics/Image.h
index 29546cc..215ac34 100644
--- a/src/libjin/Graphics/Image.h
+++ b/src/libjin/Graphics/Image.h
@@ -13,6 +13,7 @@ namespace graphics
class Image : public Bitmap
{
public:
+ static Image* createImage(const char* path);
static Image* createImage(const void* imgData, size_t size);
~Image();
diff --git a/src/libjin/Graphics/Sprite.h b/src/libjin/Graphics/Sprite.h
index acb8264..0d73464 100644
--- a/src/libjin/Graphics/Sprite.h
+++ b/src/libjin/Graphics/Sprite.h
@@ -1,5 +1,5 @@
-#ifndef __LIBJIN_IMAGE_H
-#define __LIBJIN_IMAGE_H
+#ifndef __LIBJIN_SPRITE_H
+#define __LIBJIN_SPRITE_H
namespace jin
{
diff --git a/src/libjin/Graphics/Texture.h b/src/libjin/Graphics/Texture.h
index 8498666..1704ee7 100644
--- a/src/libjin/Graphics/Texture.h
+++ b/src/libjin/Graphics/Texture.h
@@ -1,5 +1,5 @@
-#ifndef __LIBJIN_IMAGE_H
-#define __LIBJIN_IMAGE_H
+#ifndef __LIBJIN_TEXTURE_H
+#define __LIBJIN_TEXTURE_H
#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER
@@ -28,4 +28,4 @@ namespace graphics
} // jin
#endif // LIBJIN_MODULES_RENDER
-#endif // __LIBJIN_IMAGE_H \ No newline at end of file
+#endif // __LIBJIN_TEXTURE_H \ No newline at end of file