diff --git a/Docs/changelog.txt b/Docs/changelog.txt
index e4eb9fc..0fce735 100644
--- a/Docs/changelog.txt
+++ b/Docs/changelog.txt
@@ -2,6 +2,31 @@
N'gine Changelog
--------------------------------------------------------------------------------
+2022-12-24 Ver.1.11.0-stable
+--------------------------------------------------------------------------------
+- Añadido el archivo de configuración de flags de compilación de N'gine.
+ Esto permite compilar la librería desconectando ciertas funcionalidades o
+ usando otras alternativas si se ha de desarrollar para plataformas con GPU's
+ de bajo rendimiento o dispositivos portátiles o en sistemas donde no se
+ dispone de las últimas versiones de las librerías usadas por N'gine.
+ Entre otros, es posible desconectar el uso del backbuffer (perdiendo ciertas
+ opciones de filtrado bilineal) o desconectar las funciones avanzadas de
+ audio de SFML, disponibles solo en las últimas versiones de la misma.
+- Actualizada la versión de LodePNG.
+- Añadidos los operadores += y -= a la clase Vector2 y sus derivadas.
+- Añadidos los operadores *= y /= a la clase Vector2 y sus derivadas.
+- Reescritura parcial de todas las herramientas para N'gine, para una mejor
+ detección de los parámetros y una apariencia más homogénea.
+- Reescritura parcial de todas las clases internas de N'gine, convirtiéndolas
+ en singletons al fin de evitar conflictos por algún descuido. La clase
+ NGN_Camera no se ha convertido, dado que en algún proyecto puede ser
+ necesario disponer de más de una instancia de esta clase.
+- N'gine, los templates y los ejemplos se han configurado para seguir la
+ norma C++ 17 (estándar).
+- Actualizados los ejemplos de sonido.
+
+
+
2022-07-29 Ver.1.10.0-beta
--------------------------------------------------------------------------------
- Optimizaciones en las rutinas de renderizado, en especial en las de fondos
diff --git a/Examples/01_texture_loading/Texture_Loading.cbp b/Examples/01_texture_loading/Texture_Loading.cbp
index 5d660bd..2f143f0 100644
--- a/Examples/01_texture_loading/Texture_Loading.cbp
+++ b/Examples/01_texture_loading/Texture_Loading.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/01_texture_loading/source/demo/demo.cpp b/Examples/01_texture_loading/source/demo/demo.cpp
index fbae33e..51490eb 100644
--- a/Examples/01_texture_loading/source/demo/demo.cpp
+++ b/Examples/01_texture_loading/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/01_texture_loading/source/demo/demo.h b/Examples/01_texture_loading/source/demo/demo.h
index 221b420..8ca12e7 100644
--- a/Examples/01_texture_loading/source/demo/demo.h
+++ b/Examples/01_texture_loading/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/01_texture_loading/source/main.cpp b/Examples/01_texture_loading/source/main.cpp
index 2bf5ea0..879bf1c 100644
--- a/Examples/01_texture_loading/source/main.cpp
+++ b/Examples/01_texture_loading/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de carga de texturas en formato PNG
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/02_move_textures/Move_Textures.cbp b/Examples/02_move_textures/Move_Textures.cbp
index 8eedf42..d24b518 100644
--- a/Examples/02_move_textures/Move_Textures.cbp
+++ b/Examples/02_move_textures/Move_Textures.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/02_move_textures/source/demo/demo.cpp b/Examples/02_move_textures/source/demo/demo.cpp
index a7993be..1921f95 100644
--- a/Examples/02_move_textures/source/demo/demo.cpp
+++ b/Examples/02_move_textures/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/02_move_textures/source/demo/demo.h b/Examples/02_move_textures/source/demo/demo.h
index b382273..8892fc7 100644
--- a/Examples/02_move_textures/source/demo/demo.h
+++ b/Examples/02_move_textures/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/02_move_textures/source/main.cpp b/Examples/02_move_textures/source/main.cpp
index 0154944..5448ca2 100644
--- a/Examples/02_move_textures/source/main.cpp
+++ b/Examples/02_move_textures/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de carga y movimiento de texturas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/03_tiled_backgrounds/Tiled_Backgrounds.cbp b/Examples/03_tiled_backgrounds/Tiled_Backgrounds.cbp
index 5b0d09a..6234258 100644
--- a/Examples/03_tiled_backgrounds/Tiled_Backgrounds.cbp
+++ b/Examples/03_tiled_backgrounds/Tiled_Backgrounds.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/03_tiled_backgrounds/source/demo/demo.cpp b/Examples/03_tiled_backgrounds/source/demo/demo.cpp
index 7fe4149..13f97fe 100644
--- a/Examples/03_tiled_backgrounds/source/demo/demo.cpp
+++ b/Examples/03_tiled_backgrounds/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/03_tiled_backgrounds/source/demo/demo.h b/Examples/03_tiled_backgrounds/source/demo/demo.h
index 29df05a..6886b45 100644
--- a/Examples/03_tiled_backgrounds/source/demo/demo.h
+++ b/Examples/03_tiled_backgrounds/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/03_tiled_backgrounds/source/main.cpp b/Examples/03_tiled_backgrounds/source/main.cpp
index 6ad8fe7..ac57a15 100644
--- a/Examples/03_tiled_backgrounds/source/main.cpp
+++ b/Examples/03_tiled_backgrounds/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de carga y scroll de fondos con tiles
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/04_sprites/Sprites.cbp b/Examples/04_sprites/Sprites.cbp
index 94a494c..421bce4 100644
--- a/Examples/04_sprites/Sprites.cbp
+++ b/Examples/04_sprites/Sprites.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/04_sprites/debug_log.txt b/Examples/04_sprites/debug_log.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/04_sprites/source/demo/demo.cpp b/Examples/04_sprites/source/demo/demo.cpp
index 433d6bd..e51e392 100644
--- a/Examples/04_sprites/source/demo/demo.cpp
+++ b/Examples/04_sprites/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/04_sprites/source/demo/demo.h b/Examples/04_sprites/source/demo/demo.h
index f84dc4a..8b6bf9a 100644
--- a/Examples/04_sprites/source/demo/demo.h
+++ b/Examples/04_sprites/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/04_sprites/source/main.cpp b/Examples/04_sprites/source/main.cpp
index 4845efa..d8ea230 100644
--- a/Examples/04_sprites/source/main.cpp
+++ b/Examples/04_sprites/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de Sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/05_text_layers/Text_Layers.cbp b/Examples/05_text_layers/Text_Layers.cbp
index 6a6047b..fefe01d 100644
--- a/Examples/05_text_layers/Text_Layers.cbp
+++ b/Examples/05_text_layers/Text_Layers.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/05_text_layers/debug_log.txt b/Examples/05_text_layers/debug_log.txt
deleted file mode 100644
index f73096a..0000000
--- a/Examples/05_text_layers/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-05-27 13:09:50] N'gine version 1.9.1-beta started successfully!
-[2022-05-27 13:09:56] Execution terminated.
diff --git a/Examples/05_text_layers/source/demo/demo.cpp b/Examples/05_text_layers/source/demo/demo.cpp
index 4df667d..39c1816 100644
--- a/Examples/05_text_layers/source/demo/demo.cpp
+++ b/Examples/05_text_layers/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/05_text_layers/source/demo/demo.h b/Examples/05_text_layers/source/demo/demo.h
index bc2392d..b59b8ef 100644
--- a/Examples/05_text_layers/source/demo/demo.h
+++ b/Examples/05_text_layers/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/05_text_layers/source/main.cpp b/Examples/05_text_layers/source/main.cpp
index 2e39536..d6534d6 100644
--- a/Examples/05_text_layers/source/main.cpp
+++ b/Examples/05_text_layers/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de las capas de texto
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/06_collision_maps/Collision_Maps.cbp b/Examples/06_collision_maps/Collision_Maps.cbp
index e650e72..2cab6bb 100644
--- a/Examples/06_collision_maps/Collision_Maps.cbp
+++ b/Examples/06_collision_maps/Collision_Maps.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/06_collision_maps/source/demo/demo.cpp b/Examples/06_collision_maps/source/demo/demo.cpp
index aba1e9e..c472c3f 100644
--- a/Examples/06_collision_maps/source/demo/demo.cpp
+++ b/Examples/06_collision_maps/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/06_collision_maps/source/demo/demo.h b/Examples/06_collision_maps/source/demo/demo.h
index 587edb5..f869159 100644
--- a/Examples/06_collision_maps/source/demo/demo.h
+++ b/Examples/06_collision_maps/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/06_collision_maps/source/main.cpp b/Examples/06_collision_maps/source/main.cpp
index effe000..d52d091 100644
--- a/Examples/06_collision_maps/source/main.cpp
+++ b/Examples/06_collision_maps/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de uso de los mapas de colisiones y hitbox de sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/07_sprites_hitbox/Sprites_Hitbox.cbp b/Examples/07_sprites_hitbox/Sprites_Hitbox.cbp
index 8fab546..20c5d59 100644
--- a/Examples/07_sprites_hitbox/Sprites_Hitbox.cbp
+++ b/Examples/07_sprites_hitbox/Sprites_Hitbox.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/07_sprites_hitbox/source/demo/demo.cpp b/Examples/07_sprites_hitbox/source/demo/demo.cpp
index 6454c54..8785936 100644
--- a/Examples/07_sprites_hitbox/source/demo/demo.cpp
+++ b/Examples/07_sprites_hitbox/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/07_sprites_hitbox/source/demo/demo.h b/Examples/07_sprites_hitbox/source/demo/demo.h
index 035178c..183ca9e 100644
--- a/Examples/07_sprites_hitbox/source/demo/demo.h
+++ b/Examples/07_sprites_hitbox/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/07_sprites_hitbox/source/main.cpp b/Examples/07_sprites_hitbox/source/main.cpp
index b0db59f..5cd95a7 100644
--- a/Examples/07_sprites_hitbox/source/main.cpp
+++ b/Examples/07_sprites_hitbox/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de deteccion de colisiones entre sprites por caja
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/08_sprites_pixel_perfect/Sprites_Pixel_Perfect.cbp b/Examples/08_sprites_pixel_perfect/Sprites_Pixel_Perfect.cbp
index fc5661b..37c5153 100644
--- a/Examples/08_sprites_pixel_perfect/Sprites_Pixel_Perfect.cbp
+++ b/Examples/08_sprites_pixel_perfect/Sprites_Pixel_Perfect.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/08_sprites_pixel_perfect/source/demo/demo.cpp b/Examples/08_sprites_pixel_perfect/source/demo/demo.cpp
index da3ca66..b27142b 100644
--- a/Examples/08_sprites_pixel_perfect/source/demo/demo.cpp
+++ b/Examples/08_sprites_pixel_perfect/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/08_sprites_pixel_perfect/source/demo/demo.h b/Examples/08_sprites_pixel_perfect/source/demo/demo.h
index 48e9c31..c7c83a8 100644
--- a/Examples/08_sprites_pixel_perfect/source/demo/demo.h
+++ b/Examples/08_sprites_pixel_perfect/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/08_sprites_pixel_perfect/source/main.cpp b/Examples/08_sprites_pixel_perfect/source/main.cpp
index 5e4931f..ee9f60d 100644
--- a/Examples/08_sprites_pixel_perfect/source/main.cpp
+++ b/Examples/08_sprites_pixel_perfect/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de colisiones "pixel perfect" entre sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/09_sound/Sound.cbp b/Examples/09_sound/Sound.cbp
index 929f6f7..d4ca9c9 100644
--- a/Examples/09_sound/Sound.cbp
+++ b/Examples/09_sound/Sound.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/09_sound/debug_log.txt b/Examples/09_sound/debug_log.txt
deleted file mode 100644
index 6d641eb..0000000
--- a/Examples/09_sound/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-07-28 18:59:33] N'gine version 1.10.0-beta started successfully!
-[2022-07-28 18:59:40] Execution terminated.
diff --git a/Examples/09_sound/source/demo/demo.cpp b/Examples/09_sound/source/demo/demo.cpp
index d37c833..db8f8c0 100644
--- a/Examples/09_sound/source/demo/demo.cpp
+++ b/Examples/09_sound/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -207,6 +207,7 @@ bool Demo::Load() {
// Carga el stream de musica
bgm = ngn->sound->OpenMusic("data/pululate.ogg", false, 50);
+ if (!bgm) return false;
// Carga correcta
return true;
diff --git a/Examples/09_sound/source/demo/demo.h b/Examples/09_sound/source/demo/demo.h
index 5ab3bf8..34d52de 100644
--- a/Examples/09_sound/source/demo/demo.h
+++ b/Examples/09_sound/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/09_sound/source/main.cpp b/Examples/09_sound/source/main.cpp
index 06e1e37..caed36b 100644
--- a/Examples/09_sound/source/main.cpp
+++ b/Examples/09_sound/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso del sonido
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/10_music_loop/Music_Loop.cbp b/Examples/10_music_loop/Music_Loop.cbp
index 9607a0a..d56be8c 100644
--- a/Examples/10_music_loop/Music_Loop.cbp
+++ b/Examples/10_music_loop/Music_Loop.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/10_music_loop/debug_log.txt b/Examples/10_music_loop/debug_log.txt
deleted file mode 100644
index 332f872..0000000
--- a/Examples/10_music_loop/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-05-22 12:14:31] N'gine version 1.9.0-beta started successfully!
-[2022-05-22 12:15:03] Execution terminated.
diff --git a/Examples/10_music_loop/source/demo/demo.cpp b/Examples/10_music_loop/source/demo/demo.cpp
index 7a167b2..53c35dd 100644
--- a/Examples/10_music_loop/source/demo/demo.cpp
+++ b/Examples/10_music_loop/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -201,6 +201,7 @@ bool Demo::Load() {
// Abre el stream de musica
bgm = ngn->sound->OpenMusic("data/mirrorball_loop.ogg", 13721);
+ if (!bgm) return false;
// Carga correcta
return true;
diff --git a/Examples/10_music_loop/source/demo/demo.h b/Examples/10_music_loop/source/demo/demo.h
index dcb5a11..4c3497a 100644
--- a/Examples/10_music_loop/source/demo/demo.h
+++ b/Examples/10_music_loop/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/10_music_loop/source/main.cpp b/Examples/10_music_loop/source/main.cpp
index 2ca8f48..2be80fd 100644
--- a/Examples/10_music_loop/source/main.cpp
+++ b/Examples/10_music_loop/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del cambio del punto de loop en una musica
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/11_camera/Camera.cbp b/Examples/11_camera/Camera.cbp
index f093b97..edcf51a 100644
--- a/Examples/11_camera/Camera.cbp
+++ b/Examples/11_camera/Camera.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/11_camera/debug_log.txt b/Examples/11_camera/debug_log.txt
deleted file mode 100644
index fa12469..0000000
--- a/Examples/11_camera/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-06-07 12:52:57] N'gine version 1.10.0-wip_0x01 started successfully!
-[2022-06-07 12:53:18] Execution terminated.
diff --git a/Examples/11_camera/source/demo/demo.cpp b/Examples/11_camera/source/demo/demo.cpp
index c9ee972..54217ce 100644
--- a/Examples/11_camera/source/demo/demo.cpp
+++ b/Examples/11_camera/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/11_camera/source/demo/demo.h b/Examples/11_camera/source/demo/demo.h
index 5103b95..ce8d51a 100644
--- a/Examples/11_camera/source/demo/demo.h
+++ b/Examples/11_camera/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/11_camera/source/main.cpp b/Examples/11_camera/source/main.cpp
index 6fb8111..e3ce3ee 100644
--- a/Examples/11_camera/source/main.cpp
+++ b/Examples/11_camera/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de la camara 2D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/12_canvas_forms/Canvas_Forms.cbp b/Examples/12_canvas_forms/Canvas_Forms.cbp
index 1a3b436..e893772 100644
--- a/Examples/12_canvas_forms/Canvas_Forms.cbp
+++ b/Examples/12_canvas_forms/Canvas_Forms.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/12_canvas_forms/source/demo/demo.cpp b/Examples/12_canvas_forms/source/demo/demo.cpp
index 047c6a9..3b6b9ec 100644
--- a/Examples/12_canvas_forms/source/demo/demo.cpp
+++ b/Examples/12_canvas_forms/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/12_canvas_forms/source/demo/demo.h b/Examples/12_canvas_forms/source/demo/demo.h
index c6837c9..deb69f7 100644
--- a/Examples/12_canvas_forms/source/demo/demo.h
+++ b/Examples/12_canvas_forms/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/12_canvas_forms/source/main.cpp b/Examples/12_canvas_forms/source/main.cpp
index 7118589..abc03f8 100644
--- a/Examples/12_canvas_forms/source/main.cpp
+++ b/Examples/12_canvas_forms/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de la capa de dibujado (canvas) para formas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/13_canvas_paint/Canvas_Paint.cbp b/Examples/13_canvas_paint/Canvas_Paint.cbp
index c99d96c..aa98222 100644
--- a/Examples/13_canvas_paint/Canvas_Paint.cbp
+++ b/Examples/13_canvas_paint/Canvas_Paint.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/13_canvas_paint/source/demo/demo.cpp b/Examples/13_canvas_paint/source/demo/demo.cpp
index 91108a8..10079c3 100644
--- a/Examples/13_canvas_paint/source/demo/demo.cpp
+++ b/Examples/13_canvas_paint/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/13_canvas_paint/source/demo/demo.h b/Examples/13_canvas_paint/source/demo/demo.h
index e08e7b8..caf25c1 100644
--- a/Examples/13_canvas_paint/source/demo/demo.h
+++ b/Examples/13_canvas_paint/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/13_canvas_paint/source/main.cpp b/Examples/13_canvas_paint/source/main.cpp
index b14f4b5..3f73bac 100644
--- a/Examples/13_canvas_paint/source/main.cpp
+++ b/Examples/13_canvas_paint/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de la capa de dibujado (canvas) para pintura
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/14_canvas_effects/Canvas_Effects.cbp b/Examples/14_canvas_effects/Canvas_Effects.cbp
index e5c653c..2c740ef 100644
--- a/Examples/14_canvas_effects/Canvas_Effects.cbp
+++ b/Examples/14_canvas_effects/Canvas_Effects.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/14_canvas_effects/source/demo/demo.cpp b/Examples/14_canvas_effects/source/demo/demo.cpp
index 97ce700..dbde98c 100644
--- a/Examples/14_canvas_effects/source/demo/demo.cpp
+++ b/Examples/14_canvas_effects/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/14_canvas_effects/source/demo/demo.h b/Examples/14_canvas_effects/source/demo/demo.h
index 8a18126..4d612cc 100644
--- a/Examples/14_canvas_effects/source/demo/demo.h
+++ b/Examples/14_canvas_effects/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/14_canvas_effects/source/main.cpp b/Examples/14_canvas_effects/source/main.cpp
index ddc1cc7..fc0de50 100644
--- a/Examples/14_canvas_effects/source/main.cpp
+++ b/Examples/14_canvas_effects/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de la capa de dibujado (canvas) para efectos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/15_viewport_clip/Viewport_Clip.cbp b/Examples/15_viewport_clip/Viewport_Clip.cbp
index e2cb532..354f459 100644
--- a/Examples/15_viewport_clip/Viewport_Clip.cbp
+++ b/Examples/15_viewport_clip/Viewport_Clip.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/15_viewport_clip/source/demo/demo.cpp b/Examples/15_viewport_clip/source/demo/demo.cpp
index 1641bf7..649d0cb 100644
--- a/Examples/15_viewport_clip/source/demo/demo.cpp
+++ b/Examples/15_viewport_clip/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/15_viewport_clip/source/demo/demo.h b/Examples/15_viewport_clip/source/demo/demo.h
index e5b4337..7c22605 100644
--- a/Examples/15_viewport_clip/source/demo/demo.h
+++ b/Examples/15_viewport_clip/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/15_viewport_clip/source/main.cpp b/Examples/15_viewport_clip/source/main.cpp
index fa7b44a..9b4638f 100644
--- a/Examples/15_viewport_clip/source/main.cpp
+++ b/Examples/15_viewport_clip/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de uso del recorte de area del viewport
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/16_multiple_viewports/Multiple_Viewports.cbp b/Examples/16_multiple_viewports/Multiple_Viewports.cbp
index a75a5dc..49a6dba 100644
--- a/Examples/16_multiple_viewports/Multiple_Viewports.cbp
+++ b/Examples/16_multiple_viewports/Multiple_Viewports.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/16_multiple_viewports/debug_log.txt b/Examples/16_multiple_viewports/debug_log.txt
deleted file mode 100644
index b358b5b..0000000
--- a/Examples/16_multiple_viewports/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-07-28 17:23:57] N'gine version 1.10.0-beta started successfully!
-[2022-07-28 17:24:14] Execution terminated.
diff --git a/Examples/16_multiple_viewports/source/demo/demo.cpp b/Examples/16_multiple_viewports/source/demo/demo.cpp
index 935d342..0a751bd 100644
--- a/Examples/16_multiple_viewports/source/demo/demo.cpp
+++ b/Examples/16_multiple_viewports/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/16_multiple_viewports/source/demo/demo.h b/Examples/16_multiple_viewports/source/demo/demo.h
index b25cc93..d231a00 100644
--- a/Examples/16_multiple_viewports/source/demo/demo.h
+++ b/Examples/16_multiple_viewports/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/16_multiple_viewports/source/main.cpp b/Examples/16_multiple_viewports/source/main.cpp
index 1b466a1..e654253 100644
--- a/Examples/16_multiple_viewports/source/main.cpp
+++ b/Examples/16_multiple_viewports/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de uso de varios viewports simultaneos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/17_render_to_texture/Render_to_Texture.cbp b/Examples/17_render_to_texture/Render_to_Texture.cbp
index 4dd0bf0..ce1e556 100644
--- a/Examples/17_render_to_texture/Render_to_Texture.cbp
+++ b/Examples/17_render_to_texture/Render_to_Texture.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/17_render_to_texture/debug_log.txt b/Examples/17_render_to_texture/debug_log.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/17_render_to_texture/source/demo/demo.cpp b/Examples/17_render_to_texture/source/demo/demo.cpp
index 71ef8ad..04f16b4 100644
--- a/Examples/17_render_to_texture/source/demo/demo.cpp
+++ b/Examples/17_render_to_texture/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/17_render_to_texture/source/demo/demo.h b/Examples/17_render_to_texture/source/demo/demo.h
index 4c37fcb..2da6bc3 100644
--- a/Examples/17_render_to_texture/source/demo/demo.h
+++ b/Examples/17_render_to_texture/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/17_render_to_texture/source/main.cpp b/Examples/17_render_to_texture/source/main.cpp
index cdf4c17..d4b00d5 100644
--- a/Examples/17_render_to_texture/source/main.cpp
+++ b/Examples/17_render_to_texture/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo de render de una escena a una textura
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/18_sprite_colliders/Sprite_Colliders.cbp b/Examples/18_sprite_colliders/Sprite_Colliders.cbp
index 0d8ca96..9fd6d83 100644
--- a/Examples/18_sprite_colliders/Sprite_Colliders.cbp
+++ b/Examples/18_sprite_colliders/Sprite_Colliders.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/18_sprite_colliders/source/demo/demo.cpp b/Examples/18_sprite_colliders/source/demo/demo.cpp
index fd833d3..f532e29 100644
--- a/Examples/18_sprite_colliders/source/demo/demo.cpp
+++ b/Examples/18_sprite_colliders/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
http://www.nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
diff --git a/Examples/18_sprite_colliders/source/demo/demo.h b/Examples/18_sprite_colliders/source/demo/demo.h
index 98028e6..d5ad7eb 100644
--- a/Examples/18_sprite_colliders/source/demo/demo.h
+++ b/Examples/18_sprite_colliders/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
http://www.nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
diff --git a/Examples/18_sprite_colliders/source/main.cpp b/Examples/18_sprite_colliders/source/main.cpp
index e3fb047..f51094f 100644
--- a/Examples/18_sprite_colliders/source/main.cpp
+++ b/Examples/18_sprite_colliders/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de multiples colisionadores en un Sprite
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
http://www.nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
diff --git a/Examples/19_blending_modes/Blending_Modes.cbp b/Examples/19_blending_modes/Blending_Modes.cbp
index e94a77c..c995aa6 100644
--- a/Examples/19_blending_modes/Blending_Modes.cbp
+++ b/Examples/19_blending_modes/Blending_Modes.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/19_blending_modes/source/demo/demo.cpp b/Examples/19_blending_modes/source/demo/demo.cpp
index 2035f48..b484adf 100644
--- a/Examples/19_blending_modes/source/demo/demo.cpp
+++ b/Examples/19_blending_modes/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Archivo de Demo (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/19_blending_modes/source/demo/demo.h b/Examples/19_blending_modes/source/demo/demo.h
index 88a10f3..821cc7e 100644
--- a/Examples/19_blending_modes/source/demo/demo.h
+++ b/Examples/19_blending_modes/source/demo/demo.h
@@ -4,11 +4,11 @@
Archivo de Demo (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -19,8 +19,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/19_blending_modes/source/main.cpp b/Examples/19_blending_modes/source/main.cpp
index 231cd76..bef33b6 100644
--- a/Examples/19_blending_modes/source/main.cpp
+++ b/Examples/19_blending_modes/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de los modos de mezcla
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/20_window_modes/Window_Modes.cbp b/Examples/20_window_modes/Window_Modes.cbp
index c8c6841..c31c99c 100644
--- a/Examples/20_window_modes/Window_Modes.cbp
+++ b/Examples/20_window_modes/Window_Modes.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/20_window_modes/source/demo/demo.cpp b/Examples/20_window_modes/source/demo/demo.cpp
index bb45c82..ef6920c 100644
--- a/Examples/20_window_modes/source/demo/demo.cpp
+++ b/Examples/20_window_modes/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo del uso de los modos de pantalla (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/20_window_modes/source/demo/demo.h b/Examples/20_window_modes/source/demo/demo.h
index 5fe430b..00adbbc 100644
--- a/Examples/20_window_modes/source/demo/demo.h
+++ b/Examples/20_window_modes/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo del uso de los modos de pantalla (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/20_window_modes/source/main.cpp b/Examples/20_window_modes/source/main.cpp
index ca8f483..5116834 100644
--- a/Examples/20_window_modes/source/main.cpp
+++ b/Examples/20_window_modes/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso de los modos de pantalla
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.cbp b/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.cbp
index 875270a..fd1fc0f 100644
--- a/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.cbp
+++ b/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.layout b/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.layout
deleted file mode 100644
index 222efec..0000000
--- a/Examples/21_canvas_3dtunnel/Canvas_3dTunnel.layout
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Examples/21_canvas_3dtunnel/debug_log.txt b/Examples/21_canvas_3dtunnel/debug_log.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/21_canvas_3dtunnel/source/demo/demo.cpp b/Examples/21_canvas_3dtunnel/source/demo/demo.cpp
index ebadf61..b2e8069 100644
--- a/Examples/21_canvas_3dtunnel/source/demo/demo.cpp
+++ b/Examples/21_canvas_3dtunnel/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo del uso del Canvas: Tunel 3D (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/21_canvas_3dtunnel/source/demo/demo.h b/Examples/21_canvas_3dtunnel/source/demo/demo.h
index 8573328..999a84a 100644
--- a/Examples/21_canvas_3dtunnel/source/demo/demo.h
+++ b/Examples/21_canvas_3dtunnel/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo del uso del Canvas: Tunel 3D (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/21_canvas_3dtunnel/source/main.cpp b/Examples/21_canvas_3dtunnel/source/main.cpp
index fabd40f..8ca7876 100644
--- a/Examples/21_canvas_3dtunnel/source/main.cpp
+++ b/Examples/21_canvas_3dtunnel/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso del Canvas: Tunel 3D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -21,8 +21,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/22_canvas_getpixel/Canvas_Getpixel.cbp b/Examples/22_canvas_getpixel/Canvas_Getpixel.cbp
index 54ad652..7272761 100644
--- a/Examples/22_canvas_getpixel/Canvas_Getpixel.cbp
+++ b/Examples/22_canvas_getpixel/Canvas_Getpixel.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/22_canvas_getpixel/source/demo/demo.cpp b/Examples/22_canvas_getpixel/source/demo/demo.cpp
index db479ae..d77c8a6 100644
--- a/Examples/22_canvas_getpixel/source/demo/demo.cpp
+++ b/Examples/22_canvas_getpixel/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo del uso del Canvas: GetPixel (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/22_canvas_getpixel/source/demo/demo.h b/Examples/22_canvas_getpixel/source/demo/demo.h
index 342fc43..9f83dc1 100644
--- a/Examples/22_canvas_getpixel/source/demo/demo.h
+++ b/Examples/22_canvas_getpixel/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo del uso del Canvas: GetPixel (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/22_canvas_getpixel/source/main.cpp b/Examples/22_canvas_getpixel/source/main.cpp
index 61c7d2c..6bb33b0 100644
--- a/Examples/22_canvas_getpixel/source/main.cpp
+++ b/Examples/22_canvas_getpixel/source/main.cpp
@@ -3,11 +3,11 @@
Ejemplo del uso del Canvas: GetPixel
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -21,8 +21,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/23_mask/Mask.cbp b/Examples/23_mask/Mask.cbp
index 5a80aac..04981c9 100644
--- a/Examples/23_mask/Mask.cbp
+++ b/Examples/23_mask/Mask.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/23_mask/debug_log.txt b/Examples/23_mask/debug_log.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/23_mask/source/demo/demo.cpp b/Examples/23_mask/source/demo/demo.cpp
index 4c95ca0..14638ae 100644
--- a/Examples/23_mask/source/demo/demo.cpp
+++ b/Examples/23_mask/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo del uso de mascaras (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/23_mask/source/demo/demo.h b/Examples/23_mask/source/demo/demo.h
index 097e626..aa2c620 100644
--- a/Examples/23_mask/source/demo/demo.h
+++ b/Examples/23_mask/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo del uso de mascaras (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/23_mask/source/main.cpp b/Examples/23_mask/source/main.cpp
index e5a5b54..2de148d 100644
--- a/Examples/23_mask/source/main.cpp
+++ b/Examples/23_mask/source/main.cpp
@@ -4,11 +4,11 @@
Ejemplo del uso de mascaras
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/24_surface_to_raw/Surface_to_RAW.cbp b/Examples/24_surface_to_raw/Surface_to_RAW.cbp
index e5b278f..ce3c5de 100644
--- a/Examples/24_surface_to_raw/Surface_to_RAW.cbp
+++ b/Examples/24_surface_to_raw/Surface_to_RAW.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/24_surface_to_raw/debug_log.txt b/Examples/24_surface_to_raw/debug_log.txt
deleted file mode 100644
index 0393cad..0000000
--- a/Examples/24_surface_to_raw/debug_log.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[2022-06-07 12:50:53] N'gine version 1.10.0-wip_0x01 started successfully!
-[2022-06-07 12:51:04] Execution terminated.
diff --git a/Examples/24_surface_to_raw/source/demo/demo.cpp b/Examples/24_surface_to_raw/source/demo/demo.cpp
index 9d6cb17..84265fa 100644
--- a/Examples/24_surface_to_raw/source/demo/demo.cpp
+++ b/Examples/24_surface_to_raw/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo de la captura del surface (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/24_surface_to_raw/source/demo/demo.h b/Examples/24_surface_to_raw/source/demo/demo.h
index 6be279a..4ec9d6d 100644
--- a/Examples/24_surface_to_raw/source/demo/demo.h
+++ b/Examples/24_surface_to_raw/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo de la captura del surface (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/24_surface_to_raw/source/main.cpp b/Examples/24_surface_to_raw/source/main.cpp
index b73951f..bbf48ee 100644
--- a/Examples/24_surface_to_raw/source/main.cpp
+++ b/Examples/24_surface_to_raw/source/main.cpp
@@ -4,11 +4,11 @@
Ejemplo de la captura del surface
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/25_raycast_point/Raycast_point.cbp b/Examples/25_raycast_point/Raycast_point.cbp
index 164fc86..bb5b20f 100644
--- a/Examples/25_raycast_point/Raycast_point.cbp
+++ b/Examples/25_raycast_point/Raycast_point.cbp
@@ -115,7 +115,7 @@
-
+
diff --git a/Examples/25_raycast_point/debug_log.txt b/Examples/25_raycast_point/debug_log.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/25_raycast_point/source/demo/demo.cpp b/Examples/25_raycast_point/source/demo/demo.cpp
index 5423d9c..969dbab 100644
--- a/Examples/25_raycast_point/source/demo/demo.cpp
+++ b/Examples/25_raycast_point/source/demo/demo.cpp
@@ -4,11 +4,11 @@
Ejemplo Raycast a un punto de un sprite (Programa)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/25_raycast_point/source/demo/demo.h b/Examples/25_raycast_point/source/demo/demo.h
index 34a8d49..6556564 100644
--- a/Examples/25_raycast_point/source/demo/demo.h
+++ b/Examples/25_raycast_point/source/demo/demo.h
@@ -4,11 +4,11 @@
Ejemplo Raycast a un punto de un sprite (Declaraciones)
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Examples/25_raycast_point/source/main.cpp b/Examples/25_raycast_point/source/main.cpp
index 14aa9d3..50156fb 100644
--- a/Examples/25_raycast_point/source/main.cpp
+++ b/Examples/25_raycast_point/source/main.cpp
@@ -4,11 +4,11 @@
Ejemplo Raycast a un punto de un sprite
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere N'gine 1.9.0-stable o superior
+ Requiere N'gine 1.11.0-stable o superior
Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
https://www.mingw-w64.org/
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Library/linux/_NGN_1.10.0-beta.x64.null b/Library/linux/_NGN_1.10.0-beta.x64.null
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/02_move_textures/debug_log.txt b/Library/linux/_NGN_1.11.0-stable.x64.null
similarity index 100%
rename from Examples/02_move_textures/debug_log.txt
rename to Library/linux/_NGN_1.11.0-stable.x64.null
diff --git a/Library/linux/include/config_flags.h b/Library/linux/include/config_flags.h
new file mode 100644
index 0000000..238dc3e
--- /dev/null
+++ b/Library/linux/include/config_flags.h
@@ -0,0 +1,124 @@
+/******************************************************************************
+
+ N'gine Lib for C++
+ *** Version 1.11.0-stable ***
+ FLAGS de configuracion de la libreria
+ La libreria debe compilarse para que estos FLAGS sean efectivos
+
+ Proyecto iniciado el 1 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
+ https://www.mingw-w64.org/
+
+ Requiere SDL2 (2.0.22) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SDL2_TTF (2.0.15) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SFML (2.5.1) - 64-bits
+ http://www.sfml-dev.org/
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+
+ N'gine se distribuye bajo la licencia CREATIVE COMMONS
+ "Attribution-NonCommercial 4.0 International"
+ https://creativecommons.org/licenses/by-nc/4.0/
+
+ You are free to:
+
+ - Share
+ copy and redistribute the material in any medium or format.
+ - Adapt
+ remix, transform, and build upon the material.
+
+ The licensor cannot revoke these freedoms as long as you follow
+ the license terms.
+
+ Under the following terms:
+
+ - Attribution
+ You must give appropriate credit, provide a link to the license,
+ and indicate if changes were made. You may do so in any reasonable
+ manner, but not in any way that suggests the licensor endorses you
+ or your use.
+
+ - NonCommercial
+ You may not use the material for commercial purposes.
+
+ - No additional restrictions
+ You may not apply legal terms or technological measures that
+ legally restrict others from doing anything the license permits.
+
+******************************************************************************/
+
+
+
+#ifndef CONFIG_FLAGS_H_INCLUDED
+#define CONFIG_FLAGS_H_INCLUDED
+
+
+
+/******************************************************************************
+
+ Flags de seleccion del sistema operativo de destino
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the target operating system
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define OS_WINDOWS
+//#define OS_LINUX
+
+
+/******************************************************************************
+
+ Flags de seleccion del tipo de binario (debug o release)
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the type of the binary (debug or release)
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define MODE_DEBUG
+//#define MODE_RELEASE
+
+
+/******************************************************************************
+
+ Flags de configuracion avanzados de N'gine
+ N'gine advanced configuration flags
+
+******************************************************************************/
+
+/*
+ Deshabilita las funciones avanzadas de sonido de SFML
+ Usar solo si se usa una version inferior a la 2.5.1.
+ Disables the advanced features of SFML audio library.
+ Use only if you're using a version under 2.5.1
+*/
+//#define DISABLE_SFML_AUDIO_ADVANCED_FEATURES
+
+/*
+ Deshabilita la funcion de backbuffer de N'gine.
+ Esto aumenta el rendimiento en mas de un 50% en GPU's de perfil bajo,
+ pero se pierde la opcion de filtrado bilineal en objetos y capas
+ por separado.
+ Disables the backbuffer feature of N'gine.
+ That speeds up to 50% in lowend GPU's, but also disables the option
+ of enable bilinear filtering in objects and layers separately.
+*/
+//#define DISABLE_BACKBUFFER
+
+
+
+#endif // CONFIG_FLAGS_H_INCLUDED
diff --git a/Library/linux/include/lodepng/lodepng.h b/Library/linux/include/lodepng/lodepng.h
index a386459..fdafc77 100644
--- a/Library/linux/include/lodepng/lodepng.h
+++ b/Library/linux/include/lodepng/lodepng.h
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
@@ -142,16 +161,24 @@ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,
/*
Load PNG from disk, from file with given name.
Same as the other decode functions, but instead takes a filename as input.
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
-/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -191,17 +218,26 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize,
/*
Converts raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode32_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
-/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode24_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -223,6 +259,9 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
/*
Converts PNG file from disk to raw pixel data in memory.
Same as the other decode functions, but instead takes a filename as input.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned decode(std::vector& out, unsigned& w, unsigned& h,
const std::string& filename,
@@ -243,7 +282,11 @@ unsigned encode(std::vector& out,
/*
Converts 32-bit RGBA raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned encode(const std::string& filename,
const unsigned char* in, unsigned w, unsigned h,
@@ -270,12 +313,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -341,8 +393,10 @@ typedef struct LodePNGColorMode {
The alpha channels must be set as well, set them to 255 for opaque images.
- When decoding, by default you can ignore this palette, since LodePNG already
- fills the palette colors in the pixels of the raw RGBA output.
+ When decoding, with the default settings you can ignore this palette, since
+ LodePNG already fills the palette colors in the pixels of the raw RGBA output,
+ but when decoding to the original PNG color mode it is needed to reconstruct
+ the colors.
The palette is only supported for color type 3.
*/
@@ -432,10 +486,12 @@ typedef struct LodePNGInfo {
with values truncated to the bit depth in the unsigned integer.
For grayscale and palette PNGs, the value is stored in background_r. The values
- in background_g and background_b are then unused.
+ in background_g and background_b are then unused. The decoder will set them
+ equal to background_r, the encoder ignores them in this case.
- So when decoding, you may get these in a different color mode than the one you requested
- for the raw pixels.
+ When decoding, you may get these in a different color mode than the one you requested
+ for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the
+ ones defined in the header of the PNG image, are used.
When encoding with auto_convert, you must use the color model defined in info_png.color for
these values. The encoder normally ignores info_png.color when auto_convert is on, but will
@@ -454,30 +510,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -496,7 +558,7 @@ typedef struct LodePNGInfo {
unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
/*
- Color profile related chunks: gAMA, cHRM, sRGB, iCPP
+ Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
@@ -559,6 +621,45 @@ typedef struct LodePNGInfo {
unsigned char* iccp_profile;
unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+ /*
+ sBIT chunk: significant bits. Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+ sample depth, such as 10 or 12.
+
+ Encoders using this value, when storing the pixel data, should use the most significant bits
+ of the data to store the original bits, and use a good sample depth scaling method such as
+ "left bit replication" to fill in the least significant bits, rather than fill zeroes.
+
+ Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right
+ shift the data to go back to the original bit depth, but decoders are also allowed to ignore
+ sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks
+ to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.
+
+ For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color
+ type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with
+ translucent palette values, or images with color key). The values that are used must be
+ greater than zero and smaller than or equal to the PNG bit depth.
+
+ The color type from the header in the PNG image defines these used and unused fields: if
+ decoding with a color mode conversion, such as always decoding to RGBA, this metadata still
+ only uses the color type of the original PNG, and may e.g. lack the alpha channel info
+ if the PNG was RGB. When encoding with auto_convert (as well as without), also always the
+ color model defined in info_png.color determines this.
+
+ NOTE: enabling sbit can hurt compression, because the encoder can then not always use
+ auto_convert to choose a more optimal color mode for the data, because the PNG format has
+ strict requirements for the allowed sbit values in combination with color modes.
+ For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel
+ color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.
+ */
+ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/
+ unsigned sbit_r; /*red or gray component of significant bits*/
+ unsigned sbit_g; /*green component of significant bits*/
+ unsigned sbit_b; /*blue component of significant bits*/
+ unsigned sbit_a; /*alpha component of significant bits*/
+
/* End of color profile related chunks */
@@ -639,8 +740,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -720,7 +832,11 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
- If colortype is 3, PLTE is _always_ created.*/
+ If colortype is 3, PLTE is always created. If color type is explicitely set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+ optimal color mode, because it cannot use grayscale color modes in this case*/
unsigned force_palette;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
/*add LodePNG identifier and version as a text chunk, for debugging*/
@@ -774,8 +890,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h,
#endif /*LODEPNG_COMPILE_DECODER*/
/*
-Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it
-read in the state. Returns error code on failure.
+Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)
+of the PNG file and outputs what it read in the state. Returns error code on failure.
Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const
to find the desired chunk type, and if non null use lodepng_inspect_chunk (with
chunk_pointer - start_of_file as pos).
@@ -950,6 +1066,9 @@ out: output parameter, contains pointer to loaded buffer.
outsize: output parameter, size of the allocated out buffer
filename: the path to the file to load
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);
@@ -960,6 +1079,9 @@ buffer: the buffer to write
buffersize: size of the buffer to write
filename: the path to the file to save to
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -1000,12 +1122,18 @@ unsigned encode(std::vector& out,
/*
Load a file from disk into an std::vector.
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory
*/
unsigned load_file(std::vector& buffer, const std::string& filename);
/*
Save the binary data in an std::vector to a file on disk. The file is overwritten
without warning.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned save_file(const std::vector& buffer, const std::string& filename);
#endif /* LODEPNG_COMPILE_DISK */
@@ -1041,7 +1169,7 @@ unsigned compress(std::vector& out, const std::vector (2^31)-1
[ ] partial decoding (stream processing)
[X] let the "isFullyOpaque" function check color keys and transparent palettes too
@@ -1168,18 +1296,16 @@ The following features are supported by the decoder:
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
+ sBIT: significant bits
1.2. features not supported
---------------------------
-The following features are _not_ supported:
+The following features are not (yet) supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
-*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
- sBIT
- hIST
- sPLT
+*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks
2. C and C++ version
@@ -1505,6 +1631,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1678,6 +1809,9 @@ try to fix it if the compiler is modern and standards compliant.
This decoder example shows the most basic usage of LodePNG. More complex
examples can be found on the LodePNG website.
+NOTE: these examples do not support wide-character filenames, you can use an
+external method to handle such files and encode or decode in-memory
+
10.1. decoder C++ example
-------------------------
@@ -1775,6 +1909,12 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 13 jun 2022: added support for the sBIT chunk.
+*) 09 jan 2022: minor decoder speed improvements.
+*) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.
@@ -1941,5 +2081,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
*/
diff --git a/Library/linux/include/ngn.h b/Library/linux/include/ngn.h
index f8ee42f..368bb1a 100644
--- a/Library/linux/include/ngn.h
+++ b/Library/linux/include/ngn.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -21,8 +21,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -64,16 +64,13 @@
-/*** Defines del proyecto (usar SOLO si no se usan los defines del proyecto de code::blocks ***/
-//#define OS_WINDOWS
-//#define OS_LINUX
-//#define MODE_DEBUG
-//#define MODE_RELEASE
-
/*** Includes ***/
+// FLAGS de configuracion de la libreria
+#include "config_flags.h"
+
// C++
#include // Tipos de datos INTXX_T de C++ 11
@@ -118,7 +115,7 @@ class NGN {
// Destructor
~NGN();
- // Punteros a las clases
+ // Punteros a los singletons de las clases
NGN_Log* log; // Mensages de depuracion
NGN_System* system; // Funciones del sistema
NGN_Math* math; // Funciones matematicas
@@ -126,13 +123,15 @@ class NGN {
NGN_Input* input; // Metodos de entrada
NGN_Graphics* graphics; // Gestion del Renderer de SDL
NGN_Render* render; // Dibuja los diferentes elementos graficos
- NGN_Camera* camera; // Camara virtual 2D integrada
NGN_Load* load; // Funciones para la carga de archivos
NGN_Collisions* collisions; // Funciones del sistema de colisiones
NGN_Sound* sound; // Gestion de los efectos de sonido
NGN_Image* image; // Manipulacion de imagenes en RAW
NGN_Disk* disk; // Gestion de archivos en el disco
+ // Punteros a los objetos
+ NGN_Camera* camera; // Camara virtual 2D integrada
+
// Iniciliaza la libreria
bool Init();
diff --git a/Library/linux/include/ngn_audio_clip.h b/Library/linux/include/ngn_audio_clip.h
index 6a7d070..a109c0a 100644
--- a/Library/linux/include/ngn_audio_clip.h
+++ b/Library/linux/include/ngn_audio_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_camera.h b/Library/linux/include/ngn_camera.h
index b8561c4..39de1df 100644
--- a/Library/linux/include/ngn_camera.h
+++ b/Library/linux/include/ngn_camera.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_canvas.h b/Library/linux/include/ngn_canvas.h
index 51b8bab..783d1b5 100644
--- a/Library/linux/include/ngn_canvas.h
+++ b/Library/linux/include/ngn_canvas.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_collisions.h b/Library/linux/include/ngn_collisions.h
index 90e7ea4..c1bcb6c 100644
--- a/Library/linux/include/ngn_collisions.h
+++ b/Library/linux/include/ngn_collisions.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -60,11 +60,14 @@ class NGN_Collisions {
// Public
public:
- // Constructor
- NGN_Collisions();
+ // Devuelve la instancia
+ static NGN_Collisions* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Collisions();
// Consulta el color de un pixel del mapa de colisiones
uint32_t GetPixel(NGN_CollisionMapData* cmap, int32_t position_x, int32_t position_y);
@@ -86,8 +89,18 @@ class NGN_Collisions {
// Private
private:
+ // Constructor
+ NGN_Collisions();
+
+ // Destructor
+ ~NGN_Collisions();
+
+ // Puntero de memoria a la instancia
+ static NGN_Collisions* instance;
+
+
// Algoritmo de colision por cajas
- bool CheckColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
+ bool CheckBoxColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
// Deteccion de colisiones entre sprites por "pixel perfect"
SDL_Surface* RenderSpriteInSurface(
diff --git a/Library/linux/include/ngn_defines.h b/Library/linux/include/ngn_defines.h
index c9199d8..f643490 100644
--- a/Library/linux/include/ngn_defines.h
+++ b/Library/linux/include/ngn_defines.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -59,9 +59,9 @@
/*** Version de N'gine ***/
static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 10; // Version menor
+static const int32_t NGN_VERSION_MINOR = 11; // Version menor
static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "beta"; // Version metadatos
+static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
/*** Definiciones generales ***/
static const int32_t NGN_DEFAULT_VALUE = 0x7FFFFFFF; // Valor de "defecto"
diff --git a/Library/linux/include/ngn_disk.h b/Library/linux/include/ngn_disk.h
index 8e9891b..2d7d07c 100644
--- a/Library/linux/include/ngn_disk.h
+++ b/Library/linux/include/ngn_disk.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de acceso al disco
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Disk {
public:
- // Constructor
- NGN_Disk();
+ // Devuelve la instancia
+ static NGN_Disk* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Disk();
// Lee un archivo en formato binario desde el disco y almacenalo en un buffer en RAM
int32_t ReadBinaryFile(std::string filepath, std::vector &buffer);
@@ -91,6 +94,16 @@ class NGN_Disk {
private:
+ // Constructor
+ NGN_Disk();
+
+ // Destructor
+ ~NGN_Disk();
+
+ // Puntero de memoria a la instancia
+ static NGN_Disk* instance;
+
+
// Genera una estructura de directorios
int32_t MakePath(std::string path);
diff --git a/Library/linux/include/ngn_filesystem.h b/Library/linux/include/ngn_filesystem.h
index 4a7cf66..696c233 100644
--- a/Library/linux/include/ngn_filesystem.h
+++ b/Library/linux/include/ngn_filesystem.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones del sistema de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_graphics.h b/Library/linux/include/ngn_graphics.h
index a49040e..95d9849 100644
--- a/Library/linux/include/ngn_graphics.h
+++ b/Library/linux/include/ngn_graphics.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -68,11 +68,14 @@ class NGN_Graphics {
// Public
public:
- // Contructor
- NGN_Graphics();
+ // Devuelve la instancia
+ static NGN_Graphics* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Graphics();
// Inicializa la ventana principal y la superficie de renderizado
bool Init(
@@ -91,7 +94,9 @@ class NGN_Graphics {
SDL_Window* window; // Puntero a la ventana
int32_t window_flags; // Control de los falgs de la ventana
SDL_Renderer* renderer; // Puntero al renderer
- SDL_Texture* backbuffer; // Backbufer para el renderizado
+ #if !defined (DISABLE_BACKBUFFER)
+ SDL_Texture* backbuffer; // Backbufer para el renderizado
+ #endif
int8_t screen_mode; // Modo de pantalla actual
bool vsync; // VSYNC Activo?
@@ -180,10 +185,19 @@ class NGN_Graphics {
-
// Private
private:
+ // Contructor
+ NGN_Graphics();
+
+ // Destructor
+ ~NGN_Graphics();
+
+ // Puntero de memoria a la instancia
+ static NGN_Graphics* instance;
+
+
// Resolucion de pantalla completa
int32_t desktop_w;
int32_t desktop_h;
@@ -207,6 +221,8 @@ class NGN_Graphics {
void ChangeScreenMode();
// Cambio del VSYNC
void SetVsync();
+ // Cambio del modo de filtrado
+ void SetRenderScaleQuality();
// Gestion de los parametros del render
void UpdateRendererFlags();
@@ -227,7 +243,9 @@ class NGN_Graphics {
void GenerateRuntimeFrameId();
// Crea/actualiza el backbuffer del render
- void SetBackbuffer();
+ #if !defined (DISABLE_BACKBUFFER)
+ void SetBackbuffer();
+ #endif
// Manda el backbuffer a la pantalla
void RenderBackbuffer();
// Limpia el backbuffer
diff --git a/Library/linux/include/ngn_image.h b/Library/linux/include/ngn_image.h
index bcf47e3..cd2dcc0 100644
--- a/Library/linux/include/ngn_image.h
+++ b/Library/linux/include/ngn_image.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones para la manipulacion de imagenes en RAW
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -65,11 +65,14 @@ class NGN_Image {
public:
- // Constructor
- NGN_Image();
+ // Devuelve la instancia
+ static NGN_Image* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Image();
// Convierte una imagen RAW a datos de textura
NGN_TextureData* ConvertRawToTextureData(NGN_RawImage* raw);
@@ -98,6 +101,15 @@ class NGN_Image {
private:
+ // Constructor
+ NGN_Image();
+
+ // Destructor
+ ~NGN_Image();
+
+ // Puntero de memoria a la instancia
+ static NGN_Image* instance;
+
};
diff --git a/Library/linux/include/ngn_input.h b/Library/linux/include/ngn_input.h
index e287216..4e646c3 100644
--- a/Library/linux/include/ngn_input.h
+++ b/Library/linux/include/ngn_input.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -131,16 +131,27 @@ class NGN_Input {
public:
+ // Devuelve la instancia
+ static NGN_Input* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
+
+
+ private:
+
// Contructor
NGN_Input();
// Destructor
~NGN_Input();
+ // Puntero de memoria a la instancia
+ static NGN_Input* instance;
- private:
-
// Define las propiedades del game controller
struct controller_data {
bool available; // El controlador esta disponible?
diff --git a/Library/linux/include/ngn_load.h b/Library/linux/include/ngn_load.h
index 71317de..919282c 100644
--- a/Library/linux/include/ngn_load.h
+++ b/Library/linux/include/ngn_load.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -72,11 +72,14 @@ class NGN_Load {
// Public
public:
- // Contructor
- NGN_Load();
+ // Devuelve la instancia
+ static NGN_Load* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Load();
// Carga de texturas
NGN_TextureData* Texture(std::string filepath);
@@ -138,6 +141,16 @@ class NGN_Load {
// Private
private:
+ // Contructor
+ NGN_Load();
+
+ // Destructor
+ ~NGN_Load();
+
+ // Puntero de memoria a la instancia
+ static NGN_Load* instance;
+
+
// Objeto para el acceso al sistema de archivos
NGN_FileSystem* file_system;
diff --git a/Library/linux/include/ngn_log.h b/Library/linux/include/ngn_log.h
index a0b71a8..6f55f64 100644
--- a/Library/linux/include/ngn_log.h
+++ b/Library/linux/include/ngn_log.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de mensages de depuracion
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_Log {
public:
- // Constructor
- NGN_Log();
+ // Devuelve la instancia
+ static NGN_Log* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_Log();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Abre el archivo de registro
bool OpenLogFile(std::string log_file, bool overwrite = true);
@@ -79,10 +81,19 @@ class NGN_Log {
private:
+ // Constructor
+ NGN_Log();
+
+ // Destructor
+ ~NGN_Log();
+
+ // Puntero de memoria a la instancia
+ static NGN_Log* instance;
+
std::string _log_file; // Nombre del archivo de registro
bool _log_enabled; // Archivo de registro habilitado
- std::fstream file; // Stream de gestion del archivo de registro
+ std::fstream file; // Stream de gestion del archivo de registro
// Genera la marca de tiempo actual
std::string GetTimeStamp();
diff --git a/Library/linux/include/ngn_math.h b/Library/linux/include/ngn_math.h
index 16fb92d..7301881 100644
--- a/Library/linux/include/ngn_math.h
+++ b/Library/linux/include/ngn_math.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones matematicas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -82,6 +82,10 @@ class Vector2 {
Vector2 operator/(float);
bool operator==(Vector2);
bool operator!=(Vector2);
+ void operator+=(Vector2);
+ void operator-=(Vector2);
+ void operator*=(float);
+ void operator/=(float);
private:
@@ -109,6 +113,10 @@ class Vector2I32 {
Vector2I32 operator/(int32_t);
bool operator==(Vector2I32);
bool operator!=(Vector2I32);
+ void operator+=(Vector2I32);
+ void operator-=(Vector2I32);
+ void operator*=(int32_t);
+ void operator/=(int32_t);
private:
@@ -136,6 +144,10 @@ class Vector2I64 {
Vector2I64 operator/(int64_t);
bool operator==(Vector2I64);
bool operator!=(Vector2I64);
+ void operator+=(Vector2I64);
+ void operator-=(Vector2I64);
+ void operator*=(int64_t);
+ void operator/=(int64_t);
private:
@@ -150,11 +162,13 @@ class NGN_Math {
// Segmento publico
public:
- // Contructor de la clase
- NGN_Math();
+ // Devuelve la instancia
+ static NGN_Math* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_Math();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Distancia entre 2 puntos (4 parametros, punto flotante, 1a sobrecarga)
@@ -186,6 +200,14 @@ class NGN_Math {
// Segmento privado
private:
+ // Contructor de la clase
+ NGN_Math();
+
+ // Destructor de la clase
+ ~NGN_Math();
+
+ // Puntero de memoria a la instancia
+ static NGN_Math* instance;
};
diff --git a/Library/linux/include/ngn_music_clip.h b/Library/linux/include/ngn_music_clip.h
index 5edb8aa..85ccac8 100644
--- a/Library/linux/include/ngn_music_clip.h
+++ b/Library/linux/include/ngn_music_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_render.h b/Library/linux/include/ngn_render.h
index bdab099..51b69ce 100644
--- a/Library/linux/include/ngn_render.h
+++ b/Library/linux/include/ngn_render.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Render {
// Public
public:
- // Constructor
- NGN_Render();
+ // Devuelve la instancia
+ static NGN_Render* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Render();
// Dibuja una textura en la surface del renderer
void Texture(NGN_Texture* texture, float position_x = (float)NGN_DEFAULT_VALUE, float position_y = (float)NGN_DEFAULT_VALUE);
@@ -105,6 +108,16 @@ class NGN_Render {
// Private
private:
+ // Constructor
+ NGN_Render();
+
+ // Destructor
+ ~NGN_Render();
+
+ // Puntero de memoria a la instancia
+ static NGN_Render* instance;
+
+
bool render2texture; // Flag de render to texture
NGN_Texture* rend2text; // Textura de destino del render
diff --git a/Library/linux/include/ngn_sound.h b/Library/linux/include/ngn_sound.h
index 9ac1db4..4d86dcb 100644
--- a/Library/linux/include/ngn_sound.h
+++ b/Library/linux/include/ngn_sound.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sonido
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -86,11 +86,14 @@ class NGN_Sound {
// Public
public:
- // Constructor de la clase
- NGN_Sound();
+ // Devuelve la instancia
+ static NGN_Sound* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor de la clase
- ~NGN_Sound();
/*** Efectos de sonido (SFX) [64 simultaneos maximo por defecto] ***/
@@ -242,6 +245,16 @@ class NGN_Sound {
// Private
private:
+ // Constructor de la clase
+ NGN_Sound();
+
+ // Destructor de la clase
+ ~NGN_Sound();
+
+ // Puntero de memoria a la instancia
+ static NGN_Sound* instance;
+
+
// Lista de sonidos disponibles
std::vector sfx_cue;
diff --git a/Library/linux/include/ngn_sprite.h b/Library/linux/include/ngn_sprite.h
index 2a0975f..895b85a 100644
--- a/Library/linux/include/ngn_sprite.h
+++ b/Library/linux/include/ngn_sprite.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_system.h b/Library/linux/include/ngn_system.h
index 24b4062..698a487 100644
--- a/Library/linux/include/ngn_system.h
+++ b/Library/linux/include/ngn_system.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de sistema
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_System {
// Public
public:
- // Contructor
- NGN_System();
+ // Devuelve la instancia
+ static NGN_System* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_System();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Inicializa la libreria
bool Init();
@@ -93,6 +95,15 @@ class NGN_System {
// Private
private:
+ // Contructor
+ NGN_System();
+
+ // Destructor
+ ~NGN_System();
+
+ // Puntero de memoria a la instancia
+ static NGN_System* instance;
+
// Resetea los flags y variables antes de leer el evento
void ResetFlags();
diff --git a/Library/linux/include/ngn_text_layer.h b/Library/linux/include/ngn_text_layer.h
index ab8c608..3b37761 100644
--- a/Library/linux/include/ngn_text_layer.h
+++ b/Library/linux/include/ngn_text_layer.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Text Layer - Capa de texto con soporte TTF
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_texture.h b/Library/linux/include/ngn_texture.h
index b92e4b8..3f3ce88 100644
--- a/Library/linux/include/ngn_texture.h
+++ b/Library/linux/include/ngn_texture.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Fondos con texturas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_tiledbg.h b/Library/linux/include/ngn_tiledbg.h
index 77030ab..3f14fc0 100644
--- a/Library/linux/include/ngn_tiledbg.h
+++ b/Library/linux/include/ngn_tiledbg.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Fondos Tileados
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/linux/include/ngn_toolbox.h b/Library/linux/include/ngn_toolbox.h
index a045473..f5d5260 100644
--- a/Library/linux/include/ngn_toolbox.h
+++ b/Library/linux/include/ngn_toolbox.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
TOOL BOX - Caja de herramientas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -73,11 +73,13 @@ class NGN_ToolBox {
// Segmento publico
public:
- // Constructor de la clase
- NGN_ToolBox();
+ // Devuelve la instancia
+ static NGN_ToolBox* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_ToolBox();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
/*** Cadenas de texto ***/
@@ -98,6 +100,15 @@ class NGN_ToolBox {
// Segmento privado
private:
+ // Constructor de la clase
+ NGN_ToolBox();
+
+ // Destructor de la clase
+ ~NGN_ToolBox();
+
+ // Puntero de memoria a la instancia
+ static NGN_ToolBox* instance;
+
// Constantes de conversion a UTF-8 (2 bytes)
// El primer byte en la codificacion en 2 bytes empieza con 110 y contiene 5 bits de datos
const uint8_t utf8_b0_head = 0xC0; // 1100 0000
diff --git a/Library/linux/lib/libngn.a b/Library/linux/lib/libngn.a
index 4e4781c..2aedae7 100644
Binary files a/Library/linux/lib/libngn.a and b/Library/linux/lib/libngn.a differ
diff --git a/Library/linux/lib/libngn_d.a b/Library/linux/lib/libngn_d.a
index f95eb69..d6745e3 100644
Binary files a/Library/linux/lib/libngn_d.a and b/Library/linux/lib/libngn_d.a differ
diff --git a/Library/windows/_NGN_1.10.0-beta.x64.null b/Library/windows/_NGN_1.10.0-beta.x64.null
deleted file mode 100644
index e69de29..0000000
diff --git a/Examples/03_tiled_backgrounds/debug_log.txt b/Library/windows/_NGN_1.11.0-stable.x64.null
similarity index 100%
rename from Examples/03_tiled_backgrounds/debug_log.txt
rename to Library/windows/_NGN_1.11.0-stable.x64.null
diff --git a/Library/windows/include/config_flags.h b/Library/windows/include/config_flags.h
new file mode 100644
index 0000000..238dc3e
--- /dev/null
+++ b/Library/windows/include/config_flags.h
@@ -0,0 +1,124 @@
+/******************************************************************************
+
+ N'gine Lib for C++
+ *** Version 1.11.0-stable ***
+ FLAGS de configuracion de la libreria
+ La libreria debe compilarse para que estos FLAGS sean efectivos
+
+ Proyecto iniciado el 1 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
+ https://www.mingw-w64.org/
+
+ Requiere SDL2 (2.0.22) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SDL2_TTF (2.0.15) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SFML (2.5.1) - 64-bits
+ http://www.sfml-dev.org/
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+
+ N'gine se distribuye bajo la licencia CREATIVE COMMONS
+ "Attribution-NonCommercial 4.0 International"
+ https://creativecommons.org/licenses/by-nc/4.0/
+
+ You are free to:
+
+ - Share
+ copy and redistribute the material in any medium or format.
+ - Adapt
+ remix, transform, and build upon the material.
+
+ The licensor cannot revoke these freedoms as long as you follow
+ the license terms.
+
+ Under the following terms:
+
+ - Attribution
+ You must give appropriate credit, provide a link to the license,
+ and indicate if changes were made. You may do so in any reasonable
+ manner, but not in any way that suggests the licensor endorses you
+ or your use.
+
+ - NonCommercial
+ You may not use the material for commercial purposes.
+
+ - No additional restrictions
+ You may not apply legal terms or technological measures that
+ legally restrict others from doing anything the license permits.
+
+******************************************************************************/
+
+
+
+#ifndef CONFIG_FLAGS_H_INCLUDED
+#define CONFIG_FLAGS_H_INCLUDED
+
+
+
+/******************************************************************************
+
+ Flags de seleccion del sistema operativo de destino
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the target operating system
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define OS_WINDOWS
+//#define OS_LINUX
+
+
+/******************************************************************************
+
+ Flags de seleccion del tipo de binario (debug o release)
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the type of the binary (debug or release)
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define MODE_DEBUG
+//#define MODE_RELEASE
+
+
+/******************************************************************************
+
+ Flags de configuracion avanzados de N'gine
+ N'gine advanced configuration flags
+
+******************************************************************************/
+
+/*
+ Deshabilita las funciones avanzadas de sonido de SFML
+ Usar solo si se usa una version inferior a la 2.5.1.
+ Disables the advanced features of SFML audio library.
+ Use only if you're using a version under 2.5.1
+*/
+//#define DISABLE_SFML_AUDIO_ADVANCED_FEATURES
+
+/*
+ Deshabilita la funcion de backbuffer de N'gine.
+ Esto aumenta el rendimiento en mas de un 50% en GPU's de perfil bajo,
+ pero se pierde la opcion de filtrado bilineal en objetos y capas
+ por separado.
+ Disables the backbuffer feature of N'gine.
+ That speeds up to 50% in lowend GPU's, but also disables the option
+ of enable bilinear filtering in objects and layers separately.
+*/
+//#define DISABLE_BACKBUFFER
+
+
+
+#endif // CONFIG_FLAGS_H_INCLUDED
diff --git a/Library/windows/include/lodepng/lodepng.h b/Library/windows/include/lodepng/lodepng.h
index a386459..fdafc77 100644
--- a/Library/windows/include/lodepng/lodepng.h
+++ b/Library/windows/include/lodepng/lodepng.h
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
@@ -142,16 +161,24 @@ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,
/*
Load PNG from disk, from file with given name.
Same as the other decode functions, but instead takes a filename as input.
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
-/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -191,17 +218,26 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize,
/*
Converts raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode32_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
-/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode24_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -223,6 +259,9 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
/*
Converts PNG file from disk to raw pixel data in memory.
Same as the other decode functions, but instead takes a filename as input.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned decode(std::vector& out, unsigned& w, unsigned& h,
const std::string& filename,
@@ -243,7 +282,11 @@ unsigned encode(std::vector& out,
/*
Converts 32-bit RGBA raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned encode(const std::string& filename,
const unsigned char* in, unsigned w, unsigned h,
@@ -270,12 +313,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -341,8 +393,10 @@ typedef struct LodePNGColorMode {
The alpha channels must be set as well, set them to 255 for opaque images.
- When decoding, by default you can ignore this palette, since LodePNG already
- fills the palette colors in the pixels of the raw RGBA output.
+ When decoding, with the default settings you can ignore this palette, since
+ LodePNG already fills the palette colors in the pixels of the raw RGBA output,
+ but when decoding to the original PNG color mode it is needed to reconstruct
+ the colors.
The palette is only supported for color type 3.
*/
@@ -432,10 +486,12 @@ typedef struct LodePNGInfo {
with values truncated to the bit depth in the unsigned integer.
For grayscale and palette PNGs, the value is stored in background_r. The values
- in background_g and background_b are then unused.
+ in background_g and background_b are then unused. The decoder will set them
+ equal to background_r, the encoder ignores them in this case.
- So when decoding, you may get these in a different color mode than the one you requested
- for the raw pixels.
+ When decoding, you may get these in a different color mode than the one you requested
+ for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the
+ ones defined in the header of the PNG image, are used.
When encoding with auto_convert, you must use the color model defined in info_png.color for
these values. The encoder normally ignores info_png.color when auto_convert is on, but will
@@ -454,30 +510,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -496,7 +558,7 @@ typedef struct LodePNGInfo {
unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
/*
- Color profile related chunks: gAMA, cHRM, sRGB, iCPP
+ Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
@@ -559,6 +621,45 @@ typedef struct LodePNGInfo {
unsigned char* iccp_profile;
unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+ /*
+ sBIT chunk: significant bits. Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+ sample depth, such as 10 or 12.
+
+ Encoders using this value, when storing the pixel data, should use the most significant bits
+ of the data to store the original bits, and use a good sample depth scaling method such as
+ "left bit replication" to fill in the least significant bits, rather than fill zeroes.
+
+ Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right
+ shift the data to go back to the original bit depth, but decoders are also allowed to ignore
+ sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks
+ to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.
+
+ For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color
+ type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with
+ translucent palette values, or images with color key). The values that are used must be
+ greater than zero and smaller than or equal to the PNG bit depth.
+
+ The color type from the header in the PNG image defines these used and unused fields: if
+ decoding with a color mode conversion, such as always decoding to RGBA, this metadata still
+ only uses the color type of the original PNG, and may e.g. lack the alpha channel info
+ if the PNG was RGB. When encoding with auto_convert (as well as without), also always the
+ color model defined in info_png.color determines this.
+
+ NOTE: enabling sbit can hurt compression, because the encoder can then not always use
+ auto_convert to choose a more optimal color mode for the data, because the PNG format has
+ strict requirements for the allowed sbit values in combination with color modes.
+ For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel
+ color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.
+ */
+ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/
+ unsigned sbit_r; /*red or gray component of significant bits*/
+ unsigned sbit_g; /*green component of significant bits*/
+ unsigned sbit_b; /*blue component of significant bits*/
+ unsigned sbit_a; /*alpha component of significant bits*/
+
/* End of color profile related chunks */
@@ -639,8 +740,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -720,7 +832,11 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
- If colortype is 3, PLTE is _always_ created.*/
+ If colortype is 3, PLTE is always created. If color type is explicitely set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+ optimal color mode, because it cannot use grayscale color modes in this case*/
unsigned force_palette;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
/*add LodePNG identifier and version as a text chunk, for debugging*/
@@ -774,8 +890,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h,
#endif /*LODEPNG_COMPILE_DECODER*/
/*
-Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it
-read in the state. Returns error code on failure.
+Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)
+of the PNG file and outputs what it read in the state. Returns error code on failure.
Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const
to find the desired chunk type, and if non null use lodepng_inspect_chunk (with
chunk_pointer - start_of_file as pos).
@@ -950,6 +1066,9 @@ out: output parameter, contains pointer to loaded buffer.
outsize: output parameter, size of the allocated out buffer
filename: the path to the file to load
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);
@@ -960,6 +1079,9 @@ buffer: the buffer to write
buffersize: size of the buffer to write
filename: the path to the file to save to
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -1000,12 +1122,18 @@ unsigned encode(std::vector& out,
/*
Load a file from disk into an std::vector.
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory
*/
unsigned load_file(std::vector& buffer, const std::string& filename);
/*
Save the binary data in an std::vector to a file on disk. The file is overwritten
without warning.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned save_file(const std::vector& buffer, const std::string& filename);
#endif /* LODEPNG_COMPILE_DISK */
@@ -1041,7 +1169,7 @@ unsigned compress(std::vector& out, const std::vector (2^31)-1
[ ] partial decoding (stream processing)
[X] let the "isFullyOpaque" function check color keys and transparent palettes too
@@ -1168,18 +1296,16 @@ The following features are supported by the decoder:
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
+ sBIT: significant bits
1.2. features not supported
---------------------------
-The following features are _not_ supported:
+The following features are not (yet) supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
-*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
- sBIT
- hIST
- sPLT
+*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks
2. C and C++ version
@@ -1505,6 +1631,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1678,6 +1809,9 @@ try to fix it if the compiler is modern and standards compliant.
This decoder example shows the most basic usage of LodePNG. More complex
examples can be found on the LodePNG website.
+NOTE: these examples do not support wide-character filenames, you can use an
+external method to handle such files and encode or decode in-memory
+
10.1. decoder C++ example
-------------------------
@@ -1775,6 +1909,12 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 13 jun 2022: added support for the sBIT chunk.
+*) 09 jan 2022: minor decoder speed improvements.
+*) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.
@@ -1941,5 +2081,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
*/
diff --git a/Library/windows/include/ngn.h b/Library/windows/include/ngn.h
index f8ee42f..368bb1a 100644
--- a/Library/windows/include/ngn.h
+++ b/Library/windows/include/ngn.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -21,8 +21,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -64,16 +64,13 @@
-/*** Defines del proyecto (usar SOLO si no se usan los defines del proyecto de code::blocks ***/
-//#define OS_WINDOWS
-//#define OS_LINUX
-//#define MODE_DEBUG
-//#define MODE_RELEASE
-
/*** Includes ***/
+// FLAGS de configuracion de la libreria
+#include "config_flags.h"
+
// C++
#include // Tipos de datos INTXX_T de C++ 11
@@ -118,7 +115,7 @@ class NGN {
// Destructor
~NGN();
- // Punteros a las clases
+ // Punteros a los singletons de las clases
NGN_Log* log; // Mensages de depuracion
NGN_System* system; // Funciones del sistema
NGN_Math* math; // Funciones matematicas
@@ -126,13 +123,15 @@ class NGN {
NGN_Input* input; // Metodos de entrada
NGN_Graphics* graphics; // Gestion del Renderer de SDL
NGN_Render* render; // Dibuja los diferentes elementos graficos
- NGN_Camera* camera; // Camara virtual 2D integrada
NGN_Load* load; // Funciones para la carga de archivos
NGN_Collisions* collisions; // Funciones del sistema de colisiones
NGN_Sound* sound; // Gestion de los efectos de sonido
NGN_Image* image; // Manipulacion de imagenes en RAW
NGN_Disk* disk; // Gestion de archivos en el disco
+ // Punteros a los objetos
+ NGN_Camera* camera; // Camara virtual 2D integrada
+
// Iniciliaza la libreria
bool Init();
diff --git a/Library/windows/include/ngn_audio_clip.h b/Library/windows/include/ngn_audio_clip.h
index 6a7d070..a109c0a 100644
--- a/Library/windows/include/ngn_audio_clip.h
+++ b/Library/windows/include/ngn_audio_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_camera.h b/Library/windows/include/ngn_camera.h
index b8561c4..39de1df 100644
--- a/Library/windows/include/ngn_camera.h
+++ b/Library/windows/include/ngn_camera.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_canvas.h b/Library/windows/include/ngn_canvas.h
index 51b8bab..783d1b5 100644
--- a/Library/windows/include/ngn_canvas.h
+++ b/Library/windows/include/ngn_canvas.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_collisions.h b/Library/windows/include/ngn_collisions.h
index 90e7ea4..c1bcb6c 100644
--- a/Library/windows/include/ngn_collisions.h
+++ b/Library/windows/include/ngn_collisions.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -60,11 +60,14 @@ class NGN_Collisions {
// Public
public:
- // Constructor
- NGN_Collisions();
+ // Devuelve la instancia
+ static NGN_Collisions* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Collisions();
// Consulta el color de un pixel del mapa de colisiones
uint32_t GetPixel(NGN_CollisionMapData* cmap, int32_t position_x, int32_t position_y);
@@ -86,8 +89,18 @@ class NGN_Collisions {
// Private
private:
+ // Constructor
+ NGN_Collisions();
+
+ // Destructor
+ ~NGN_Collisions();
+
+ // Puntero de memoria a la instancia
+ static NGN_Collisions* instance;
+
+
// Algoritmo de colision por cajas
- bool CheckColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
+ bool CheckBoxColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
// Deteccion de colisiones entre sprites por "pixel perfect"
SDL_Surface* RenderSpriteInSurface(
diff --git a/Library/windows/include/ngn_defines.h b/Library/windows/include/ngn_defines.h
index c9199d8..f643490 100644
--- a/Library/windows/include/ngn_defines.h
+++ b/Library/windows/include/ngn_defines.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -59,9 +59,9 @@
/*** Version de N'gine ***/
static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 10; // Version menor
+static const int32_t NGN_VERSION_MINOR = 11; // Version menor
static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "beta"; // Version metadatos
+static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
/*** Definiciones generales ***/
static const int32_t NGN_DEFAULT_VALUE = 0x7FFFFFFF; // Valor de "defecto"
diff --git a/Library/windows/include/ngn_disk.h b/Library/windows/include/ngn_disk.h
index 8e9891b..2d7d07c 100644
--- a/Library/windows/include/ngn_disk.h
+++ b/Library/windows/include/ngn_disk.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de acceso al disco
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Disk {
public:
- // Constructor
- NGN_Disk();
+ // Devuelve la instancia
+ static NGN_Disk* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Disk();
// Lee un archivo en formato binario desde el disco y almacenalo en un buffer en RAM
int32_t ReadBinaryFile(std::string filepath, std::vector &buffer);
@@ -91,6 +94,16 @@ class NGN_Disk {
private:
+ // Constructor
+ NGN_Disk();
+
+ // Destructor
+ ~NGN_Disk();
+
+ // Puntero de memoria a la instancia
+ static NGN_Disk* instance;
+
+
// Genera una estructura de directorios
int32_t MakePath(std::string path);
diff --git a/Library/windows/include/ngn_filesystem.h b/Library/windows/include/ngn_filesystem.h
index 4a7cf66..696c233 100644
--- a/Library/windows/include/ngn_filesystem.h
+++ b/Library/windows/include/ngn_filesystem.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones del sistema de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_graphics.h b/Library/windows/include/ngn_graphics.h
index a49040e..95d9849 100644
--- a/Library/windows/include/ngn_graphics.h
+++ b/Library/windows/include/ngn_graphics.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -68,11 +68,14 @@ class NGN_Graphics {
// Public
public:
- // Contructor
- NGN_Graphics();
+ // Devuelve la instancia
+ static NGN_Graphics* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Graphics();
// Inicializa la ventana principal y la superficie de renderizado
bool Init(
@@ -91,7 +94,9 @@ class NGN_Graphics {
SDL_Window* window; // Puntero a la ventana
int32_t window_flags; // Control de los falgs de la ventana
SDL_Renderer* renderer; // Puntero al renderer
- SDL_Texture* backbuffer; // Backbufer para el renderizado
+ #if !defined (DISABLE_BACKBUFFER)
+ SDL_Texture* backbuffer; // Backbufer para el renderizado
+ #endif
int8_t screen_mode; // Modo de pantalla actual
bool vsync; // VSYNC Activo?
@@ -180,10 +185,19 @@ class NGN_Graphics {
-
// Private
private:
+ // Contructor
+ NGN_Graphics();
+
+ // Destructor
+ ~NGN_Graphics();
+
+ // Puntero de memoria a la instancia
+ static NGN_Graphics* instance;
+
+
// Resolucion de pantalla completa
int32_t desktop_w;
int32_t desktop_h;
@@ -207,6 +221,8 @@ class NGN_Graphics {
void ChangeScreenMode();
// Cambio del VSYNC
void SetVsync();
+ // Cambio del modo de filtrado
+ void SetRenderScaleQuality();
// Gestion de los parametros del render
void UpdateRendererFlags();
@@ -227,7 +243,9 @@ class NGN_Graphics {
void GenerateRuntimeFrameId();
// Crea/actualiza el backbuffer del render
- void SetBackbuffer();
+ #if !defined (DISABLE_BACKBUFFER)
+ void SetBackbuffer();
+ #endif
// Manda el backbuffer a la pantalla
void RenderBackbuffer();
// Limpia el backbuffer
diff --git a/Library/windows/include/ngn_image.h b/Library/windows/include/ngn_image.h
index bcf47e3..cd2dcc0 100644
--- a/Library/windows/include/ngn_image.h
+++ b/Library/windows/include/ngn_image.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones para la manipulacion de imagenes en RAW
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -65,11 +65,14 @@ class NGN_Image {
public:
- // Constructor
- NGN_Image();
+ // Devuelve la instancia
+ static NGN_Image* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Image();
// Convierte una imagen RAW a datos de textura
NGN_TextureData* ConvertRawToTextureData(NGN_RawImage* raw);
@@ -98,6 +101,15 @@ class NGN_Image {
private:
+ // Constructor
+ NGN_Image();
+
+ // Destructor
+ ~NGN_Image();
+
+ // Puntero de memoria a la instancia
+ static NGN_Image* instance;
+
};
diff --git a/Library/windows/include/ngn_input.h b/Library/windows/include/ngn_input.h
index e287216..4e646c3 100644
--- a/Library/windows/include/ngn_input.h
+++ b/Library/windows/include/ngn_input.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -131,16 +131,27 @@ class NGN_Input {
public:
+ // Devuelve la instancia
+ static NGN_Input* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
+
+
+ private:
+
// Contructor
NGN_Input();
// Destructor
~NGN_Input();
+ // Puntero de memoria a la instancia
+ static NGN_Input* instance;
- private:
-
// Define las propiedades del game controller
struct controller_data {
bool available; // El controlador esta disponible?
diff --git a/Library/windows/include/ngn_load.h b/Library/windows/include/ngn_load.h
index 71317de..919282c 100644
--- a/Library/windows/include/ngn_load.h
+++ b/Library/windows/include/ngn_load.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -72,11 +72,14 @@ class NGN_Load {
// Public
public:
- // Contructor
- NGN_Load();
+ // Devuelve la instancia
+ static NGN_Load* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Load();
// Carga de texturas
NGN_TextureData* Texture(std::string filepath);
@@ -138,6 +141,16 @@ class NGN_Load {
// Private
private:
+ // Contructor
+ NGN_Load();
+
+ // Destructor
+ ~NGN_Load();
+
+ // Puntero de memoria a la instancia
+ static NGN_Load* instance;
+
+
// Objeto para el acceso al sistema de archivos
NGN_FileSystem* file_system;
diff --git a/Library/windows/include/ngn_log.h b/Library/windows/include/ngn_log.h
index a0b71a8..6f55f64 100644
--- a/Library/windows/include/ngn_log.h
+++ b/Library/windows/include/ngn_log.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de mensages de depuracion
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_Log {
public:
- // Constructor
- NGN_Log();
+ // Devuelve la instancia
+ static NGN_Log* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_Log();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Abre el archivo de registro
bool OpenLogFile(std::string log_file, bool overwrite = true);
@@ -79,10 +81,19 @@ class NGN_Log {
private:
+ // Constructor
+ NGN_Log();
+
+ // Destructor
+ ~NGN_Log();
+
+ // Puntero de memoria a la instancia
+ static NGN_Log* instance;
+
std::string _log_file; // Nombre del archivo de registro
bool _log_enabled; // Archivo de registro habilitado
- std::fstream file; // Stream de gestion del archivo de registro
+ std::fstream file; // Stream de gestion del archivo de registro
// Genera la marca de tiempo actual
std::string GetTimeStamp();
diff --git a/Library/windows/include/ngn_math.h b/Library/windows/include/ngn_math.h
index 16fb92d..7301881 100644
--- a/Library/windows/include/ngn_math.h
+++ b/Library/windows/include/ngn_math.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones matematicas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -82,6 +82,10 @@ class Vector2 {
Vector2 operator/(float);
bool operator==(Vector2);
bool operator!=(Vector2);
+ void operator+=(Vector2);
+ void operator-=(Vector2);
+ void operator*=(float);
+ void operator/=(float);
private:
@@ -109,6 +113,10 @@ class Vector2I32 {
Vector2I32 operator/(int32_t);
bool operator==(Vector2I32);
bool operator!=(Vector2I32);
+ void operator+=(Vector2I32);
+ void operator-=(Vector2I32);
+ void operator*=(int32_t);
+ void operator/=(int32_t);
private:
@@ -136,6 +144,10 @@ class Vector2I64 {
Vector2I64 operator/(int64_t);
bool operator==(Vector2I64);
bool operator!=(Vector2I64);
+ void operator+=(Vector2I64);
+ void operator-=(Vector2I64);
+ void operator*=(int64_t);
+ void operator/=(int64_t);
private:
@@ -150,11 +162,13 @@ class NGN_Math {
// Segmento publico
public:
- // Contructor de la clase
- NGN_Math();
+ // Devuelve la instancia
+ static NGN_Math* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_Math();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Distancia entre 2 puntos (4 parametros, punto flotante, 1a sobrecarga)
@@ -186,6 +200,14 @@ class NGN_Math {
// Segmento privado
private:
+ // Contructor de la clase
+ NGN_Math();
+
+ // Destructor de la clase
+ ~NGN_Math();
+
+ // Puntero de memoria a la instancia
+ static NGN_Math* instance;
};
diff --git a/Library/windows/include/ngn_music_clip.h b/Library/windows/include/ngn_music_clip.h
index 5edb8aa..85ccac8 100644
--- a/Library/windows/include/ngn_music_clip.h
+++ b/Library/windows/include/ngn_music_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_render.h b/Library/windows/include/ngn_render.h
index bdab099..51b69ce 100644
--- a/Library/windows/include/ngn_render.h
+++ b/Library/windows/include/ngn_render.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Render {
// Public
public:
- // Constructor
- NGN_Render();
+ // Devuelve la instancia
+ static NGN_Render* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Render();
// Dibuja una textura en la surface del renderer
void Texture(NGN_Texture* texture, float position_x = (float)NGN_DEFAULT_VALUE, float position_y = (float)NGN_DEFAULT_VALUE);
@@ -105,6 +108,16 @@ class NGN_Render {
// Private
private:
+ // Constructor
+ NGN_Render();
+
+ // Destructor
+ ~NGN_Render();
+
+ // Puntero de memoria a la instancia
+ static NGN_Render* instance;
+
+
bool render2texture; // Flag de render to texture
NGN_Texture* rend2text; // Textura de destino del render
diff --git a/Library/windows/include/ngn_sound.h b/Library/windows/include/ngn_sound.h
index 9ac1db4..4d86dcb 100644
--- a/Library/windows/include/ngn_sound.h
+++ b/Library/windows/include/ngn_sound.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sonido
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -86,11 +86,14 @@ class NGN_Sound {
// Public
public:
- // Constructor de la clase
- NGN_Sound();
+ // Devuelve la instancia
+ static NGN_Sound* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor de la clase
- ~NGN_Sound();
/*** Efectos de sonido (SFX) [64 simultaneos maximo por defecto] ***/
@@ -242,6 +245,16 @@ class NGN_Sound {
// Private
private:
+ // Constructor de la clase
+ NGN_Sound();
+
+ // Destructor de la clase
+ ~NGN_Sound();
+
+ // Puntero de memoria a la instancia
+ static NGN_Sound* instance;
+
+
// Lista de sonidos disponibles
std::vector sfx_cue;
diff --git a/Library/windows/include/ngn_sprite.h b/Library/windows/include/ngn_sprite.h
index 2a0975f..895b85a 100644
--- a/Library/windows/include/ngn_sprite.h
+++ b/Library/windows/include/ngn_sprite.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_system.h b/Library/windows/include/ngn_system.h
index 24b4062..698a487 100644
--- a/Library/windows/include/ngn_system.h
+++ b/Library/windows/include/ngn_system.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Funciones de sistema
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_System {
// Public
public:
- // Contructor
- NGN_System();
+ // Devuelve la instancia
+ static NGN_System* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_System();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Inicializa la libreria
bool Init();
@@ -93,6 +95,15 @@ class NGN_System {
// Private
private:
+ // Contructor
+ NGN_System();
+
+ // Destructor
+ ~NGN_System();
+
+ // Puntero de memoria a la instancia
+ static NGN_System* instance;
+
// Resetea los flags y variables antes de leer el evento
void ResetFlags();
diff --git a/Library/windows/include/ngn_text_layer.h b/Library/windows/include/ngn_text_layer.h
index ab8c608..3b37761 100644
--- a/Library/windows/include/ngn_text_layer.h
+++ b/Library/windows/include/ngn_text_layer.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Text Layer - Capa de texto con soporte TTF
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_texture.h b/Library/windows/include/ngn_texture.h
index b92e4b8..3f3ce88 100644
--- a/Library/windows/include/ngn_texture.h
+++ b/Library/windows/include/ngn_texture.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Fondos con texturas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_tiledbg.h b/Library/windows/include/ngn_tiledbg.h
index 77030ab..3f14fc0 100644
--- a/Library/windows/include/ngn_tiledbg.h
+++ b/Library/windows/include/ngn_tiledbg.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
Fondos Tileados
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Library/windows/include/ngn_toolbox.h b/Library/windows/include/ngn_toolbox.h
index a045473..f5d5260 100644
--- a/Library/windows/include/ngn_toolbox.h
+++ b/Library/windows/include/ngn_toolbox.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.10.0-beta ***
+ *** Version 1.11.0-stable ***
TOOL BOX - Caja de herramientas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -73,11 +73,13 @@ class NGN_ToolBox {
// Segmento publico
public:
- // Constructor de la clase
- NGN_ToolBox();
+ // Devuelve la instancia
+ static NGN_ToolBox* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_ToolBox();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
/*** Cadenas de texto ***/
@@ -98,6 +100,15 @@ class NGN_ToolBox {
// Segmento privado
private:
+ // Constructor de la clase
+ NGN_ToolBox();
+
+ // Destructor de la clase
+ ~NGN_ToolBox();
+
+ // Puntero de memoria a la instancia
+ static NGN_ToolBox* instance;
+
// Constantes de conversion a UTF-8 (2 bytes)
// El primer byte en la codificacion en 2 bytes empieza con 110 y contiene 5 bits de datos
const uint8_t utf8_b0_head = 0xC0; // 1100 0000
diff --git a/Library/windows/lib/libngn.a b/Library/windows/lib/libngn.a
index 5349b28..acd6369 100644
Binary files a/Library/windows/lib/libngn.a and b/Library/windows/lib/libngn.a differ
diff --git a/Library/windows/lib/libngn_d.a b/Library/windows/lib/libngn_d.a
index b2ba40e..9a0077b 100644
Binary files a/Library/windows/lib/libngn_d.a and b/Library/windows/lib/libngn_d.a differ
diff --git a/Source/config_flags.h b/Source/config_flags.h
index 5cede61..238dc3e 100644
--- a/Source/config_flags.h
+++ b/Source/config_flags.h
@@ -1,12 +1,12 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
FLAGS de configuracion de la libreria
La libreria debe compilarse para que estos FLAGS sean efectivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -22,8 +22,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
diff --git a/Source/ngn.cpp b/Source/ngn.cpp
index 66d702c..2ce39fc 100644
--- a/Source/ngn.cpp
+++ b/Source/ngn.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -18,8 +18,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -78,7 +78,7 @@ NGN* ngn; // Clase principal
/*** Contructor ***/
NGN::NGN() {
- // Crea los objetos de la libreria
+ // Prepara los singletons de los objetos de la libreria
log = NULL; // Mensages de depuracion
system = NULL; // Funciones del sistema
math = NULL; // Funciones matematicas
@@ -86,13 +86,15 @@ NGN::NGN() {
input = NULL; // Metodos de entrada
graphics = NULL; // Gestion del Renderer de SDL
render = NULL; // Dibuja los diferentes elementos graficos
- camera = NULL; // Crea la camara virtual 2D
load = NULL; // Carga de archivos
collisions = NULL; // Sistema de colisiones
sound = NULL; // Efectos de sonido
image = NULL; // Manipulacion de imagenes en RAW
disk = NULL; // Gestion de archivos en el disco
+ // Prepara los objetos de la libreria
+ camera = NULL; // Crea la camara virtual 2D
+
}
@@ -100,20 +102,22 @@ NGN::NGN() {
/*** Destructor ***/
NGN::~NGN() {
- // Elimina todos los objetos creados
- delete disk; disk = NULL;
- delete image; image = NULL;
- delete sound; sound = NULL;
- delete collisions; collisions = NULL;
- delete load; load = NULL;
+ // Elimina los objetos
delete camera; camera = NULL;
- delete render; render = NULL;
- delete graphics; graphics = NULL;
- delete input; input = NULL;
- delete toolbox; toolbox = NULL;
- delete math; math = NULL;
- delete system; system = NULL;
- delete log; log = NULL;
+
+ // Elimina todas las instancias a los singletons
+ NGN_Disk::RemoveInstance(); disk = NULL;
+ NGN_Image::RemoveInstance(); image = NULL;
+ NGN_Sound::RemoveInstance(); sound = NULL;
+ NGN_Collisions::RemoveInstance(); collisions = NULL;
+ NGN_Load::RemoveInstance(); load = NULL;
+ NGN_Render::RemoveInstance(); render = NULL;
+ NGN_Graphics::RemoveInstance(); graphics = NULL;
+ NGN_Input::RemoveInstance(); input = NULL;
+ NGN_ToolBox::RemoveInstance(); toolbox = NULL;
+ NGN_Math::RemoveInstance(); math = NULL;
+ NGN_System::RemoveInstance(); system = NULL;
+ NGN_Log::RemoveInstance(); log = NULL;
// Cierra los subsistemas de SDL
SDL_Quit(); // Cierra la libreria SDL correctamente
@@ -125,31 +129,36 @@ NGN::~NGN() {
/*** Inicializa la libreria ***/
bool NGN::Init() {
- // Crea los objetos de la libreria
- log = new NGN_Log(); // Mensages de depuracion
- if (!log) return false;
- system = new NGN_System(); // Funciones del sistema
- if (!system) return false;
- toolbox = new NGN_ToolBox(); // Caja de herramientas
- if (!toolbox) return false;
- input = new NGN_Input(); // Metodos de entrada
- if (!input) return false;
- graphics = new NGN_Graphics(); // Gestion del Renderer de SDL
- if (!graphics) return false;
- render = new NGN_Render(); // Dibuja los diferentes elementos graficos
- if (!render) return false;
- camera = new NGN_Camera(); // Crea la camara virtual 2D
- if (!camera) return false;
- load = new NGN_Load(); // Carga de archivos
- if (!load) return false;
- collisions = new NGN_Collisions(); // Sistema de colisiones
- if (!collisions) return false;
- sound = new NGN_Sound(); // Efectos de sonido
- if (!sound) return false;
- image = new NGN_Image(); // Manipulacion de imagenes en RAW
- if (!image) return false;
- disk = new NGN_Disk(); // Gestion de archivos en el disco
- if (!disk) return false;
+ // Crea las instancias a los singletons de los modulos de la libreria
+ log = NGN_Log::GetInstance(); // Mensages de depuracion
+ system = NGN_System::GetInstance(); // Funciones del sistema
+ math = NGN_Math::GetInstance(); // Funciones matematicas
+ toolbox = NGN_ToolBox::GetInstance(); // Caja de herramientas
+ input = NGN_Input::GetInstance(); // Metodos de entrada
+ graphics = NGN_Graphics::GetInstance(); // Gestion del Renderer de SDL
+ render = NGN_Render::GetInstance(); // Dibuja los diferentes elementos graficos
+ load = NGN_Load::GetInstance(); // Carga de archivos
+ collisions = NGN_Collisions::GetInstance(); // Sistema de colisiones
+ sound = NGN_Sound::GetInstance(); // Efectos de sonido
+ image = NGN_Image::GetInstance(); // Manipulacion de imagenes en RAW
+ disk = NGN_Disk::GetInstance(); // Gestion de archivos en el disco
+
+ // Inicia los singletons de la libreria
+ log->BootUp(); // Mensages de depuracion
+ system->BootUp(); // Funciones del sistema
+ math->BootUp(); // Funciones matematicas
+ toolbox->BootUp(); // Caja de herramientas
+ input->BootUp(); // Metodos de entrada
+ graphics->BootUp(); // Gestion del Renderer de SDL
+ render->BootUp(); // Dibuja los diferentes elementos graficos
+ load->BootUp(); // Carga de archivos
+ collisions->BootUp(); // Sistema de colisiones
+ sound->BootUp(); // Efectos de sonido
+ image->BootUp(); // Manipulacion de imagenes en RAW
+ disk->BootUp(); // Gestion de archivos en el disco
+
+ // Crea los objetos adicionales de a libreria
+ camera = new NGN_Camera(); // Crea la camara virtual 2D
// Inicializa la libreria SDL
if (!system->Init()) return false;
diff --git a/Source/ngn.h b/Source/ngn.h
index 54cb581..368bb1a 100644
--- a/Source/ngn.h
+++ b/Source/ngn.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Archivo principal de la libreria
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -21,8 +21,8 @@
Requiere SFML (2.5.1) - 64-bits
http://www.sfml-dev.org/
- Requiere LodePNG (20200306)
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
@@ -115,7 +115,7 @@ class NGN {
// Destructor
~NGN();
- // Punteros a las clases
+ // Punteros a los singletons de las clases
NGN_Log* log; // Mensages de depuracion
NGN_System* system; // Funciones del sistema
NGN_Math* math; // Funciones matematicas
@@ -123,13 +123,15 @@ class NGN {
NGN_Input* input; // Metodos de entrada
NGN_Graphics* graphics; // Gestion del Renderer de SDL
NGN_Render* render; // Dibuja los diferentes elementos graficos
- NGN_Camera* camera; // Camara virtual 2D integrada
NGN_Load* load; // Funciones para la carga de archivos
NGN_Collisions* collisions; // Funciones del sistema de colisiones
NGN_Sound* sound; // Gestion de los efectos de sonido
NGN_Image* image; // Manipulacion de imagenes en RAW
NGN_Disk* disk; // Gestion de archivos en el disco
+ // Punteros a los objetos
+ NGN_Camera* camera; // Camara virtual 2D integrada
+
// Iniciliaza la libreria
bool Init();
diff --git a/Source/ngn_audio_clip.cpp b/Source/ngn_audio_clip.cpp
index 2b058ee..8102e6c 100644
--- a/Source/ngn_audio_clip.cpp
+++ b/Source/ngn_audio_clip.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_audio_clip.h b/Source/ngn_audio_clip.h
index 0300000..a109c0a 100644
--- a/Source/ngn_audio_clip.h
+++ b/Source/ngn_audio_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Clips de audio
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_camera.cpp b/Source/ngn_camera.cpp
index 2f928e0..8299499 100644
--- a/Source/ngn_camera.cpp
+++ b/Source/ngn_camera.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_camera.h b/Source/ngn_camera.h
index 8bc9560..39de1df 100644
--- a/Source/ngn_camera.h
+++ b/Source/ngn_camera.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Camara virtual en 2D
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_canvas.cpp b/Source/ngn_canvas.cpp
index e64d606..269331d 100644
--- a/Source/ngn_canvas.cpp
+++ b/Source/ngn_canvas.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_canvas.h b/Source/ngn_canvas.h
index fe8c1d4..783d1b5 100644
--- a/Source/ngn_canvas.h
+++ b/Source/ngn_canvas.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Canvas - Capa de dibujo
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_collisions.cpp b/Source/ngn_collisions.cpp
index 67f2cf1..5dbebfb 100644
--- a/Source/ngn_collisions.cpp
+++ b/Source/ngn_collisions.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -58,6 +58,37 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Collisions* NGN_Collisions::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Collisions* NGN_Collisions::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Collisions();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Collisions::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
/*** Contructor ***/
NGN_Collisions::NGN_Collisions() {
@@ -71,6 +102,12 @@ NGN_Collisions::~NGN_Collisions() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Collisions::BootUp() {
+}
+
+
+
/*** Consulta el color de un pixel del mapa de colisiones ***/
uint32_t NGN_Collisions::GetPixel(NGN_CollisionMapData* cmap, int32_t position_x, int32_t position_y) {
@@ -142,7 +179,7 @@ bool NGN_Collisions::HitBox(NGN_Sprite* spr1, NGN_Sprite* spr2) {
w2 = spr2->box.width;
h2 = spr2->box.height;
// Colision entre las cajas principales
- r |= CheckColliders(x1, y1, w1, h1, x2, y2, w2, h2);
+ r |= CheckBoxColliders(x1, y1, w1, h1, x2, y2, w2, h2);
}
// Fase 2 - Si la caja principal del Sprite 1 esta habilitada, verifica la colision con los colliders del Sprite 2, si estos existen
@@ -162,7 +199,7 @@ bool NGN_Collisions::HitBox(NGN_Sprite* spr1, NGN_Sprite* spr2) {
w2 = spr2->colliders[i].width;
h2 = spr2->colliders[i].height;
// Verifica la colision
- r |= CheckColliders(x1, y1, w1, h1, x2, y2, w2, h2);
+ r |= CheckBoxColliders(x1, y1, w1, h1, x2, y2, w2, h2);
}
}
}
@@ -184,7 +221,7 @@ bool NGN_Collisions::HitBox(NGN_Sprite* spr1, NGN_Sprite* spr2) {
w1 = spr1->colliders[i].width;
h1 = spr1->colliders[i].height;
// Verifica la colision
- r |= CheckColliders(x1, y1, w1, h1, x2, y2, w2, h2);
+ r |= CheckBoxColliders(x1, y1, w1, h1, x2, y2, w2, h2);
}
}
}
@@ -210,7 +247,7 @@ bool NGN_Collisions::HitBox(NGN_Sprite* spr1, NGN_Sprite* spr2) {
w2 = spr2->colliders[i].width;
h2 = spr2->colliders[i].height;
// Verifica la colision
- r |= CheckColliders(x1, y1, w1, h1, x2, y2, w2, h2);
+ r |= CheckBoxColliders(x1, y1, w1, h1, x2, y2, w2, h2);
}
}
}
@@ -225,7 +262,7 @@ bool NGN_Collisions::HitBox(NGN_Sprite* spr1, NGN_Sprite* spr2) {
/*** Algoritmo de colision por cajas ***/
-bool NGN_Collisions::CheckColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) {
+bool NGN_Collisions::CheckBoxColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) {
// Calculos previos (distancia entre sprites)
Vector2 distance;
diff --git a/Source/ngn_collisions.h b/Source/ngn_collisions.h
index 802de91..c1bcb6c 100644
--- a/Source/ngn_collisions.h
+++ b/Source/ngn_collisions.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sistema de colisiones
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -60,11 +60,14 @@ class NGN_Collisions {
// Public
public:
- // Constructor
- NGN_Collisions();
+ // Devuelve la instancia
+ static NGN_Collisions* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Collisions();
// Consulta el color de un pixel del mapa de colisiones
uint32_t GetPixel(NGN_CollisionMapData* cmap, int32_t position_x, int32_t position_y);
@@ -86,8 +89,18 @@ class NGN_Collisions {
// Private
private:
+ // Constructor
+ NGN_Collisions();
+
+ // Destructor
+ ~NGN_Collisions();
+
+ // Puntero de memoria a la instancia
+ static NGN_Collisions* instance;
+
+
// Algoritmo de colision por cajas
- bool CheckColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
+ bool CheckBoxColliders(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2);
// Deteccion de colisiones entre sprites por "pixel perfect"
SDL_Surface* RenderSpriteInSurface(
diff --git a/Source/ngn_defines.cpp b/Source/ngn_defines.cpp
index 8e3a2ff..8dbdfea 100644
--- a/Source/ngn_defines.cpp
+++ b/Source/ngn_defines.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_defines.h b/Source/ngn_defines.h
index 7fe11ba..f643490 100644
--- a/Source/ngn_defines.h
+++ b/Source/ngn_defines.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Definiciones de prototipos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,7 +61,7 @@
static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
static const int32_t NGN_VERSION_MINOR = 11; // Version menor
static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "wip-0x02"; // Version metadatos
+static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
/*** Definiciones generales ***/
static const int32_t NGN_DEFAULT_VALUE = 0x7FFFFFFF; // Valor de "defecto"
diff --git a/Source/ngn_disk.cpp b/Source/ngn_disk.cpp
index 72dab1c..d3140e4 100644
--- a/Source/ngn_disk.cpp
+++ b/Source/ngn_disk.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de acceso al disco
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -60,6 +60,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Disk* NGN_Disk::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Disk* NGN_Disk::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Disk();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Disk::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Constructor ***/
NGN_Disk::NGN_Disk() {
@@ -78,6 +110,12 @@ NGN_Disk::~NGN_Disk() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Disk::BootUp() {
+}
+
+
+
/*** Lee un archivo en formato binario desde el disco y almacenalo en un buffer en RAM ***/
int32_t NGN_Disk::ReadBinaryFile(std::string filepath, std::vector &buffer) {
diff --git a/Source/ngn_disk.h b/Source/ngn_disk.h
index c88df82..2d7d07c 100644
--- a/Source/ngn_disk.h
+++ b/Source/ngn_disk.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de acceso al disco
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Disk {
public:
- // Constructor
- NGN_Disk();
+ // Devuelve la instancia
+ static NGN_Disk* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Disk();
// Lee un archivo en formato binario desde el disco y almacenalo en un buffer en RAM
int32_t ReadBinaryFile(std::string filepath, std::vector &buffer);
@@ -91,6 +94,16 @@ class NGN_Disk {
private:
+ // Constructor
+ NGN_Disk();
+
+ // Destructor
+ ~NGN_Disk();
+
+ // Puntero de memoria a la instancia
+ static NGN_Disk* instance;
+
+
// Genera una estructura de directorios
int32_t MakePath(std::string path);
diff --git a/Source/ngn_filesystem.cpp b/Source/ngn_filesystem.cpp
index 4095c99..fea0c12 100644
--- a/Source/ngn_filesystem.cpp
+++ b/Source/ngn_filesystem.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones del sistema de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_filesystem.h b/Source/ngn_filesystem.h
index 737a1d3..696c233 100644
--- a/Source/ngn_filesystem.h
+++ b/Source/ngn_filesystem.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones del sistema de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_graphics.cpp b/Source/ngn_graphics.cpp
index fb5b8cc..b6fea58 100644
--- a/Source/ngn_graphics.cpp
+++ b/Source/ngn_graphics.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -64,6 +64,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Graphics* NGN_Graphics::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Graphics* NGN_Graphics::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Graphics();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Graphics::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Contructor ***/
NGN_Graphics::NGN_Graphics() {
@@ -134,6 +166,12 @@ NGN_Graphics::~NGN_Graphics() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Graphics::BootUp() {
+}
+
+
+
/*** Inicializa el engine grafico ***/
bool NGN_Graphics::Init(
std::string window_name, // Nombre en la ventana
diff --git a/Source/ngn_graphics.h b/Source/ngn_graphics.h
index 83ffe5d..95d9849 100644
--- a/Source/ngn_graphics.h
+++ b/Source/ngn_graphics.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -68,11 +68,14 @@ class NGN_Graphics {
// Public
public:
- // Contructor
- NGN_Graphics();
+ // Devuelve la instancia
+ static NGN_Graphics* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Graphics();
// Inicializa la ventana principal y la superficie de renderizado
bool Init(
@@ -185,6 +188,16 @@ class NGN_Graphics {
// Private
private:
+ // Contructor
+ NGN_Graphics();
+
+ // Destructor
+ ~NGN_Graphics();
+
+ // Puntero de memoria a la instancia
+ static NGN_Graphics* instance;
+
+
// Resolucion de pantalla completa
int32_t desktop_w;
int32_t desktop_h;
diff --git a/Source/ngn_image.cpp b/Source/ngn_image.cpp
index e781946..3f8e72c 100644
--- a/Source/ngn_image.cpp
+++ b/Source/ngn_image.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones para la manipulacion de imagenes en RAW
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -54,6 +54,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Image* NGN_Image::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Image* NGN_Image::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Image();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Image::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Constructor ***/
NGN_Image::NGN_Image() {
@@ -67,6 +99,11 @@ NGN_Image::~NGN_Image() {
}
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Image::BootUp() {
+}
+
+
/*** Convierte una imagen RAW a datos de textura ***/
NGN_TextureData* NGN_Image::ConvertRawToTextureData(NGN_RawImage* raw) {
diff --git a/Source/ngn_image.h b/Source/ngn_image.h
index 759235d..cd2dcc0 100644
--- a/Source/ngn_image.h
+++ b/Source/ngn_image.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones para la manipulacion de imagenes en RAW
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -65,11 +65,14 @@ class NGN_Image {
public:
- // Constructor
- NGN_Image();
+ // Devuelve la instancia
+ static NGN_Image* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Image();
// Convierte una imagen RAW a datos de textura
NGN_TextureData* ConvertRawToTextureData(NGN_RawImage* raw);
@@ -98,6 +101,15 @@ class NGN_Image {
private:
+ // Constructor
+ NGN_Image();
+
+ // Destructor
+ ~NGN_Image();
+
+ // Puntero de memoria a la instancia
+ static NGN_Image* instance;
+
};
diff --git a/Source/ngn_input.cpp b/Source/ngn_input.cpp
index a083e01..a08a69b 100644
--- a/Source/ngn_input.cpp
+++ b/Source/ngn_input.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -122,6 +122,39 @@ void NGN_Key::Reset() {
/*** Metodos de entrada (Clase NGN_Input) ***/
+
+/*** Puntero de la instancia a NULL ***/
+NGN_Input* NGN_Input::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Input* NGN_Input::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Input();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Input::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Constructor ***/
NGN_Input::NGN_Input() {
@@ -151,6 +184,12 @@ NGN_Input::~NGN_Input() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Input::BootUp() {
+}
+
+
+
/*** Actualiza el estado de los dispositivos de entrada ***/
void NGN_Input::Update() {
diff --git a/Source/ngn_input.h b/Source/ngn_input.h
index f84fdc9..4e646c3 100644
--- a/Source/ngn_input.h
+++ b/Source/ngn_input.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Meotodos de entrada
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -131,16 +131,27 @@ class NGN_Input {
public:
+ // Devuelve la instancia
+ static NGN_Input* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
+
+
+ private:
+
// Contructor
NGN_Input();
// Destructor
~NGN_Input();
+ // Puntero de memoria a la instancia
+ static NGN_Input* instance;
- private:
-
// Define las propiedades del game controller
struct controller_data {
bool available; // El controlador esta disponible?
diff --git a/Source/ngn_load.cpp b/Source/ngn_load.cpp
index 506fed6..dfd2599 100644
--- a/Source/ngn_load.cpp
+++ b/Source/ngn_load.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -67,6 +67,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Load* NGN_Load::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Load* NGN_Load::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Load();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Load::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Contructor ***/
NGN_Load::NGN_Load() {
@@ -91,6 +123,12 @@ NGN_Load::~NGN_Load() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Load::BootUp() {
+}
+
+
+
/*** Carga una textura ***/
NGN_TextureData* NGN_Load::Texture(std::string filepath) {
diff --git a/Source/ngn_load.h b/Source/ngn_load.h
index 05d5381..919282c 100644
--- a/Source/ngn_load.h
+++ b/Source/ngn_load.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de carga de archivos
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -72,11 +72,14 @@ class NGN_Load {
// Public
public:
- // Contructor
- NGN_Load();
+ // Devuelve la instancia
+ static NGN_Load* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Load();
// Carga de texturas
NGN_TextureData* Texture(std::string filepath);
@@ -138,6 +141,16 @@ class NGN_Load {
// Private
private:
+ // Contructor
+ NGN_Load();
+
+ // Destructor
+ ~NGN_Load();
+
+ // Puntero de memoria a la instancia
+ static NGN_Load* instance;
+
+
// Objeto para el acceso al sistema de archivos
NGN_FileSystem* file_system;
diff --git a/Source/ngn_log.cpp b/Source/ngn_log.cpp
index ba454e9..eead5e1 100644
--- a/Source/ngn_log.cpp
+++ b/Source/ngn_log.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de mensages de depuracion
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -55,6 +55,37 @@
#include "ngn.h"
+/*** Puntero de la instancia a NULL ***/
+NGN_Log* NGN_Log::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Log* NGN_Log::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Log();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Log::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
/*** Constructor ***/
NGN_Log::NGN_Log() {
@@ -75,6 +106,12 @@ NGN_Log::~NGN_Log() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Log::BootUp() {
+}
+
+
+
/*** Abre el archivo de registro ***/
bool NGN_Log::OpenLogFile(std::string log_file, bool overwrite) {
diff --git a/Source/ngn_log.h b/Source/ngn_log.h
index 9ea0cea..6f55f64 100644
--- a/Source/ngn_log.h
+++ b/Source/ngn_log.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de mensages de depuracion
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_Log {
public:
- // Constructor
- NGN_Log();
+ // Devuelve la instancia
+ static NGN_Log* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_Log();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Abre el archivo de registro
bool OpenLogFile(std::string log_file, bool overwrite = true);
@@ -79,10 +81,19 @@ class NGN_Log {
private:
+ // Constructor
+ NGN_Log();
+
+ // Destructor
+ ~NGN_Log();
+
+ // Puntero de memoria a la instancia
+ static NGN_Log* instance;
+
std::string _log_file; // Nombre del archivo de registro
bool _log_enabled; // Archivo de registro habilitado
- std::fstream file; // Stream de gestion del archivo de registro
+ std::fstream file; // Stream de gestion del archivo de registro
// Genera la marca de tiempo actual
std::string GetTimeStamp();
diff --git a/Source/ngn_math.cpp b/Source/ngn_math.cpp
index f2074ff..58d7fd5 100644
--- a/Source/ngn_math.cpp
+++ b/Source/ngn_math.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones matematicas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -147,6 +147,20 @@ void Vector2::operator-=(Vector2 p) {
}
+void Vector2::operator*=(float p) {
+
+ x *= p;
+ y *= p;
+
+}
+
+void Vector2::operator/=(float p) {
+
+ x /= p;
+ y /= p;
+
+}
+
/*** Clase Vector2I32 (int32_t) - Calcula la magnitud del vector ***/
@@ -219,6 +233,20 @@ void Vector2I32::operator-=(Vector2I32 p) {
}
+void Vector2I32::operator*=(int32_t p) {
+
+ x *= p;
+ y *= p;
+
+}
+
+void Vector2I32::operator/=(int32_t p) {
+
+ x /= p;
+ y /= p;
+
+}
+
/*** Clase Vector2I64 (int64_t) - Calcula la magnitud del vector ***/
@@ -291,6 +319,22 @@ void Vector2I64::operator-=(Vector2I64 p) {
}
+void Vector2I64::operator*=(int64_t p) {
+
+ x *= p;
+ y *= p;
+
+}
+
+void Vector2I64::operator/=(int64_t p) {
+
+ x /= p;
+ y /= p;
+
+}
+
+
+
/******************************************************************************
@@ -299,6 +343,38 @@ void Vector2I64::operator-=(Vector2I64 p) {
******************************************************************************/
+/*** Puntero de la instancia a NULL ***/
+NGN_Math* NGN_Math::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Math* NGN_Math::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Math();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Math::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Constructor ***/
NGN_Math::NGN_Math() {
@@ -313,6 +389,12 @@ NGN_Math::~NGN_Math() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Math::BootUp() {
+}
+
+
+
/*** Distancia entre 2 puntos (4 parametros, punto flotante, 1ra sobrecarga) ***/
float NGN_Math::GetDistance(float x1, float y1, float x2, float y2) {
diff --git a/Source/ngn_math.h b/Source/ngn_math.h
index 42a6416..7301881 100644
--- a/Source/ngn_math.h
+++ b/Source/ngn_math.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones matematicas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -84,6 +84,8 @@ class Vector2 {
bool operator!=(Vector2);
void operator+=(Vector2);
void operator-=(Vector2);
+ void operator*=(float);
+ void operator/=(float);
private:
@@ -113,6 +115,8 @@ class Vector2I32 {
bool operator!=(Vector2I32);
void operator+=(Vector2I32);
void operator-=(Vector2I32);
+ void operator*=(int32_t);
+ void operator/=(int32_t);
private:
@@ -142,6 +146,8 @@ class Vector2I64 {
bool operator!=(Vector2I64);
void operator+=(Vector2I64);
void operator-=(Vector2I64);
+ void operator*=(int64_t);
+ void operator/=(int64_t);
private:
@@ -156,11 +162,13 @@ class NGN_Math {
// Segmento publico
public:
- // Contructor de la clase
- NGN_Math();
+ // Devuelve la instancia
+ static NGN_Math* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_Math();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Distancia entre 2 puntos (4 parametros, punto flotante, 1a sobrecarga)
@@ -192,6 +200,14 @@ class NGN_Math {
// Segmento privado
private:
+ // Contructor de la clase
+ NGN_Math();
+
+ // Destructor de la clase
+ ~NGN_Math();
+
+ // Puntero de memoria a la instancia
+ static NGN_Math* instance;
};
diff --git a/Source/ngn_music_clip.cpp b/Source/ngn_music_clip.cpp
index 8e76924..781d5e7 100644
--- a/Source/ngn_music_clip.cpp
+++ b/Source/ngn_music_clip.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_music_clip.h b/Source/ngn_music_clip.h
index 9deb134..85ccac8 100644
--- a/Source/ngn_music_clip.h
+++ b/Source/ngn_music_clip.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Clips de musica
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_render.cpp b/Source/ngn_render.cpp
index 791a001..d279281 100644
--- a/Source/ngn_render.cpp
+++ b/Source/ngn_render.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -58,6 +58,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Render* NGN_Render::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Render* NGN_Render::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Render();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Render::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Contructor ***/
NGN_Render::NGN_Render() {
@@ -87,6 +119,12 @@ NGN_Render::~NGN_Render() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Render::BootUp() {
+}
+
+
+
void NGN_Render::Texture(NGN_Texture* texture, float position_x, float position_y) {
// Si no debe dibujarse...
diff --git a/Source/ngn_render.h b/Source/ngn_render.h
index d926be6..51b69ce 100644
--- a/Source/ngn_render.h
+++ b/Source/ngn_render.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Gestion del Renderer de SDL
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -66,11 +66,14 @@ class NGN_Render {
// Public
public:
- // Constructor
- NGN_Render();
+ // Devuelve la instancia
+ static NGN_Render* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor
- ~NGN_Render();
// Dibuja una textura en la surface del renderer
void Texture(NGN_Texture* texture, float position_x = (float)NGN_DEFAULT_VALUE, float position_y = (float)NGN_DEFAULT_VALUE);
@@ -105,6 +108,16 @@ class NGN_Render {
// Private
private:
+ // Constructor
+ NGN_Render();
+
+ // Destructor
+ ~NGN_Render();
+
+ // Puntero de memoria a la instancia
+ static NGN_Render* instance;
+
+
bool render2texture; // Flag de render to texture
NGN_Texture* rend2text; // Textura de destino del render
diff --git a/Source/ngn_sound.cpp b/Source/ngn_sound.cpp
index 5f28a64..bc91fda 100644
--- a/Source/ngn_sound.cpp
+++ b/Source/ngn_sound.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sonido
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -58,6 +58,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_Sound* NGN_Sound::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_Sound* NGN_Sound::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_Sound();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_Sound::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Constructor de la clase NGN_Sound ***/
NGN_Sound::NGN_Sound() {
@@ -87,6 +119,12 @@ NGN_Sound::~NGN_Sound() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_Sound::BootUp() {
+}
+
+
+
/*** Reproduce un sonido ***/
NGN_AudioClip* NGN_Sound::PlaySfx(
NGN_AudioClipData* sound, // Clip de audio
diff --git a/Source/ngn_sound.h b/Source/ngn_sound.h
index 968cf28..4d86dcb 100644
--- a/Source/ngn_sound.h
+++ b/Source/ngn_sound.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sonido
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -86,11 +86,14 @@ class NGN_Sound {
// Public
public:
- // Constructor de la clase
- NGN_Sound();
+ // Devuelve la instancia
+ static NGN_Sound* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
+
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
- // Destructor de la clase
- ~NGN_Sound();
/*** Efectos de sonido (SFX) [64 simultaneos maximo por defecto] ***/
@@ -242,6 +245,16 @@ class NGN_Sound {
// Private
private:
+ // Constructor de la clase
+ NGN_Sound();
+
+ // Destructor de la clase
+ ~NGN_Sound();
+
+ // Puntero de memoria a la instancia
+ static NGN_Sound* instance;
+
+
// Lista de sonidos disponibles
std::vector sfx_cue;
diff --git a/Source/ngn_sprite.cpp b/Source/ngn_sprite.cpp
index 4f6a9e7..684f9fb 100644
--- a/Source/ngn_sprite.cpp
+++ b/Source/ngn_sprite.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_sprite.h b/Source/ngn_sprite.h
index c028a8a..895b85a 100644
--- a/Source/ngn_sprite.h
+++ b/Source/ngn_sprite.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Sprites
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_system.cpp b/Source/ngn_system.cpp
index 46f91af..a773981 100644
--- a/Source/ngn_system.cpp
+++ b/Source/ngn_system.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de sistema
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -58,6 +58,38 @@
+/*** Puntero de la instancia a NULL ***/
+NGN_System* NGN_System::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_System* NGN_System::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_System();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_System::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Contructor ***/
NGN_System::NGN_System() {
@@ -83,6 +115,12 @@ NGN_System::~NGN_System() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_System::BootUp() {
+}
+
+
+
/*** Inicializa el engine SDL ***/
bool NGN_System::Init() {
diff --git a/Source/ngn_system.h b/Source/ngn_system.h
index c1ca6be..698a487 100644
--- a/Source/ngn_system.h
+++ b/Source/ngn_system.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Funciones de sistema
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -61,11 +61,13 @@ class NGN_System {
// Public
public:
- // Contructor
- NGN_System();
+ // Devuelve la instancia
+ static NGN_System* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor
- ~NGN_System();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
// Inicializa la libreria
bool Init();
@@ -93,6 +95,15 @@ class NGN_System {
// Private
private:
+ // Contructor
+ NGN_System();
+
+ // Destructor
+ ~NGN_System();
+
+ // Puntero de memoria a la instancia
+ static NGN_System* instance;
+
// Resetea los flags y variables antes de leer el evento
void ResetFlags();
diff --git a/Source/ngn_text_layer.cpp b/Source/ngn_text_layer.cpp
index 435dc49..ea9df92 100644
--- a/Source/ngn_text_layer.cpp
+++ b/Source/ngn_text_layer.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Text Layer - Capa de texto con soporte TTF
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_text_layer.h b/Source/ngn_text_layer.h
index 9c286df..3b37761 100644
--- a/Source/ngn_text_layer.h
+++ b/Source/ngn_text_layer.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Text Layer - Capa de texto con soporte TTF
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_texture.cpp b/Source/ngn_texture.cpp
index 02966b0..318571a 100644
--- a/Source/ngn_texture.cpp
+++ b/Source/ngn_texture.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Fondos con texturas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_texture.h b/Source/ngn_texture.h
index 972c507..3f3ce88 100644
--- a/Source/ngn_texture.h
+++ b/Source/ngn_texture.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Fondos con texturas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_tiledbg.cpp b/Source/ngn_tiledbg.cpp
index 72be63d..48014a2 100644
--- a/Source/ngn_tiledbg.cpp
+++ b/Source/ngn_tiledbg.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Fondos Tileados
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_tiledbg.h b/Source/ngn_tiledbg.h
index b380132..3f14fc0 100644
--- a/Source/ngn_tiledbg.h
+++ b/Source/ngn_tiledbg.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
Fondos Tileados
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Source/ngn_toolbox.cpp b/Source/ngn_toolbox.cpp
index ebc7a49..c437faa 100644
--- a/Source/ngn_toolbox.cpp
+++ b/Source/ngn_toolbox.cpp
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
TOOL BOX - Caja de herramientas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -67,6 +67,40 @@
******************************************************************************/
+
+
+/*** Puntero de la instancia a NULL ***/
+NGN_ToolBox* NGN_ToolBox::instance = NULL;
+
+
+
+/*** Metodo para crear/obtener la instancia ***/
+NGN_ToolBox* NGN_ToolBox::GetInstance() {
+
+ // Verifica si la instancia ya se ha creado
+ // Si no es asi, creala
+ if (!instance) instance = new NGN_ToolBox();
+
+ // Devuelve la instancia
+ return instance;
+
+}
+
+
+
+/*** Metodo para eliminar la instancia ***/
+void NGN_ToolBox::RemoveInstance() {
+
+ // Si la instancia aun existe, eliminala
+ if (instance) {
+ delete instance;
+ instance = NULL;
+ }
+
+}
+
+
+
/*** Contructor de la clase NGN_ToolBox ***/
NGN_ToolBox::NGN_ToolBox() {
}
@@ -79,6 +113,12 @@ NGN_ToolBox::~NGN_ToolBox() {
+/*** Procesos iniciales despues de crear la instancia ***/
+void NGN_ToolBox::BootUp() {
+}
+
+
+
/******************************************************************************
Cadenas de texto
diff --git a/Source/ngn_toolbox.h b/Source/ngn_toolbox.h
index 6614773..f5d5260 100644
--- a/Source/ngn_toolbox.h
+++ b/Source/ngn_toolbox.h
@@ -1,11 +1,11 @@
/******************************************************************************
N'gine Lib for C++
- *** Version 1.11.0-wip0x02 ***
+ *** Version 1.11.0-stable ***
TOOL BOX - Caja de herramientas
Proyecto iniciado el 1 de Febrero del 2016
- (cc) 2016 - 2022 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -73,11 +73,13 @@ class NGN_ToolBox {
// Segmento publico
public:
- // Constructor de la clase
- NGN_ToolBox();
+ // Devuelve la instancia
+ static NGN_ToolBox* GetInstance();
+ // Elimina la instancia
+ static void RemoveInstance();
- // Destructor de la clase
- ~NGN_ToolBox();
+ // Procesos iniciales despues de crear la instancia
+ void BootUp();
/*** Cadenas de texto ***/
@@ -98,6 +100,15 @@ class NGN_ToolBox {
// Segmento privado
private:
+ // Constructor de la clase
+ NGN_ToolBox();
+
+ // Destructor de la clase
+ ~NGN_ToolBox();
+
+ // Puntero de memoria a la instancia
+ static NGN_ToolBox* instance;
+
// Constantes de conversion a UTF-8 (2 bytes)
// El primer byte en la codificacion en 2 bytes empieza con 110 y contiene 5 bits de datos
const uint8_t utf8_b0_head = 0xC0; // 1100 0000
diff --git a/Tools/NGN_CollisionMap/NGN_CollisionMap.cbp b/Tools/NGN_CollisionMap/NGN_CollisionMap.cbp
index ba10272..9424805 100644
--- a/Tools/NGN_CollisionMap/NGN_CollisionMap.cbp
+++ b/Tools/NGN_CollisionMap/NGN_CollisionMap.cbp
@@ -13,6 +13,8 @@
+
+
@@ -23,6 +25,8 @@
+
+
@@ -35,6 +39,8 @@
+
+
@@ -45,6 +51,8 @@
+
+
@@ -53,22 +61,26 @@
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
diff --git a/Tools/NGN_CollisionMap/source/collision_map.cpp b/Tools/NGN_CollisionMap/source/collision_map.cpp
new file mode 100644
index 0000000..2cafaba
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/collision_map.cpp
@@ -0,0 +1,267 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Nucleo del programa -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+// Includes del proyecto
+#include "collision_map.h"
+#include "defines.h"
+#include "message.h"
+#include "convert_to_map.h"
+
+
+
+
+/*** Constructor ***/
+CollisionMap::CollisionMap(int32_t argc, char* args[]) {
+
+
+ // Guarda el numero de argumentos
+ argument_count = argc;
+
+ // General al lista de argumentos
+ argument_list.clear();
+ argument_list.resize(argument_count);
+ for (int32_t i = 0; i < argument_count; i ++) argument_list[i] = args[i];
+
+ // Parametros
+ parameter.in_file = "";
+ parameter.out_file = "";
+ parameter.tile_size = 0;
+
+ // Crea los objetos adicionales
+ msg = new Message(argument_list[0]);
+ fs = new FsManager();
+ png2map = new ConvertToMap();
+
+ // Flags de argumentos
+ arg_help.state = false; arg_help.value = "";
+ arg_in_file.state = false; arg_in_file.value = "";
+ arg_out_file.state = false; arg_out_file.value = "";
+ arg_tile_size.state = false; arg_tile_size.value = "";
+
+}
+
+
+
+/*** Destructor ***/
+CollisionMap::~CollisionMap() {
+
+ // Elimina la lista de argumentos
+ argument_list.clear();
+
+ // Elimina los objetos adicionales
+ delete png2map; png2map = NULL;
+ delete fs; fs = NULL;
+ delete msg; msg = NULL;
+
+}
+
+
+
+/*** Programa principal ***/
+int32_t CollisionMap::Run() {
+
+ // Resultado de la ejecucion
+ int32_t r = ERR_CODE_OK;
+
+ // Texto de cabecera
+ msg->AppHeader();
+
+ // Analiza la lista de argumentos
+ int32_t arglist = CheckArguments();
+ //DebugArgList();
+
+ // Analisis de los posibles errores en la linea de comandos / peticion de ayuda
+ if (arglist == 0) {
+ // Si no se ha especificado ningun argumento
+ msg->QuestionMarkForHelp();
+ } else if (arglist < 0) {
+ // Uso incorrecto
+ msg->UseError();
+ msg->UserManual();
+ r = ERR_CODE_ARG_INVALID;
+ } else if (arg_help.state) {
+ // Manual en pantalla
+ msg->UserManual();
+ } else {
+ // Valida los parametros de entrada
+ if (ValidateParameters()) {
+ Report();
+ if (
+ !png2map->Convert(
+ parameter.in_file,
+ parameter.out_file,
+ parameter.tile_size
+ )
+ ) r = ERR_CODE_CONVERSION_FAILURE;
+ } else {
+ msg->QuestionMarkForHelp();
+ r = ERR_CODE_ARG_INVALID;
+ }
+ }
+
+ // Resultado de la ejecucion
+ return r;
+
+}
+
+
+
+/*** Analiza la lista de argumentos proporcionados ***/
+int32_t CollisionMap::CheckArguments() {
+
+ // Si no hay argumentos, muestra el texto de ayuda
+ if (argument_count == 1) return 0;
+
+ // Si el numero de argumentos es incorrecto
+ if ((argument_count < ARG_MIN_NUM) || (argument_count > ARG_MAX_NUM)) return -1;
+
+ // Flag de argumentos validos
+ bool arg = false;
+ bool valid = false;
+
+ // Analiza la lista de argumentos
+ for (uint32_t i = 1; i < argument_list.size(); i ++) {
+
+ valid = false;
+
+ if (argument_list[i] == ARG_HELP) { // Texto de ayuda
+
+ if (arg_help.state) return -1;
+ arg_help.state = true;
+ valid = true;
+
+ } else if (argument_list[i] == ARG_OUT_FILE) { // Archivo de salida
+
+ if (arg_out_file.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_out_file.state = true;
+ i ++;
+ arg_out_file.value = argument_list[i];
+ valid = true;
+
+ } else if (argument_list[i] == ARG_TILE_SIZE) { // Tamaño del tile
+
+ if (arg_tile_size.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_tile_size.state = true;
+ i ++;
+ arg_tile_size.value = argument_list[i];
+ valid = true;
+
+ } else if (i == 1) {
+
+ if (arg_in_file.state) return -1;
+ arg_in_file.state = true;
+ arg_in_file.value = argument_list[i];
+ valid = true;
+
+ }
+
+ // Si el argumento no se reconoce...
+ if (!valid) return -1;
+
+ // Argumento valido?
+ arg |= valid;
+
+ }
+
+ // Indica los argumentos se han leido correctamente
+ return (arg) ? 1:-1;
+
+}
+
+
+
+/*** Valida los parametros de entrada ***/
+bool CollisionMap::ValidateParameters() {
+
+ // Resultado
+ bool r = true;
+
+ // Verifica si el archivo de origen existe
+ if (!fs->CheckIfFileExist(arg_in_file.value)) {
+ std::cout << arg_in_file.value << " file not found." << std::endl;
+ r = false;
+ } else {
+ parameter.in_file = arg_in_file.value;
+ }
+
+
+ // Nombre base de los archivos de salida
+ if (arg_out_file.state) {
+ parameter.out_file = arg_out_file.value;
+ } else {
+ parameter.out_file = parameter.in_file.substr(0, (parameter.in_file.length() - 4));
+ }
+
+
+ // Tamaño del tile
+ if (arg_tile_size.state) {
+ parameter.tile_size = std::stoi(arg_tile_size.value);
+ if ((parameter.tile_size < MIN_TILE_SIZE) || (parameter.tile_size > MAX_TILE_SIZE)) {
+ std::cout << "Tile size out of range." << std::endl;
+ r = false;
+ }
+ } else {
+ parameter.tile_size = DEFAULT_TILE_SIZE;
+ }
+
+ // Parametros validados
+ return r;
+
+}
+
+
+
+/*** Resumen de los datos recopilados ***/
+void CollisionMap::Report() {
+
+ // Informacion de los parametros introducidos
+ std::cout << "Output filename: " << parameter.out_file << MAP_EXTENSION << std::endl;
+ std::cout << "Tile size: " << parameter.tile_size << "x" << parameter.tile_size << " pixels." << std::endl;
+
+}
+
+
+
+/*** DEBUG: Imprime la lista de argumentos introducidos ***/
+void CollisionMap::DebugArgList() {
+
+ std::cout << std::endl;
+ std::cout << "Argument list" << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << "Executable name: " << argument_list[0] << std::endl;
+ std::cout << "Input file: " << arg_in_file.state << " " << arg_in_file.value << std::endl;
+ std::cout << ARG_HELP << " " << arg_help.state << " " << arg_help.value << std::endl;
+ std::cout << ARG_OUT_FILE << " " << arg_out_file.state << " " << arg_out_file.value << std::endl;
+ std::cout << ARG_TILE_SIZE << " " << arg_tile_size.state << " " << arg_tile_size.value << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << std::endl;
+
+}
diff --git a/Tools/NGN_CollisionMap/source/collision_map.h b/Tools/NGN_CollisionMap/source/collision_map.h
new file mode 100644
index 0000000..276ee78
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/collision_map.h
@@ -0,0 +1,100 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Nucleo del programa -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef COLLISION_MAP_H_INCLUDED
+#define COLLISION_MAP_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+#include "message.h"
+#include "fs_manager.h"
+#include "convert_to_map.h"
+
+
+
+/*** Declaracion de la clase ***/
+class CollisionMap {
+
+ public:
+
+ // Constructor
+ CollisionMap(int32_t argc, char* args[]);
+
+ // Destructor
+ ~CollisionMap();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+ int32_t Run(); // Programa principal
+
+
+ private:
+
+ /*** Propiedades ***/
+
+ // Flags de los argumentos
+ struct argument {
+ bool state;
+ std::string value;
+ };
+ argument arg_help; // Ayuda
+ argument arg_in_file; // Archivo de origen
+ argument arg_out_file; // Archivo de salida
+ argument arg_tile_size; // Tamaño del tile
+
+ // Argumentos introducidos
+ int32_t argument_count; // Numero de argumentos en la linea de comandos
+ std::vector argument_list; // Lista con los argumentos proporcionados
+
+ // Parametros de la conversion
+ struct {
+ std::string in_file; // Archivo de entrada
+ std::string out_file; // Archivo de salida
+ int32_t tile_size; // Tamaño del tile
+ } parameter;
+
+
+ /*** Objetos ***/
+ Message* msg; // Gestor de mensages
+ FsManager* fs; // Gestor de archivos del sistema
+ ConvertToMap* png2map; // Conversor de PNG a mapa de colision
+
+
+ /*** Metodos para la lectura de parametros***/
+ int32_t CheckArguments(); // Analiza la lista de argumentos proporcionados
+ bool ValidateParameters(); // Valida los parametros de entrada
+ void Report(); // Resumen de los datos
+
+
+ /*** Metodos de depuracion ***/
+ void DebugArgList(); // Imprime la lista de argumentos introducidos
+
+};
+
+
+
+#endif // COLLISION_MAP_H_INCLUDED
diff --git a/Tools/NGN_CollisionMap/source/map.cpp b/Tools/NGN_CollisionMap/source/convert_to_map.cpp
similarity index 54%
rename from Tools/NGN_CollisionMap/source/map.cpp
rename to Tools/NGN_CollisionMap/source/convert_to_map.cpp
index 38174a9..c6d5b0b 100644
--- a/Tools/NGN_CollisionMap/source/map.cpp
+++ b/Tools/NGN_CollisionMap/source/convert_to_map.cpp
@@ -1,418 +1,439 @@
-/******************************************************************************
-
- N'gine Lib for C++
- Conversor de PNG a Mapa de Colisiones (.map)
-
- Proyecto iniciado el 8 de Abril del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
- https://nightfoxandco.com
- contact@nightfoxandco.com
-
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
- http://lodev.org/lodepng/
-
-******************************************************************************/
-
-
-
-/*** Includes ***/
-
-// C++
-#include
-#include
-#include
-#include
-#include
-
-// LodePNG
-#include "lodepng/lodepng.h"
-
-// CollisionMap class
-#include "map.h"
-
-
-
-/*** Constructor ***/
-CollisionMap::CollisionMap() {
-
-}
-
-
-
-/*** Destructor ***/
-CollisionMap::~CollisionMap() {
-
- // Borra los buffers de memoria temporales
- png.clear();
- raw.clear();
- bitmap.clear();
- // Borra los buffers de archivo
- palette.clear();
- tiles.clear();
- tmap.clear();
- // Borra los buffers temporales
- t_palette.clear();
- t_tiles.clear();
- t_tl.clear();
-
-}
-
-
-
-/*** Convierte el archivo a un Sprite Sheet del tamaño solicitado ***/
-int32_t CollisionMap::ConvertPng() {
-
- // Intenta cargar el archivo PNG, si hay error sal e informa.
- if (ReadPNG(input_filename, raw) > 0) return 1;
- // Genera el Bitmap de colisiones
- if (GenerateBitmap() > 0) return 1;
- // Genera los tiles y el mapa
- GenerateMap();
- // Genera la cabecera del archivo
- GenerateHeader();
- // Graba los archivos de salida
- if (WriteFile(output_filename) > 0) return 1;
- // Devuelve el resultado
- return 0;
-
-}
-
-
-
-/*** Lee el archivo PNG y almacena los pixeles de la imagen en el buffer ***/
-int32_t CollisionMap::ReadPNG(std::string filename, std::vector &data) {
-
- // Borra los buffers
- png.clear();
-
- // Carga el archivo PNG
- uint32_t _error = lodepng::load_file(png, filename);
-
- // Si se ha cargado correctamente, decodifica la imagen
- if (_error == 0) {
- _error = lodepng::decode(raw, in_width, in_height, png);
- } else {
- std::cout << "Error loading " << filename << "." << std::endl;
- png.clear();
- return 1;
- }
-
- // Verifica que la decodificacion sea la correcta
- if (_error == 0) {
- std::cout << "File " << filename << " loaded & decoded successfully." << std::endl;
- std::cout << "Image size is " << in_width << "x" << in_height << " pixels." << std::endl;
- png.clear();
- return 0;
- } else {
- std::cout << "Error decoding " << filename << "." << std::endl;
- png.clear();
- return 1;
- }
-
-
-}
-
-
-
-/*** Graba el archivo empaquetado ***/
-int32_t CollisionMap::WriteFile(std::string filename) {
-
- // Proteccion de path
- if (filename.length() >= 252) {
- std::cout << "Error saving " << filename << "." << std::endl;
- std::cout << "Path too long." << std::endl;
- return 1;
- }
- // Variables
- uint32_t i = 0;
-
- for (i = 0; i < sizeof(header.reserve); i ++) header.reserve[i] = 0;
-
- // Genera el nombre de archivo
- char f[256];
- char basename[252];
- for (i = 0; i < filename.length(); i ++) basename[i] = filename[i]; // Nombre base
- basename[i] = '\0'; // Terminador
-
- // Espaciado en el texto
- std::cout << std::endl;
-
- // Graba el archivo principal
- sprintf(f, "%s.map", basename);
- std::ofstream file;
- file.open(f, std::ofstream::out | std::ofstream::binary);
- if (file.is_open()) {
- file.write((char*)&header, sizeof(header)); // Cabecera
- file.write((char*)&palette[0], (palette.capacity() * sizeof(int32_t))); // Paleta
- file.write((char*)&tiles[0], tiles.capacity()); // Tiles
- file.write((char*)&tmap[0], (tmap.capacity() * sizeof(int32_t))); // Mapa de tiles
- file.close();
- std::cout << "File " << f << " successfully saved." << std::endl;
- } else {
- std::cout << "Error saving " << f << "." << std::endl;
- return 1;
- }
-
- // Todo correcto
- return 0;
-
-}
-
-
-
-
-/*** Lee un pixel del buffer especificado ***/
-uint32_t CollisionMap::GetPixel(std::vector &data, uint32_t offset) {
-
- // Variables
- uint32_t pixel = 0;
-
- // Lee los bits del pixel
- /*if ((offset + 3) < data.capacity()) {*/
- pixel = data[(offset + 3)] | (data[(offset + 2)] << 8) | (data[(offset + 1)] << 16) | (data[offset] << 24);
- /*} else {
- pixel.r = pixel.g = pixel.b = pixel.a = 0;
- std::cout << "Pixel read out of range." << std::endl;
- }*/
-
- return pixel;
-
-}
-
-
-
-/*** Genera el mapa de colisiones ***/
-int32_t CollisionMap::GenerateBitmap() {
-
- // Medidas del mapa
- out_width = in_width;
- out_height = in_height;
-
- // Prepara los bufferes de destino
- bitmap.clear();
- bitmap.resize((out_width * out_height), 0);
- t_palette.clear();
- t_palette.resize(256, 0);
-
- // Variables de uso temporal
- uint32_t pixel; // Alamacena el valor del pixel
- int32_t id = 0; // Contenedor de ID de la paleta
- uint32_t pal_id = 0; // Posicion actual en la paleta
- uint32_t offset = 0; // Posicion actual en el mapa
-
- // Marcador de progreso
- uint64_t max_pixels = (out_height * out_width);
- uint64_t current_pixel = 0;
- uint64_t percent = 0, old_percent = 0;
- char s[16];
- std::cout << std::endl;
- std::cout << "Generating bitmap & palette..." << std::endl;
-
- // Identifica el color de cada pixel e identificalo en la paleta, de no existir, añadelo
- for (uint32_t y = 0; y < out_height; y ++) {
- for (uint32_t x = 0; x < out_width; x ++) {
- // Color del pixel actual
- offset = ((y * out_width) + x);
- pixel = GetPixel(raw, (offset << 2));
- // Reset de ID
- id = -1;
- // Si el color coincide con alguno de la paleta...
- for (uint32_t c = 0; c < t_palette.size(); c ++) {
- if (pixel == t_palette[c]) {
- id = c;
- break;
- }
- }
- // Si es un nuevo color, indicalo
- if (id < 0) {
- if (pal_id > 255) {
- std::cout << "Image format not compatible. The image must be indexed at 256 colors." << std::endl;
- return 1;
- }
- // Guarda el nuevo color
- t_palette[pal_id] = pixel;
- // Guarda el pixel
- bitmap[offset] = (0xff & ((uint8_t)(pal_id)));
- // Siguente PAL ID
- pal_id ++;
- } else {
- // Guarda el Pixel
- bitmap[offset] = (0xff & ((uint8_t)(id)));
- }
- // Informacion del progreso
- current_pixel ++;
- percent = ((current_pixel * 1000) / max_pixels);
- if (percent != old_percent) {
- sprintf(s, "%05.1f%%", ((float)percent / 10.0f));
- std::cout << "\x0d" << s << " ";
- old_percent = percent;
- }
- //std::cout << "OFFSET:" << offset << " COLOR:" << pixel << " ID:" << (int32_t)_id << " BITMAP:" << (int32_t)bitmap[offset] << std::endl;
- }
- }
-
- // Mensage del finde del progreso
- std::cout << "done!" << std::endl;
- std::cout << "Palette generated with " << pal_id << " colors." << std::endl;
-
- // Guarda el tamaño del buffer de la paleta
- pal_length = pal_id;
-
- // Copia la paleta temporal a la final
- palette.clear();
- palette.resize(pal_length, 0);
- for (uint32_t n = 0; n < pal_length; n ++) palette[n] = t_palette[n];
- t_palette.clear();
-
- // Todo Ok
- return 0;
-
-}
-
-
-
-/*** Genera la cabecera del archivo ***/
-void CollisionMap::GenerateHeader() {
-
- // Actualiza la informacion de la cabecera
- header.version = VERSION; // Version del programa
- sprintf(header.magic, "%s", MAGIC_STRING.c_str()); // Magic String
- header.width = out_width; // Tamaño del mapa en pixeles
- header.height = out_height;
- header.tile_size = tile_size; // Tamaño del tile
- header.pal_length = pal_length; // nº de elementos de la paleta (*4)
- header.tileset_length = tileset_length; // nº de elementos del tileset
- header.map_length = map_length; // nº de elementos del mapa (*4)
- for (uint32_t i = 0; i < sizeof(header.reserve); i ++) header.reserve[i] = 0; // Espacio reservado
-
-}
-
-
-
-/*** Genera el tileset y el mapa ***/
-void CollisionMap::GenerateMap() {
-
- // Prepara el buffer para almacenar el mapa de tiles
- uint32_t width = (out_width / tile_size);
- if ((out_width % tile_size) != 0) width ++;
- uint32_t height = (out_height / tile_size);
- if ((out_height % tile_size) != 0) height ++;
-
- // Aviso de ajuste del tamaño de tiles
- std::cout << std::endl;
- if (((out_width % tile_size) != 0) || (out_height % tile_size)) {
- std::cout << "WARNING: Image size doesn't fits the tile size." << std::endl;
- std::cout << "Tilemap size will be adjusted to the right size." << std::endl;
- }
-
- // Datos para el indicador de progreso
- uint64_t max_tiles = (height * width);
- uint64_t current_tile = 0;
- uint64_t percent = 0, old_percent = 0;
- char s[16];
- std::cout << "Generating a tilemap of " << width << "x" << height <<" tiles." << std::endl;
-
- // Crea el buffer para el mapa
- map_length = (width * height);
- tmap.clear();
- tmap.resize(map_length, 0);
-
- // Crea el buffer temporal para el tileset
- uint32_t tile_length = (tile_size * tile_size);
- uint32_t l = (width * height * tile_length);
- t_tiles.clear();
- t_tiles.resize(l, 0);
-
- // Control de tile nuevo
- bool new_tile = false, miss_match = false;
- uint32_t last_tile = 0;
- uint32_t offset = 0;
- uint32_t t_num = 0;
-
- // Recorre todo el mapa analizando los tiles
- for (uint32_t ty = 0; ty < height; ty ++) {
- for (uint32_t tx = 0; tx < width; tx ++) {
- // Reset del flag
- new_tile = true;
- // Copia un tile del bitmap
- GetTile(tx, ty);
- // Comparalo con todos los tiles previamente guardados
- for (uint32_t i = 0; i < last_tile; i ++) {
- offset = (i * tile_length);
- miss_match = false;
- for (uint32_t n = 0; n < tile_length; n ++) {
- if (t_tl[n] != t_tiles[(offset + n)]) {
- miss_match = true;
- break;
- }
- }
- // Si no hay discrepancia, añade el tile actual al mapa
- if (!miss_match) {
- t_num = ((ty * width) + tx);
- tmap[t_num] = i;
- new_tile = false;
- break;
- }
- }
- // Si no se encuentra coincidencia, añade el tile
- if (new_tile) {
- t_num = ((ty * width) + tx);
- tmap[t_num] = last_tile;
- offset = (last_tile * tile_length);
- for (uint32_t n = 0; n < tile_length; n ++) t_tiles[(offset + n)] = t_tl[n];
- last_tile ++;
- }
- // Informacion del progreso
- current_tile ++;
- percent = ((current_tile * 1000) / max_tiles);
- if (percent != old_percent) {
- sprintf(s, "%05.1f%%", ((float)percent / 10.0f));
- std::cout << "\x0d" << s << " ";
- old_percent = percent;
- }
- }
- }
-
- // Copia el tileset final al buffer de destino
- tileset_length = (last_tile * tile_length);
- tiles.clear();
- tiles.resize(tileset_length, 0);
- for (uint32_t n = 0; n < tileset_length; n ++) tiles[n] = t_tiles[n];
- t_tiles.clear();
-
- // Resultado
- std::cout << "done!" << std::endl;
- std::cout << "Tilemap with " << last_tile << " tiles created successfully." << std::endl << std::endl;
-
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Convierte un archivo PNG en tiles -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+#include
+
+// LodePNG
+#include "lodepng/lodepng.h"
+
+// Includes del proyecto
+#include "convert_to_map.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+ConvertToMap::ConvertToMap() {
+
+ map_width = 0; // Ancho del mapa
+ map_height = 0; // Altura del mapa
+ size_of_tile = 0; // Tamaño del tile
+ pal_length = 0; // Tamaño de la paleta
+ tileset_length = 0; // Tamaño del tileset
+ map_length = 0; // Tamaño del mapa
+
+ palette.clear();
+ tiles.clear();
+ tmap.clear();
+
+ bitmap.clear();
+
+}
+
+
+
+/*** Destructor ***/
+ConvertToMap::~ConvertToMap() {
+
+ bitmap.clear();
+
+ palette.clear();
+ tiles.clear();
+ tmap.clear();
+
+}
+
+
+
+/*** Convierte un archivo PNG en tiles ***/
+bool ConvertToMap::Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t tile_size // Tamaño del tile
+) {
+
+ // Guarda los parametros
+ size_of_tile = tile_size;
+
+ // Prepara el buffer para los pixeles de la imagen
+ std::vector png_pixels;
+ png_pixels.clear();
+
+ // Intenta abrir y decodificar el archivo PNG
+ if (!ReadPng(in_file, png_pixels)) return false;
+
+ // Convierte el PNG a BITMAP + PALETA
+ if (!GenerateBitmap(png_pixels)) return false;
+ png_pixels.clear();
+
+ // Genera un tilemap con los datos del bitmap
+ GenerateTileMap();
+
+ // Guarda en el archivo empaquetado los datos generados
+ bool r = WriteFile(out_file);
+
+ // Elimina los buffers
+ bitmap.clear();
+ palette.clear();
+ tiles.clear();
+ tmap.clear();
+
+ // Conversion correcta
+ return r;
+
+}
+
+
+
+/*** Convierte la imagen en bitmap + paleta ***/
+bool ConvertToMap::GenerateBitmap(std::vector &data) {
+
+ // Prepara los bufferes de destino
+ bitmap.clear();
+ bitmap.resize((map_width * map_height), 0);
+
+ // Prepara los buffers temporales
+ std::vector t_palette;
+ t_palette.clear();
+ t_palette.resize(256, 0);
+
+ // Variables de uso temporal
+ uint32_t pixel; // Alamacena el valor del pixel
+ int32_t id = 0; // Contenedor de ID de la paleta
+ uint32_t pal_id = 0; // Posicion actual en la paleta
+ uint32_t offset = 0; // Posicion actual en el mapa
+
+ // Marcador de progreso
+ uint64_t max_pixels = (map_width * map_height);
+ uint64_t current_pixel = 0;
+ uint64_t percent = 0, old_percent = 0;
+ char s[16];
+ std::cout << std::endl;
+ std::cout << "Generating bitmap & palette..." << std::endl;
+
+ // Identifica el color de cada pixel e identificalo en la paleta, de no existir, añadelo
+ for (uint32_t y = 0; y < map_height; y ++) {
+ for (uint32_t x = 0; x < map_width; x ++) {
+ // Color del pixel actual
+ offset = ((y * map_width) + x);
+ pixel = GetPixel(data, (offset << 2));
+ // Reset de ID
+ id = -1;
+ // Si el color coincide con alguno de la paleta...
+ for (uint32_t c = 0; c < t_palette.size(); c ++) {
+ if (pixel == t_palette[c]) {
+ id = c;
+ break;
+ }
+ }
+ // Si es un nuevo color, indicalo
+ if (id < 0) {
+ if (pal_id > 255) {
+ std::cout << "Image format not compatible. The image must be indexed at 256 colors." << std::endl;
+ bitmap.clear();
+ t_palette.clear();
+ return false;
+ }
+ // Guarda el nuevo color
+ t_palette[pal_id] = pixel;
+ // Guarda el pixel
+ bitmap[offset] = (0xff & ((uint8_t)(pal_id)));
+ // Siguente PAL ID
+ pal_id ++;
+ } else {
+ // Guarda el Pixel
+ bitmap[offset] = (0xff & ((uint8_t)(id)));
+ }
+ // Informacion del progreso
+ current_pixel ++;
+ percent = ((current_pixel * 1000) / max_pixels);
+ if (percent != old_percent) {
+ sprintf(s, "%05.1f%%", ((float)percent / 10.0f));
+ std::cout << "\x0d" << s << " ";
+ old_percent = percent;
+ }
+ //std::cout << "OFFSET:" << offset << " COLOR:" << pixel << " ID:" << (int32_t)_id << " BITMAP:" << (int32_t)bitmap[offset] << std::endl;
+ }
+ }
+
+ // Mensage del finde del progreso
+ std::cout << "done!" << std::endl;
+ std::cout << "Bitmap generation completed." << std::endl;
+ std::cout << "Palette generation completed. The palette contains " << pal_id << " colors." << std::endl;
+
+ // Guarda el tamaño del buffer de la paleta
+ pal_length = pal_id;
+
+ // Copia la paleta temporal a la final
+ palette.clear();
+ palette.resize(pal_length, 0);
+ for (uint32_t n = 0; n < pal_length; n ++) palette[n] = t_palette[n];
+ t_palette.clear();
+
+ // Todo Ok
+ return true;
+
+}
+
+
+
+/*** Genera una mapa de tiles a partir del bitmap ***/
+void ConvertToMap::GenerateTileMap() {
+
+ // Aviso de ajuste del tamaño de tiles
+ std::cout << std::endl;
+ if (((map_width % size_of_tile) != 0) || (map_height % size_of_tile) != 0) {
+ std::cout << "WARNING: Image size doesn't fits the tile size." << std::endl;
+ std::cout << "The size of the Tilemap will be adjusted to the closest right size." << std::endl;
+ }
+
+ // Prepara el buffer para almacenar el mapa de tiles
+ uint32_t width = (map_width / size_of_tile);
+ if ((map_width % size_of_tile) != 0) width ++;
+ uint32_t height = (map_height / size_of_tile);
+ if ((map_height % size_of_tile) != 0) height ++;
+
+ // Crea el buffer para el mapa
+ map_length = (width * height);
+ tmap.clear();
+ tmap.resize(map_length, 0);
+
+ // Crea el buffer temporal para el tileset
+ uint32_t tile_length = (size_of_tile * size_of_tile);
+ uint32_t l = (width * height * tile_length);
+ std::vector t_tiles; // Buffer para almacenar los pixeles de los tiles
+ t_tiles.clear();
+ t_tiles.resize(l, 0);
+
+ // Crea el buffer temporal para el tile actual a analizar
+ std::vector t_tl;
+ t_tl.clear();
+
+ // Control de tile nuevo
+ bool new_tile = false, miss_match = false;
+ uint32_t last_tile = 0;
+ uint32_t offset = 0;
+ uint32_t t_num = 0;
+
+ // Datos para el indicador de progreso
+ uint64_t max_tiles = (height * width);
+ uint64_t current_tile = 0;
+ uint64_t percent = 0, old_percent = 0;
+ char s[16];
+ std::cout << "Generating a tilemap of " << width << "x" << height <<" tiles." << std::endl;
+
+ // Recorre todo el mapa analizando los tiles
+ for (uint32_t ty = 0; ty < height; ty ++) {
+ for (uint32_t tx = 0; tx < width; tx ++) {
+ // Reset del flag
+ new_tile = true;
+ // Copia un tile del bitmap
+ GetTile(t_tl, tx, ty);
+ // Comparalo con todos los tiles previamente guardados
+ for (uint32_t i = 0; i < last_tile; i ++) {
+ offset = (i * tile_length);
+ miss_match = false;
+ for (uint32_t n = 0; n < tile_length; n ++) {
+ if (t_tl[n] != t_tiles[(offset + n)]) {
+ miss_match = true;
+ break;
+ }
+ }
+ // Si no hay discrepancia, añade el tile actual al mapa
+ if (!miss_match) {
+ t_num = ((ty * width) + tx);
+ tmap[t_num] = i;
+ new_tile = false;
+ break;
+ }
+ }
+ // Si no se encuentra coincidencia, añade el tile
+ if (new_tile) {
+ t_num = ((ty * width) + tx);
+ tmap[t_num] = last_tile;
+ offset = (last_tile * tile_length);
+ for (uint32_t n = 0; n < tile_length; n ++) t_tiles[(offset + n)] = t_tl[n];
+ last_tile ++;
+ }
+ // Informacion del progreso
+ current_tile ++;
+ percent = ((current_tile * 1000) / max_tiles);
+ if (percent != old_percent) {
+ sprintf(s, "%05.1f%%", ((float)percent / 10.0f));
+ std::cout << "\x0d" << s << " ";
+ old_percent = percent;
+ }
+ }
+ }
+
+ // Copia el tileset final al buffer de destino
+ tileset_length = (last_tile * tile_length);
+ tiles.clear();
+ tiles.resize(tileset_length, 0);
+ for (uint32_t n = 0; n < tileset_length; n ++) tiles[n] = t_tiles[n];
+
+ // Borra los buffers temporales
+ t_tl.clear();
+ t_tiles.clear();
+
+ // Resultado
+ std::cout << "done!" << std::endl;
+ std::cout << "Tilemap with " << last_tile << " tiles created successfully." << std::endl << std::endl;
+
+}
+
+
+
+/*** Graba el archivo empaquetado ***/
+bool ConvertToMap::WriteFile(std::string filename) {
+
+ // Guarda la informacion para la cabecera del archivo
+ FileHeader header;
+ memset((void*)&header, 0, sizeof(header));
+ header.version = VERSION;
+ strncpy(header.magic, MAGIC_STRING.c_str(), MAGIC_STRING.length());
+ header.width = map_width; // Tamaño del mapa en pixeles
+ header.height = map_height;
+ header.tile_size = size_of_tile; // Tamaño del tile
+ header.pal_length = pal_length; // nº de elementos de la paleta (*4)
+ header.tileset_length = tileset_length; // nº de elementos del tileset
+ header.map_length = map_length; // nº de elementos del mapa (*4)
+
+ // Genera el nombres de archivo
+ std::string fname = filename + MAP_EXTENSION;
+ const char* map_filename = fname.c_str();
+
+ // Graba el archivo principal
+ std::ofstream file;
+ file.open(map_filename, std::ofstream::out | std::ofstream::binary);
+ if (file.is_open()) {
+ file.write((char*)&header, sizeof(header)); // Cabecera
+ file.write((char*)&palette[0], (palette.capacity() * sizeof(int32_t))); // Paleta
+ file.write((char*)&tiles[0], tiles.capacity()); // Tiles
+ file.write((char*)&tmap[0], (tmap.capacity() * sizeof(int32_t))); // Mapa de tiles
+ file.close();
+ std::cout << "File " << fname << " successfully saved." << std::endl;
+ } else {
+ std::cout << "Error saving " << fname << "." << std::endl;
+ return false;
+ }
+
+ // Todo correcto
+ return true;
+
+}
+
+
+
+/*** Lee un archivo .PNG y coloca los pixeles en un buffer ***/
+bool ConvertToMap::ReadPng(std::string filename, std::vector &data) {
+
+ // Variables
+ uint32_t width = 0, height = 0; // Tamaño del archivo cargado
+
+ // Prepara el buffer temporal
+ std::vector png_data;
+ png_data.clear();
+
+ // Prepara el buffer para los datos decodificados
+ data.clear();
+
+ // Carga el archivo PNG
+ if (lodepng::load_file(png_data, filename) != 0) {
+ std::cout << "Error loading " << filename << "." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Si se ha cargado correctamente, decodifica la imagen
+ if (lodepng::decode(data, width, height, png_data) != 0) {
+ std::cout << "Error decoding " << filename << "." << std::endl;
+ png_data.clear();
+ data.clear();
+ return false;
+ }
+
+ // Guarda el tamaño del mapa
+ map_width = width;
+ map_height = height;
+
+ // Borra el buffer temporal
+ png_data.clear();
+
+ // Fin de la funcion de carga
+ return true;
+
+}
+
+
+
+/*** Lee un pixel del buffer especificado ***/
+uint32_t ConvertToMap::GetPixel(std::vector &data, uint32_t offset) {
+
+ // Variables
+ uint32_t pixel = 0;
+
+ // Lee los bits del pixel
+ /*if ((offset + 3) < data.capacity()) {*/
+ pixel = data[(offset + 3)] | (data[(offset + 2)] << 8) | (data[(offset + 1)] << 16) | (data[offset] << 24);
+ /*} else {
+ pixel.r = pixel.g = pixel.b = pixel.a = 0;
+ std::cout << "Pixel read out of range." << std::endl;
+ }*/
+
+ return pixel;
+
}
/*** Obten un tile del bitmap ***/
-void CollisionMap::GetTile(uint32_t pos_x, uint32_t pos_y) {
+void ConvertToMap::GetTile(std::vector &data, uint32_t pos_x, uint32_t pos_y) {
// Prepara el buffer de salida
- t_tl.clear();
- t_tl.resize(tile_size * tile_size);
+ data.clear();
+ data.resize(size_of_tile * size_of_tile);
// Calcula los puntos de corte
- uint32_t start_x = (pos_x * tile_size);
- uint32_t end_x = (start_x + tile_size);
- uint32_t start_y = (pos_y * tile_size);
- uint32_t end_y = (start_y + tile_size);
+ uint32_t start_x = (pos_x * size_of_tile);
+ uint32_t end_x = (start_x + size_of_tile);
+ uint32_t start_y = (pos_y * size_of_tile);
+ uint32_t end_y = (start_y + size_of_tile);
// Copia los datos del buffer al tile
uint32_t px = 0;
uint32_t offset = 0;
for (uint32_t y = start_y; y < end_y; y ++) {
for (uint32_t x = start_x; x < end_x; x ++) {
- if ((y < out_height) && (x < out_width)) {
- offset = ((out_width * y) + x);
- t_tl[px] = bitmap[offset];
+ if ((y < map_height) && (x < map_width)) {
+ offset = ((map_width * y) + x);
+ data[px] = bitmap[offset];
} else {
- t_tl[px] = 0;
+ data[px] = 0;
}
px ++;
}
- }
+ }
-}
+}
diff --git a/Tools/NGN_CollisionMap/source/convert_to_map.h b/Tools/NGN_CollisionMap/source/convert_to_map.h
new file mode 100644
index 0000000..d11e7ad
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/convert_to_map.h
@@ -0,0 +1,103 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Convierte un archivo PNG en tiles -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef CONVERT_TO_MAP_H_INCLUDED
+#define CONVERT_TO_MAP_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class ConvertToMap {
+
+ public:
+
+ // Constructor
+ ConvertToMap();
+
+ // Destructor
+ ~ConvertToMap();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+
+ // Convierte un archivo PNG en tiles
+ bool Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t tile_size // Tamaño del tile
+ );
+
+
+ private:
+
+ /*** Propiedades ***/
+
+ // Parametros del mapa
+ uint32_t map_width; // Ancho del mapa
+ uint32_t map_height; // Altura del mapa
+ uint32_t size_of_tile; // Tamaño del tile
+ uint32_t pal_length; // Tamaño de la paleta
+ uint32_t tileset_length; // Tamaño del tileset
+ uint32_t map_length; // Tamaño del mapa
+
+ // Define los vectores de memoria para el archivo de guardado
+ std::vector palette; // Buffer para almacenar la paleta de colores
+ std::vector tiles; // Buffer para almacenar los pixeles de los tiles
+ std::vector tmap; // Buffer para almacenar el mapa de tiles
+
+ // Define los vectores de memoria para datos temporales
+ std::vector bitmap; // Buffer para almacenar el mapa de pixeles
+
+
+ /*** Metodos ***/
+
+ // Genera un bitmap + paleta a partir de la imagen
+ bool GenerateBitmap(std::vector &data);
+
+ // Genera una mapa de tiles a partir del bitmap
+ void GenerateTileMap();
+
+ // Graba el archivo empaquetado
+ bool WriteFile(std::string filename);
+
+ // Lee el archivo .PNG y almacena los pixeles de la imagen en el buffer
+ bool ReadPng(std::string filename, std::vector &data);
+
+ // Lee un pixel del buffer especificado
+ uint32_t GetPixel(std::vector &data, uint32_t offset);
+
+ // Lee un tile del buffer especificado
+ void GetTile(std::vector &data, uint32_t pos_x, uint32_t pos_y);
+
+};
+
+
+
+#endif // CONVERT_TO_MAP_H_INCLUDED
diff --git a/Tools/NGN_CollisionMap/source/defines.h b/Tools/NGN_CollisionMap/source/defines.h
new file mode 100644
index 0000000..9d93d0b
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/defines.h
@@ -0,0 +1,90 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Definiciones -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+#ifndef DEFINES_H_INCLUDED
+#define DEFINES_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+
+
+
+/*** Codigos de ERROR ***/
+const int32_t ERR_CODE_OK = 0x00;
+const int32_t ERR_CODE_BOOTFAILURE = 0x01;
+const int32_t ERR_CODE_ARG_INVALID = 0x02;
+const int32_t ERR_CODE_CONVERSION_FAILURE = 0x03;
+
+
+/*** Version de N'gine ***/
+const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
+const int32_t NGN_VERSION_MINOR = 11; // Version menor
+const int32_t NGN_VERSION_PATCH = 0; // Version parche
+const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
+
+
+/*** Version del programa ***/
+const std::string PROGRAM_NAME = "N'gine PNG to Collision Map converter"; // Nombre del programa
+const std::string CC_YEARS = "2016-2023"; // Años en el texto CREATIVE COMMONS
+const int32_t PROGRAM_VERSION_MAJOR = 2; // Version mayor
+const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
+const int32_t PROGRAM_VERSION_PATCH = 0; // Version parche
+const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
+const std::string MAGIC_STRING = "NGN COLLISION MAP"; // Magic string
+const uint8_t MS_LENGTH = 17; // Logitud del magic string
+const uint8_t VERSION = 2; // Version del archivo
+
+
+/*** Textos recurrentes ***/
+const std::string TEXT_DASHED_LINE = "------------------------------------------------------------";
+
+
+/*** Listado de argumentos disponibles ***/
+const int32_t ARG_MIN_NUM = 2; // Numero minimo de argumentos
+const int32_t ARG_MAX_NUM = 7; // Numero maximo de argumentos
+const std::string ARG_HELP = "-?"; // Ayuda
+const std::string ARG_OUT_FILE = "-o"; // Define el archivo de salida
+const std::string ARG_TILE_SIZE = "-ts"; // Define el tamaño del tile
+
+/*** Parametros de los argumentos ***/
+const int32_t MIN_TILE_SIZE = 8; // Tamaño minimo del tile
+const int32_t MAX_TILE_SIZE = 1024; // Tamaño maximo del tile
+const int32_t DEFAULT_TILE_SIZE = 32; // Tamaño por defecto del tile
+
+/*** Extensiones ***/
+const std::string MAP_EXTENSION = ".map"; // Extension de archivo: Archivo tilemap
+
+
+/*** Estructuras personalizadas ***/
+
+// Cabecera del archivo
+struct FileHeader {
+ uint8_t version; // Version del programa de conversion
+ char magic[32]; // Magic String
+ uint32_t width; // Ancho del mapa
+ uint32_t height; // Alto del mapa
+ uint32_t tile_size; // Tamaño del tile
+ uint32_t pal_length; // Tamaño de los datos (nº de elementos) de la paleta
+ uint32_t tileset_length; // Tamaño de los datos (nº de elementos) del tileset
+ uint32_t map_length; // Tamaño de los datos (nº de elementos) del mapa
+ uint8_t reserve[256]; // Posible uso futuro
+};
+
+
+#endif // DEFINES_H_INCLUDED
diff --git a/Tools/NGN_CollisionMap/source/fs_manager.cpp b/Tools/NGN_CollisionMap/source/fs_manager.cpp
new file mode 100644
index 0000000..0dcd004
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/fs_manager.cpp
@@ -0,0 +1,171 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+// C
+#include
+#include
+#include
+// Includes del proyecto
+#include "fs_manager.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+FsManager::FsManager() {
+
+}
+
+
+
+/*** Destructor ***/
+FsManager::~FsManager() {
+
+}
+
+
+
+/*** Crea una lista de archivos de un directorio concreto ***/
+std::vector FsManager::GetListOfFiles(std::string path) {
+
+ // Crea una lista temporal
+ std::vector file_list;
+ file_list.clear();
+
+ // Lista recursiva
+ if (path.length() > 0) GetFilesRecursive(path, file_list);
+
+ // Devuelve la lista creada
+ return file_list;
+
+}
+
+
+
+/*** Crea un directorio a partir de un path, si este no existe ***/
+int32_t FsManager::MakePath(std::string path) {
+
+ // Caracter de referencia
+ std::string getchar = "";
+
+ // Genera una lista de directorios
+ std::vector directory;
+ directory.clear();
+ for (uint32_t i = 0; i < path.length(); i ++) {
+ getchar = path.at(i);
+ if (getchar == "/") {
+ directory.push_back(path.substr(0, i));
+ }
+ }
+
+ // Genera un path sin el nombre de archivo
+ for (uint32_t i = 0; i < directory.size(); i ++) {
+ if (directory[i] == ".") continue;
+ if (i == (directory.size() - 1)) std::cout << "Attempting to create [" << directory[i] << "]" << std::endl;
+ const char* p = directory[i].c_str();
+ #if defined (OS_WINDOWS)
+ mkdir(p);
+ #elif defined (OS_LINUX)
+ mkdir(p, 0777);
+ #else
+ mkdir(p, 0777);
+ #endif
+ }
+
+ // Devuelve el resultado
+ return directory.size();
+
+}
+
+
+
+/*** Crea una lista recursiva de los archivos ***/
+void FsManager::GetFilesRecursive(std::string path, std::vector &files) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Estructura de datos de "dirent"
+ struct dirent* dp;
+ // Variable de control de los metodos
+ DIR *dir;
+
+ // Intenta abrir el directorio
+ dir = opendir(_path);
+ // Si no puedes, asume que es un archivo y registralo
+ if (!dir) {
+ if (CheckIfFileExist(path)) files.push_back(path);
+ return;
+ }
+
+ // Variables
+ std::string file_name = "";
+
+ // Lee el directorio hasta que te quedes sin datos
+ while ((dp = readdir(dir)) != NULL) {
+
+ // Nombre del archivo actual
+ file_name = dp->d_name;
+
+ // Si es el indicador de raiz (.) o subir un nivel (..), saltatelo
+ if ((file_name == ".") || (file_name == "..")) continue;
+
+ // Genera una nueva ruta, por si es un directorio y no un archivo
+ std::string new_path = "";
+ if (path.substr(0, 1) != ".") new_path += (path + "/");
+ new_path += dp->d_name;
+
+ // Recursividad
+ GetFilesRecursive(new_path, files);
+
+ }
+
+ // Cierra el directorio
+ closedir(dir);
+
+}
+
+
+
+/*** Verifica que el archivo existe ***/
+bool FsManager::CheckIfFileExist(std::string path) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Intenta abrir el archivo en modo binario
+ std::ifstream file;
+ file.open(_path, std::ifstream::in | std::ifstream::binary);
+
+ // Segun si has podido o no abrirlo...
+ if (file.is_open()) {
+ file.close();
+ return true;
+ } else {
+ return false;
+ }
+
+}
diff --git a/Tools/NGN_CollisionMap/source/fs_manager.h b/Tools/NGN_CollisionMap/source/fs_manager.h
new file mode 100644
index 0000000..d0ecc38
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/fs_manager.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef FS_MANAGER_H_INCLUDED
+#define FS_MANAGER_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class FsManager {
+
+ public:
+
+ // Constructor
+ FsManager();
+
+ // Destructor
+ ~FsManager();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+
+ // Crea una lista con los archivos contenidos en un directorio
+ std::vector GetListOfFiles(std::string path);
+
+ // Crea un directorio a partir de un path, si este no existe
+ int32_t MakePath(std::string path);
+
+
+ // Verifica si un archivo existe
+ bool CheckIfFileExist(std::string path);
+
+
+ private:
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+
+ // Metodo recursivo para listar todos los archivos de todos los directorios
+ void GetFilesRecursive(std::string path, std::vector &files);
+
+};
+
+
+
+#endif // FS_MANAGER_H_INCLUDED
diff --git a/Tools/NGN_CollisionMap/source/lodepng/lodepng.cpp b/Tools/NGN_CollisionMap/source/lodepng/lodepng.cpp
index ee8cf33..1f89677 100644
--- a/Tools/NGN_CollisionMap/source/lodepng/lodepng.cpp
+++ b/Tools/NGN_CollisionMap/source/lodepng/lodepng.cpp
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,10 +44,10 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
#endif /*_MSC_VER */
-const char* LODEPNG_VERSION_STRING = "20200306";
+const char* LODEPNG_VERSION_STRING = "20220717";
/*
-This source file is built up in the following large parts. The code sections
+This source file is divided into the following large parts. The code sections
with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way.
-Tools for C and common code for PNG and Zlib
-C Code for Zlib (huffman, deflate, ...)
@@ -267,7 +267,7 @@ typedef struct ucvector {
} ucvector;
/*returns 1 if success, 0 if failure ==> nothing done*/
-static unsigned ucvector_resize(ucvector* p, size_t size) {
+static unsigned ucvector_reserve(ucvector* p, size_t size) {
if(size > p->allocsize) {
size_t newsize = size + (p->allocsize >> 1u);
void* data = lodepng_realloc(p->data, newsize);
@@ -277,10 +277,15 @@ static unsigned ucvector_resize(ucvector* p, size_t size) {
}
else return 0; /*error: not enough memory*/
}
- p->size = size;
return 1; /*success*/
}
+/*returns 1 if success, 0 if failure ==> nothing done*/
+static unsigned ucvector_resize(ucvector* p, size_t size) {
+ p->size = size;
+ return ucvector_reserve(p, size);
+}
+
static ucvector ucvector_init(unsigned char* buffer, size_t size) {
ucvector v;
v.data = buffer;
@@ -299,6 +304,7 @@ static void string_cleanup(char** out) {
*out = NULL;
}
+/*also appends null termination character*/
static char* alloc_string_sized(const char* in, size_t insize) {
char* out = (char*)lodepng_malloc(insize + 1);
if(out) {
@@ -479,71 +485,62 @@ static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned c
ensureBits functions:
Ensures the reader can at least read nbits bits in one or more readBits calls,
safely even if not enough bits are available.
-Returns 1 if there are enough bits available, 0 if not.
+The nbits parameter is unused but is given for documentation purposes, error
+checking for amount of bits must be done beforehand.
*/
-/*See ensureBits documentation above. This one ensures exactly 1 bit */
-/*static unsigned ensureBits1(LodePNGBitReader* reader) {
- if(reader->bp >= reader->bitsize) return 0;
- reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u);
- return 1;
-}*/
-
/*See ensureBits documentation above. This one ensures up to 9 bits */
-static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits9(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 1u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
- if(start + 0u < size) reader->buffer |= reader->data[start + 0];
+ if(start + 0u < size) reader->buffer = reader->data[start + 0];
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 17 bits */
-static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits17(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 2u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 25 bits */
-static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits25(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 3u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 32 bits */
-static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits32(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 4u < size) {
@@ -551,7 +548,6 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u)));
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
@@ -559,48 +555,28 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */
-static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
/* The shift allows nbits to be only up to 31. */
return reader->buffer & ((1u << nbits) - 1u);
}
/* Must have enough bits available with ensureBits */
-static void advanceBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void advanceBits(LodePNGBitReader* reader, size_t nbits) {
reader->buffer >>= nbits;
reader->bp += nbits;
}
/* Must have enough bits available with ensureBits */
-static unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
unsigned result = peekBits(reader, nbits);
advanceBits(reader, nbits);
return result;
}
-
-/* Public for testing only. steps and result must have numsteps values. */
-unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
- size_t numsteps, const size_t* steps, unsigned* result) {
- size_t i;
- LodePNGBitReader reader;
- unsigned error = LodePNGBitReader_init(&reader, data, size);
- if(error) return 0;
- for(i = 0; i < numsteps; i++) {
- size_t step = steps[i];
- unsigned ok;
- if(step > 25) ok = ensureBits32(&reader, step);
- else if(step > 17) ok = ensureBits25(&reader, step);
- else if(step > 9) ok = ensureBits17(&reader, step);
- else ok = ensureBits9(&reader, step);
- if(!ok) return 0;
- result[i] = readBits(&reader, step);
- }
- return 1;
-}
#endif /*LODEPNG_COMPILE_DECODER*/
static unsigned reverseBits(unsigned bits, unsigned num) {
@@ -735,10 +711,11 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) {
numpresent = 0;
for(i = 0; i < tree->numcodes; ++i) {
unsigned l = tree->lengths[i];
- unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
- /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
- unsigned reverse = reverseBits(symbol, l);
+ unsigned symbol, reverse;
if(l == 0) continue;
+ symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
+ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
+ reverse = reverseBits(symbol, l);
numpresent++;
if(l <= FIRSTBITS) {
@@ -1102,11 +1079,10 @@ static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree*
advanceBits(reader, l);
return value;
} else {
- unsigned index2;
advanceBits(reader, FIRSTBITS);
- index2 = value + peekBits(reader, l - FIRSTBITS);
- advanceBits(reader, codetree->table_len[index2] - FIRSTBITS);
- return codetree->table_value[index2];
+ value += peekBits(reader, l - FIRSTBITS);
+ advanceBits(reader, codetree->table_len[value] - FIRSTBITS);
+ return codetree->table_value[value];
}
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -1139,7 +1115,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
unsigned* bitlen_cl = 0;
HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/
- if(!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/
+ if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the memory*/
+ ensureBits17(reader, 14);
/*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/
HLIT = readBits(reader, 5) + 257;
@@ -1260,10 +1237,14 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/
static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
- unsigned btype) {
+ unsigned btype, size_t max_output_size) {
unsigned error = 0;
HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/
HuffmanTree tree_d; /*the huffman tree for distance codes*/
+ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */
+ int done = 0;
+
+ if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
HuffmanTree_init(&tree_ll);
HuffmanTree_init(&tree_d);
@@ -1271,14 +1252,21 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d);
else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader);
- while(!error) /*decode all symbols until end reached, breaks at end code*/ {
+
+ while(!error && !done) /*decode all symbols until end reached, breaks at end code*/ {
/*code_ll is literal, length or end code*/
unsigned code_ll;
- ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */
+ /* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second literal is read at once. This
+ appears to be slightly faster, than ensuring 20 bits here for 1 huffman symbol and the potential 5 extra bits for the length symbol.*/
+ ensureBits32(reader, 30);
code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ if(code_ll <= 255) {
+ /*slightly faster code path if multiple literals in a row*/
+ out->data[out->size++] = (unsigned char)code_ll;
+ code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ }
if(code_ll <= 255) /*literal symbol*/ {
- if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/);
- out->data[out->size - 1] = (unsigned char)code_ll;
+ out->data[out->size++] = (unsigned char)code_ll;
} else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ {
unsigned code_d, distance;
unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/
@@ -1291,6 +1279,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX];
if(numextrabits_l != 0) {
/* bits already ensured above */
+ ensureBits25(reader, 5);
length += readBits(reader, numextrabits_l);
}
@@ -1318,7 +1307,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(distance > start) ERROR_BREAK(52); /*too long backward distance*/
backward = start - distance;
- if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/);
+ out->size += length;
if(distance < length) {
size_t forward;
lodepng_memcpy(out->data + start, out->data + backward, distance);
@@ -1330,10 +1319,13 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
lodepng_memcpy(out->data + start, out->data + backward, length);
}
} else if(code_ll == 256) {
- break; /*end code, break the loop*/
+ done = 1; /*end code, finish the loop*/
} else /*if(code_ll == INVALIDSYMBOL)*/ {
ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
}
+ if(out->allocsize - out->size < reserved_size) {
+ if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
+ }
/*check if any of the ensureBits above went out of bounds*/
if(reader->bp > reader->bitsize) {
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
@@ -1341,6 +1333,9 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
/* TODO: revise error codes 10,11,50: the above comment is no longer valid */
ERROR_BREAK(51); /*error, bit pointer jumps past memory*/
}
+ if(max_output_size && out->size > max_output_size) {
+ ERROR_BREAK(109); /*error, larger than max size*/
+ }
}
HuffmanTree_cleanup(&tree_ll);
@@ -1373,8 +1368,11 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
- lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
- bytepos += LEN;
+ /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
+ if (LEN) {
+ lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
+ bytepos += LEN;
+ }
reader->bp = bytepos << 3u;
@@ -1392,15 +1390,16 @@ static unsigned lodepng_inflatev(ucvector* out,
while(!BFINAL) {
unsigned BTYPE;
- if(!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/
+ if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/
+ ensureBits9(&reader, 3);
BFINAL = readBits(&reader, 1);
BTYPE = readBits(&reader, 2);
if(BTYPE == 3) return 20; /*error: invalid BTYPE*/
else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/
- else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/
-
- if(error) return error;
+ else error = inflateHuffmanBlock(out, &reader, BTYPE, settings->max_output_size); /*compression, BTYPE 01 or 10*/
+ if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ if(error) break;
}
return error;
@@ -1421,6 +1420,12 @@ static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize,
if(settings->custom_inflate) {
unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings);
out->allocsize = out->size;
+ if(error) {
+ /*the custom inflate is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ }
return error;
} else {
return lodepng_inflatev(out, in, insize, settings);
@@ -2116,7 +2121,9 @@ static unsigned deflate(unsigned char** out, size_t* outsize,
const unsigned char* in, size_t insize,
const LodePNGCompressSettings* settings) {
if(settings->custom_deflate) {
- return settings->custom_deflate(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_deflate(out, outsize, in, insize, settings);
+ /*the custom deflate is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_deflate(out, outsize, in, insize, settings);
}
@@ -2213,10 +2220,16 @@ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const uns
/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
+ unsigned error;
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ error = settings->custom_zlib(out, outsize, in, insize, settings);
+ if(error) {
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
+ }
} else {
- unsigned error;
ucvector v = ucvector_init(*out, *outsize);
if(expected_size) {
/*reserve the memory to avoid intermediate reallocations*/
@@ -2226,8 +2239,8 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t exp
error = lodepng_zlib_decompressv(&v, in, insize, settings);
*out = v.data;
*outsize = v.size;
- return error;
}
+ return error;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2275,7 +2288,9 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in,
size_t insize, const LodePNGCompressSettings* settings) {
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_zlib(out, outsize, in, insize, settings);
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_zlib_compress(out, outsize, in, insize, settings);
}
@@ -2334,13 +2349,14 @@ const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT
void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) {
settings->ignore_adler32 = 0;
settings->ignore_nlen = 0;
+ settings->max_output_size = 0;
settings->custom_zlib = 0;
settings->custom_inflate = 0;
settings->custom_context = 0;
}
-const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0};
+const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0, 0};
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2357,7 +2373,7 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
/* ////////////////////////////////////////////////////////////////////////// */
-#ifndef LODEPNG_NO_COMPILE_CRC
+#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
@@ -2403,9 +2419,11 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) {
}
return r ^ 0xffffffffu;
}
-#else /* !LODEPNG_NO_COMPILE_CRC */
+#else /* LODEPNG_COMPILE_CRC */
+/*in this case, the function is only declared here, and must be defined externally
+so that it will be linked in*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
-#endif /* !LODEPNG_NO_COMPILE_CRC */
+#endif /* LODEPNG_COMPILE_CRC */
/* ////////////////////////////////////////////////////////////////////////// */
/* / Reading and writing PNG color channel bits / */
@@ -2443,7 +2461,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream,
/* ////////////////////////////////////////////////////////////////////////// */
unsigned lodepng_chunk_length(const unsigned char* chunk) {
- return lodepng_read32bitInt(&chunk[0]);
+ return lodepng_read32bitInt(chunk);
}
void lodepng_chunk_type(char type[5], const unsigned char* chunk) {
@@ -2493,34 +2511,32 @@ void lodepng_chunk_generate_crc(unsigned char* chunk) {
}
unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- const unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
@@ -2872,8 +2888,8 @@ static void LodePNGText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->text_keys = 0;
- dest->text_strings = 0;
+ dest->text_keys = NULL;
+ dest->text_strings = NULL;
dest->text_num = 0;
for(i = 0; i != source->text_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i]));
@@ -2932,10 +2948,10 @@ static void LodePNGIText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->itext_keys = 0;
- dest->itext_langtags = 0;
- dest->itext_transkeys = 0;
- dest->itext_strings = 0;
+ dest->itext_keys = NULL;
+ dest->itext_langtags = NULL;
+ dest->itext_transkeys = NULL;
+ dest->itext_strings = NULL;
dest->itext_num = 0;
for(i = 0; i != source->itext_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i],
@@ -3030,6 +3046,9 @@ void lodepng_info_init(LodePNGInfo* info) {
info->iccp_name = NULL;
info->iccp_profile = NULL;
+ info->sbit_defined = 0;
+ info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0;
+
LodePNGUnknownChunks_init(info);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
}
@@ -3924,7 +3943,7 @@ static unsigned auto_choose_color(LodePNGColorMode* mode_out,
if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize
&& mode_in->bitdepth == mode_out->bitdepth) {
/*If input should have same palette colors, keep original to preserve its order and prevent conversion*/
- lodepng_color_mode_cleanup(mode_out);
+ lodepng_color_mode_cleanup(mode_out); /*clears palette, keeps the above set colortype and bitdepth fields as-is*/
lodepng_color_mode_copy(mode_out, mode_in);
}
} else /*8-bit or 16-bit per channel*/ {
@@ -4093,10 +4112,12 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
case 0:
for(i = 0; i != length; ++i) recon[i] = scanline[i];
break;
- case 1:
+ case 1: {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth];
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + recon[j];
break;
+ }
case 2:
if(precon) {
for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i];
@@ -4106,24 +4127,56 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
break;
case 3:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u);
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u);
+ /* Unroll independent paths of this predictor. A 6x and 8x version is also possible but that adds
+ too much code. Whether this speeds up anything depends on compiler and settings. */
+ if(bytewidth >= 4) {
+ for(; i + 3 < length; i += 4, j += 4) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ recon[i + 3] = s3 + ((r3 + p3) >> 1u);
+ }
+ } else if(bytewidth >= 3) {
+ for(; i + 2 < length; i += 3, j += 3) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ }
+ } else if(bytewidth >= 2) {
+ for(; i + 1 < length; i += 2, j += 2) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ }
+ }
+ for(; i != length; ++i, ++j) recon[i] = scanline[i] + ((recon[j] + precon[i]) >> 1u);
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u);
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + (recon[j] >> 1u);
}
break;
case 4:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
- /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that
- adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */
+ /* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that
+ adds too much code. Whether this speeds up anything depends on compiler and settings. */
if(bytewidth >= 4) {
- for(; i + 3 < length; i += 4) {
- size_t j = i - bytewidth;
+ for(; i + 3 < length; i += 4, j += 4) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
@@ -4134,8 +4187,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 3] = s3 + paethPredictor(r3, p3, q3);
}
} else if(bytewidth >= 3) {
- for(; i + 2 < length; i += 3) {
- size_t j = i - bytewidth;
+ for(; i + 2 < length; i += 3, j += 3) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
@@ -4145,8 +4197,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
}
} else if(bytewidth >= 2) {
- for(; i + 1 < length; i += 2) {
- size_t j = i - bytewidth;
+ for(; i + 1 < length; i += 2, j += 2) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
@@ -4156,16 +4207,17 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
}
}
- for(; i != length; ++i) {
- recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
+ for(; i != length; ++i, ++j) {
+ recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j]));
}
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = scanline[i];
}
- for(i = bytewidth; i < length; ++i) {
+ for(i = bytewidth; i != length; ++i, ++j) {
/*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
- recon[i] = (scanline[i] + recon[i - bytewidth]);
+ recon[i] = (scanline[i] + recon[j]);
}
}
break;
@@ -4447,10 +4499,13 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
}
/*compressed text chunk (zTXt)*/
-static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, string2_begin;
char *key = 0;
unsigned char* str = 0;
@@ -4473,12 +4528,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(error) break;
error = lodepng_add_text_sized(info, key, (char*)str, size);
-
break;
}
@@ -4489,11 +4546,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
}
/*international text chunk (iTXt)*/
-static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, begin, compressed;
char *key = 0, *langtag = 0, *transkey = 0;
@@ -4550,9 +4610,12 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(compressed) {
unsigned char* str = 0;
size_t size = 0;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
lodepng_free(str);
} else {
@@ -4628,11 +4691,13 @@ static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, siz
return 0; /* OK */
}
-static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
size_t size = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
unsigned length, string2_begin;
@@ -4655,13 +4720,57 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_icc_size;
error = zlib_decompress(&info->iccp_profile, &size, 0,
&data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: ICC profile larger than decoder->max_icc_size*/
+ if(error && size > zlibsettings.max_output_size) error = 113;
info->iccp_profile_size = size;
if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
return error;
}
+
+/*significant bits chunk (sBIT)*/
+static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ if(info->color.colortype == LCT_GREY) {
+ /*error: this chunk must be 1 bytes for grayscale image*/
+ if(chunkLength != 1) return 114;
+ if(data[0] == 0 || data[0] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ /*error: this chunk must be 3 bytes for RGB and palette image*/
+ if(chunkLength != 3) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ /*error: this chunk must be 2 byte for grayscale with alpha image*/
+ if(chunkLength != 2) return 114;
+ if(data[0] == 0 || data[1] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ info->sbit_a = data[1];
+ } else if(info->color.colortype == LCT_RGBA) {
+ /*error: this chunk must be 4 bytes for grayscale image*/
+ if(chunkLength != 4) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ info->sbit_a = data[3];
+ }
+
+ return 0; /* OK */
+}
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
@@ -4676,7 +4785,7 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
chunkLength = lodepng_chunk_length(chunk);
if(chunkLength > 2147483647) return 63;
data = lodepng_chunk_data_const(chunk);
- if(data + chunkLength + 4 > in + insize) return 30;
+ if(chunkLength + 12 > insize - pos) return 30;
if(lodepng_chunk_type_equals(chunk, "PLTE")) {
error = readChunk_PLTE(&state->info_png.color, data, chunkLength);
@@ -4688,9 +4797,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "tEXt")) {
error = readChunk_tEXt(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
- error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
- error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
error = readChunk_tIME(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "pHYs")) {
@@ -4702,7 +4811,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "sRGB")) {
error = readChunk_sRGB(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ error = readChunk_sBIT(&state->info_png, data, chunkLength);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else {
/* unhandled chunk is ok (is not an error) */
@@ -4721,7 +4832,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
LodePNGState* state,
const unsigned char* in, size_t insize) {
unsigned char IEND = 0;
- const unsigned char* chunk;
+ const unsigned char* chunk; /*points to beginning of next chunk*/
unsigned char* idat; /*the data from idat chunks, zlib compressed*/
size_t idatsize = 0;
unsigned char* scanlines = 0;
@@ -4757,14 +4868,15 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
while(!IEND && !state->error) {
unsigned chunkLength;
const unsigned char* data; /*the data in the chunk*/
+ size_t pos = (size_t)(chunk - in);
- /*error: size of the in buffer too small to contain next chunk*/
- if((size_t)((chunk - in) + 12) > insize || chunk < in) {
+ /*error: next chunk out of bounds of the in buffer*/
+ if(chunk < in || pos + 12 > insize) {
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 30);
}
- /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
+ /*length of the data of the chunk, excluding the 12 bytes for length, chunk type and CRC*/
chunkLength = lodepng_chunk_length(chunk);
/*error: chunk length larger than the max PNG chunk size*/
if(chunkLength > 2147483647) {
@@ -4772,8 +4884,8 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
CERROR_BREAK(state->error, 63);
}
- if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) {
- CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
+ if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) {
+ CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk (or int overflow)*/
}
data = lodepng_chunk_data_const(chunk);
@@ -4820,13 +4932,13 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
/*compressed text chunk (zTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
/*international text chunk (iTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
@@ -4845,7 +4957,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
state->error = readChunk_sRGB(&state->info_png, data, chunkLength);
if(state->error) break;
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- state->error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ if(state->error) break;
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ state->error = readChunk_sBIT(&state->info_png, data, chunkLength);
if(state->error) break;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else /*it's not an implemented chunk type, so ignore it: skip over the data*/ {
@@ -4871,7 +4986,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize);
}
- if(state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
+ if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */
}
@@ -4955,6 +5070,11 @@ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, co
lodepng_state_init(&state);
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*disable reading things that this function doesn't output*/
+ state.decoder.read_text_chunks = 0;
+ state.decoder.remember_unknown_chunks = 0;
+#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
error = lodepng_decode(out, w, h, &state, in, insize);
lodepng_state_cleanup(&state);
return error;
@@ -4997,6 +5117,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
settings->read_text_chunks = 1;
settings->remember_unknown_chunks = 0;
+ settings->max_text_size = 16777216;
+ settings->max_icc_size = 16777216; /* 16MB is much more than enough for any reasonable ICC profile */
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
settings->ignore_crc = 0;
settings->ignore_critical = 0;
@@ -5075,6 +5197,10 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) {
unsigned char* chunk;
size_t i, j = 8;
+ if(info->palettesize == 0 || info->palettesize > 256) {
+ return 68; /*invalid palette size, it is only allowed to be 1-256*/
+ }
+
CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE"));
for(i = 0; i != info->palettesize; ++i) {
@@ -5330,6 +5456,42 @@ static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCom
return error;
}
+static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ unsigned char* chunk = 0;
+ if(info->color.colortype == LCT_GREY) {
+ if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT"));
+ chunk[8] = info->sbit_r;
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ if(info->sbit_r == 0 || info->sbit_a == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_a;
+ } else if(info->color.colortype == LCT_RGBA) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 ||
+ info->sbit_r > bitdepth || info->sbit_g > bitdepth ||
+ info->sbit_b > bitdepth || info->sbit_a > bitdepth) {
+ return 115;
+ }
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ chunk[11] = info->sbit_a;
+ }
+ if(chunk) lodepng_chunk_generate_crc(chunk);
+ return 0;
+}
+
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline,
@@ -5775,8 +5937,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
ucvector outv = ucvector_init(NULL, 0);
LodePNGInfo info;
const LodePNGInfo* info_png = &state->info_png;
+ LodePNGColorMode auto_color;
lodepng_info_init(&info);
+ lodepng_color_mode_init(&auto_color);
/*provide some proper output values if error will happen*/
*out = 0;
@@ -5786,6 +5950,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*check input values validity*/
if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
&& (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) {
+ /*this error is returned even if auto_convert is enabled and thus encoder could
+ generate the palette by itself: while allowing this could be possible in theory,
+ it may complicate the code or edge cases, and always requiring to give a palette
+ when setting this color type is a simpler contract*/
state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
goto cleanup;
}
@@ -5806,6 +5974,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
lodepng_info_copy(&info, &state->info_png);
if(state->encoder.auto_convert) {
LodePNGColorStats stats;
+ unsigned allow_convert = 1;
lodepng_color_stats_init(&stats);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined &&
@@ -5827,23 +5996,85 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*the background chunk's color must be taken into account as well*/
unsigned r = 0, g = 0, b = 0;
LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
- lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
+ lodepng_convert_rgb(&r, &g, &b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
state->error = lodepng_color_stats_add(&stats, r, g, b, 65535);
if(state->error) goto cleanup;
}
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
- state->error = auto_choose_color(&info.color, &state->info_raw, &stats);
+ state->error = auto_choose_color(&auto_color, &state->info_raw, &stats);
if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
- /*also convert the background chunk*/
- if(info_png->background_defined) {
- if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
- info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
- state->error = 104;
- goto cleanup;
+ if(info_png->sbit_defined) {
+ /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes,
+ auto_convert can't be done in many cases. However, do support a few cases here.
+ TODO: more conversions may be possible, and it may also be possible to get a more appropriate color type out of
+ auto_choose_color if knowledge about sbit is used beforehand
+ */
+ unsigned sbit_max = LODEPNG_MAX(LODEPNG_MAX(LODEPNG_MAX(info_png->sbit_r, info_png->sbit_g),
+ info_png->sbit_b), info_png->sbit_a);
+ unsigned equal = (!info_png->sbit_g || info_png->sbit_g == info_png->sbit_r)
+ && (!info_png->sbit_b || info_png->sbit_b == info_png->sbit_r)
+ && (!info_png->sbit_a || info_png->sbit_a == info_png->sbit_r);
+ allow_convert = 0;
+ if(info.color.colortype == LCT_PALETTE &&
+ auto_color.colortype == LCT_PALETTE) {
+ /* input and output are palette, and in this case it may happen that palette data is
+ expected to be copied from info_raw into the info_png */
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGB to palette (or 16-bit as long as sbit_max <= 8) is possible
+ since both are 8-bit RGB for sBIT's purposes*/
+ if(info.color.colortype == LCT_RGB &&
+ auto_color.colortype == LCT_PALETTE && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/
+ if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE &&
+ info_png->sbit_a == 8 && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/
+ if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth == 16 &&
+ auto_color.colortype == info.color.colortype && auto_color.bitdepth == 8 &&
+ sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going to less channels is ok if all bit values are equal (all possible values in sbit,
+ as well as the chosen bitdepth of the result). Due to how auto_convert works,
+ we already know that auto_color.colortype has less than or equal amount of channels than
+ info.colortype. Palette is not used here. This conversion is not allowed if
+ info_png->sbit_r < auto_color.bitdepth, because specifically for alpha, non-presence of
+ an sbit value heavily implies that alpha's bit depth is equal to the PNG bit depth (rather
+ than the bit depths set in the r, g and b sbit values, by how the PNG specification describes
+ handling tRNS chunk case with sBIT), so be conservative here about ignoring user input.*/
+ if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE &&
+ equal && info_png->sbit_r == auto_color.bitdepth) {
+ allow_convert = 1;
}
}
+#endif
+ if(state->encoder.force_palette) {
+ if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
+ (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
+ /*user speficially forced a PLTE palette, so cannot convert to grayscale types because
+ the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
+ allow_convert = 0;
+ }
+ }
+ if(allow_convert) {
+ lodepng_color_mode_copy(&info.color, &auto_color);
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*also convert the background chunk*/
+ if(info_png->background_defined) {
+ if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
+ state->error = 104;
+ goto cleanup;
+ }
+ }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+ }
}
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined) {
@@ -5914,6 +6145,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
state->error = addChunk_cHRM(&outv, &info);
if(state->error) goto cleanup;
}
+ if(info_png->sbit_defined) {
+ state->error = addChunk_sBIT(&outv, &info);
+ if(state->error) goto cleanup;
+ }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
/*PLTE*/
if(info.color.colortype == LCT_PALETTE) {
@@ -6020,6 +6255,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
cleanup:
lodepng_info_cleanup(&info);
lodepng_free(data);
+ lodepng_color_mode_cleanup(&auto_color);
/*instead of cleaning the vector up, give it to the output*/
*out = outv.data;
@@ -6204,6 +6440,18 @@ const char* lodepng_error_text(unsigned code) {
case 106: return "PNG file must have PLTE chunk if color type is palette";
case 107: return "color convert from palette mode requested without setting the palette data in it";
case 108: return "tried to add more than 256 values to a palette";
+ /*this limit can be configured in LodePNGDecompressSettings*/
+ case 109: return "tried to decompress zlib or deflate data larger than desired max_output_size";
+ case 110: return "custom zlib or inflate decompression failed";
+ case 111: return "custom zlib or deflate compression failed";
+ /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large text sizes.*/
+ case 112: return "compressed text unreasonably large";
+ /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large ICC profile*/
+ case 113: return "ICC profile unreasonably large";
+ case 114: return "sBIT chunk has wrong size for the color type of the image";
+ case 115: return "sBIT value out of range";
}
return "unknown error code";
}
@@ -6240,7 +6488,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si
size_t buffersize = 0;
unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6259,7 +6507,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size
size_t buffersize = 0;
unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6304,7 +6552,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6322,7 +6570,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize);
if(buffer && !error) {
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6354,7 +6602,7 @@ unsigned encode(std::vector& out, const unsigned char* in, unsign
size_t buffersize;
unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6374,7 +6622,7 @@ unsigned encode(std::vector& out,
size_t buffersize;
unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
diff --git a/Tools/NGN_CollisionMap/source/lodepng/lodepng.h b/Tools/NGN_CollisionMap/source/lodepng/lodepng.h
index a386459..fdafc77 100644
--- a/Tools/NGN_CollisionMap/source/lodepng/lodepng.h
+++ b/Tools/NGN_CollisionMap/source/lodepng/lodepng.h
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
@@ -142,16 +161,24 @@ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,
/*
Load PNG from disk, from file with given name.
Same as the other decode functions, but instead takes a filename as input.
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
-/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -191,17 +218,26 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize,
/*
Converts raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode32_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
-/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode24_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -223,6 +259,9 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
/*
Converts PNG file from disk to raw pixel data in memory.
Same as the other decode functions, but instead takes a filename as input.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned decode(std::vector& out, unsigned& w, unsigned& h,
const std::string& filename,
@@ -243,7 +282,11 @@ unsigned encode(std::vector& out,
/*
Converts 32-bit RGBA raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned encode(const std::string& filename,
const unsigned char* in, unsigned w, unsigned h,
@@ -270,12 +313,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -341,8 +393,10 @@ typedef struct LodePNGColorMode {
The alpha channels must be set as well, set them to 255 for opaque images.
- When decoding, by default you can ignore this palette, since LodePNG already
- fills the palette colors in the pixels of the raw RGBA output.
+ When decoding, with the default settings you can ignore this palette, since
+ LodePNG already fills the palette colors in the pixels of the raw RGBA output,
+ but when decoding to the original PNG color mode it is needed to reconstruct
+ the colors.
The palette is only supported for color type 3.
*/
@@ -432,10 +486,12 @@ typedef struct LodePNGInfo {
with values truncated to the bit depth in the unsigned integer.
For grayscale and palette PNGs, the value is stored in background_r. The values
- in background_g and background_b are then unused.
+ in background_g and background_b are then unused. The decoder will set them
+ equal to background_r, the encoder ignores them in this case.
- So when decoding, you may get these in a different color mode than the one you requested
- for the raw pixels.
+ When decoding, you may get these in a different color mode than the one you requested
+ for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the
+ ones defined in the header of the PNG image, are used.
When encoding with auto_convert, you must use the color model defined in info_png.color for
these values. The encoder normally ignores info_png.color when auto_convert is on, but will
@@ -454,30 +510,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -496,7 +558,7 @@ typedef struct LodePNGInfo {
unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
/*
- Color profile related chunks: gAMA, cHRM, sRGB, iCPP
+ Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
@@ -559,6 +621,45 @@ typedef struct LodePNGInfo {
unsigned char* iccp_profile;
unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+ /*
+ sBIT chunk: significant bits. Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+ sample depth, such as 10 or 12.
+
+ Encoders using this value, when storing the pixel data, should use the most significant bits
+ of the data to store the original bits, and use a good sample depth scaling method such as
+ "left bit replication" to fill in the least significant bits, rather than fill zeroes.
+
+ Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right
+ shift the data to go back to the original bit depth, but decoders are also allowed to ignore
+ sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks
+ to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.
+
+ For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color
+ type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with
+ translucent palette values, or images with color key). The values that are used must be
+ greater than zero and smaller than or equal to the PNG bit depth.
+
+ The color type from the header in the PNG image defines these used and unused fields: if
+ decoding with a color mode conversion, such as always decoding to RGBA, this metadata still
+ only uses the color type of the original PNG, and may e.g. lack the alpha channel info
+ if the PNG was RGB. When encoding with auto_convert (as well as without), also always the
+ color model defined in info_png.color determines this.
+
+ NOTE: enabling sbit can hurt compression, because the encoder can then not always use
+ auto_convert to choose a more optimal color mode for the data, because the PNG format has
+ strict requirements for the allowed sbit values in combination with color modes.
+ For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel
+ color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.
+ */
+ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/
+ unsigned sbit_r; /*red or gray component of significant bits*/
+ unsigned sbit_g; /*green component of significant bits*/
+ unsigned sbit_b; /*blue component of significant bits*/
+ unsigned sbit_a; /*alpha component of significant bits*/
+
/* End of color profile related chunks */
@@ -639,8 +740,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -720,7 +832,11 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
- If colortype is 3, PLTE is _always_ created.*/
+ If colortype is 3, PLTE is always created. If color type is explicitely set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+ optimal color mode, because it cannot use grayscale color modes in this case*/
unsigned force_palette;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
/*add LodePNG identifier and version as a text chunk, for debugging*/
@@ -774,8 +890,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h,
#endif /*LODEPNG_COMPILE_DECODER*/
/*
-Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it
-read in the state. Returns error code on failure.
+Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)
+of the PNG file and outputs what it read in the state. Returns error code on failure.
Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const
to find the desired chunk type, and if non null use lodepng_inspect_chunk (with
chunk_pointer - start_of_file as pos).
@@ -950,6 +1066,9 @@ out: output parameter, contains pointer to loaded buffer.
outsize: output parameter, size of the allocated out buffer
filename: the path to the file to load
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);
@@ -960,6 +1079,9 @@ buffer: the buffer to write
buffersize: size of the buffer to write
filename: the path to the file to save to
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -1000,12 +1122,18 @@ unsigned encode(std::vector& out,
/*
Load a file from disk into an std::vector.
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory
*/
unsigned load_file(std::vector& buffer, const std::string& filename);
/*
Save the binary data in an std::vector to a file on disk. The file is overwritten
without warning.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned save_file(const std::vector& buffer, const std::string& filename);
#endif /* LODEPNG_COMPILE_DISK */
@@ -1041,7 +1169,7 @@ unsigned compress(std::vector& out, const std::vector (2^31)-1
[ ] partial decoding (stream processing)
[X] let the "isFullyOpaque" function check color keys and transparent palettes too
@@ -1168,18 +1296,16 @@ The following features are supported by the decoder:
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
+ sBIT: significant bits
1.2. features not supported
---------------------------
-The following features are _not_ supported:
+The following features are not (yet) supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
-*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
- sBIT
- hIST
- sPLT
+*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks
2. C and C++ version
@@ -1505,6 +1631,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1678,6 +1809,9 @@ try to fix it if the compiler is modern and standards compliant.
This decoder example shows the most basic usage of LodePNG. More complex
examples can be found on the LodePNG website.
+NOTE: these examples do not support wide-character filenames, you can use an
+external method to handle such files and encode or decode in-memory
+
10.1. decoder C++ example
-------------------------
@@ -1775,6 +1909,12 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 13 jun 2022: added support for the sBIT chunk.
+*) 09 jan 2022: minor decoder speed improvements.
+*) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.
@@ -1941,5 +2081,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
*/
diff --git a/Tools/NGN_CollisionMap/source/main.cpp b/Tools/NGN_CollisionMap/source/main.cpp
index 1f555cb..da26198 100644
--- a/Tools/NGN_CollisionMap/source/main.cpp
+++ b/Tools/NGN_CollisionMap/source/main.cpp
@@ -1,15 +1,15 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a Mapa de Colisiones (.map)
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Archivo principal -
- Proyecto iniciado el 8 de Abril del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
@@ -22,150 +22,29 @@
#include
#include
#include
-#include
-// LodePNG
-#include "lodepng/lodepng.h"
+// Programa
+#include "collision_map.h"
+#include "defines.h"
-// CollisionMap class
-#include "map.h"
+/*** Main ***/
+int32_t main(int32_t argc, char* args[]) {
-/*** Version de N'gine ***/
-static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 0; // Version menor
-static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
-/*** Version del programa ***/
-static const int32_t PROGRAM_VERSION_MAJOR = 1; // Version mayor
-static const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
-static const int32_t PROGRAM_VERSION_PATCH = 2; // Version parche
-static const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
-
-
-
-/*** Mensages de error ***/
-void ErrorMsg() {
- std::cout << "Command line error." << std::endl;
- std::cout << "Usage: NGN_CollisionMap INPUT_FILE.PNG [-o filename] [-ts xx]" << std::endl;
- std::cout << "-o filename Name for the output file, without extension (.map will be added automaticaly)." << std::endl;
- std::cout << "-ts xx Size of the squared tile in pixels (From 8 to 1024, 32 pixels by default)." << std::endl << std::endl;
-}
-
-
+ // Crea el objeto principal del programa
+ CollisionMap* cmap = new CollisionMap(argc, args);
+ // Si no se crea con exito, sal del programa
+ if (!cmap) return ERR_CODE_BOOTFAILURE;
-/*** Main ***/
-int32_t main(int32_t argc, char* args[]) {
+ // Transfiere el control del objeto principal
+ int32_t r = cmap->Run();
- // Variables
- std::string in_file = ""; // Nombre del archivo de entrada
- std::string out_file = ""; // Nombre base de los archivos de salida
- uint32_t ts = 32; // Tamaño del tile
-
- // Variables de control
- bool _filename = false;
- bool _ts = false;
- bool _err = false;
-
- // Texto de bienvenida
- std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::cout <<
- std::endl << "N'gine PNG to Collision Map converter. (v" << program_version << ")." <<
- std::endl << "For N'gine Version " << ngn_version << " or higher." <<
- std::endl << "(cc) 2016 - 2022 by Cesar Rincon." <<
- std::endl << "https://nightfoxandco.com" <<
- std::endl << "contact@nightfoxandco.com" <<
- std::endl << std::endl;
-
-
- // Verifica la linea de comandos
- if ((argc < 2) || (argc > 8)) { // Nº de argumentos incorrecto
-
- ErrorMsg();
- return 1;
-
- } else { // Analiza los argumentos extra
-
- // Archivo de entrada
- in_file = args[1];
- if ((in_file.length() < 5) || (in_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
-
- for (int32_t i = 2; i < argc; i ++) {
-
- _err = true;
-
- if (strcmp(args[i], "-o") == 0) { // Comando -O
-
- if (((i + 1) < argc) && !_filename) {
- _filename = true;
- _err = false;
- out_file = args[(i + 1)];
- i ++;
- if ((out_file.length() < 1) || (out_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
-
- } else if (strcmp(args[i], "-ts") == 0) { // Comando -TS
-
- if (((i + 1) < argc) && !_ts) {
- _ts = true;
- _err = false;
- ts = atoi(args[(i + 1)]);
- i ++;
- if ((ts < 8) || (ts > 1024)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
-
- }
-
- }
-
- // Error de uso incorrecto de argumentos
- if (_err) {
- ErrorMsg();
- return 1;
- }
-
- }
-
- std::cout << std::endl;
-
-
- // Nombre del archivo de salida
- if (out_file == "") out_file = in_file.substr(0, (in_file.length() - 4));
-
- /*** Parametros aceptados, crea el objeto principal ***/
- CollisionMap* cmap = new CollisionMap();
-
- // Aplica los parametros por defecto
- cmap->input_filename = in_file;
- cmap->output_filename = out_file;
- cmap->tile_size = ts;
-
- // Carga y convierte la imagen PNG en un mapa de colisiones
- cmap->ConvertPng();
-
- /*** Proceso completado, destruye el objeto principal ***/
+ // Elimina el objeto principal
delete cmap;
-
- // Fin del programa
- return 0;
+ // Devuelve el resultado de ejecucion del programa
+ return r;
}
diff --git a/Tools/NGN_CollisionMap/source/map.h b/Tools/NGN_CollisionMap/source/map.h
deleted file mode 100644
index d0a94e2..0000000
--- a/Tools/NGN_CollisionMap/source/map.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/******************************************************************************
-
- N'gine Lib for C++
- Conversor de PNG a Mapa de Colisiones (.map)
-
- Proyecto iniciado el 8 de Abril del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
- https://nightfoxandco.com
- contact@nightfoxandco.com
-
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
- http://lodev.org/lodepng/
-
-******************************************************************************/
-
-
-
-#ifndef MAP_H_INCLUDED
-#define MAP_H_INCLUDED
-
-
-
-/*** Includes ***/
-#include
-#include
-
-
-
-/*** Defines ***/
-static const int32_t VERSION = 2; // Version del archivo
-static const std::string MAGIC_STRING = "NGN COLLISION MAP"; // Magic string
-
-
-
-/*** Estructuras personalizadas ***/
-
-// Pixel RGBA
-struct rgba_pixel {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
-};
-
-// Cabecera del archivo
-struct file_header {
- uint8_t version; // Version del programa de conversion
- char magic[32]; // Magic String
- uint32_t width; // Ancho del mapa
- uint32_t height; // Alto del mapa
- uint32_t tile_size; // Tamaño del tile
- uint32_t pal_length; // Tamaño de los datos (nº de elementos) de la paleta
- uint32_t tileset_length; // Tamaño de los datos (nº de elementos) del tileset
- uint32_t map_length; // Tamaño de los datos (nº de elementos) del mapa
- uint8_t reserve[256]; // Posible uso futuro
-};
-
-
-
-/*** Declaracion de la clase ***/
-class CollisionMap {
-
- // Public
- public:
-
- // Constructor
- CollisionMap();
-
- // Destructor
- ~CollisionMap();
-
- /*** Propiedades ***/
-
- std::string input_filename; // Fichero de entrada
- std::string output_filename; // Nombre base del archivo de salida
- uint32_t tile_size; // Tamaño del tile
-
-
- /*** Metodos ***/
-
- // Convierte el archivo
- int32_t ConvertPng();
-
-
-
- // Private
- private:
-
- /*** Propiedades ***/
-
- // Define los vectores de memoria temporales
- std::vector png; // Buffer para almacenar la imagen PNG
- std::vector raw; // Buffer para almacenar los pixeles de la imagen de entrada
- std::vector bitmap; // Buffer para almacenar el mapa de pixeles
- // Define los vectores de memoria para el archivo de guardado
- std::vector palette; // Buffer para almacenar la paleta de colores
- std::vector tiles; // Buffer para almacenar los pixeles de los tiles
- std::vector tmap; // Buffer para almacenar el mapa de tiles
- // Define los vectores de memoria temporales
- std::vector t_palette; // Buffer para almacenar la paleta de colores
- std::vector t_tiles; // Buffer para almacenar los pixeles de los tiles
- std::vector t_tl; // Buffer para almacenar un tile
-
- // Parametros de las imagenes
- uint32_t in_width, in_height; // Tamaño del archivo de entrada
- uint32_t out_width, out_height; // Tamaño del archivo de salida
-
- // Parametros del mapa
- uint32_t pal_length;
- uint32_t tileset_length;
- uint32_t map_length;
-
- // Cabecera del archivo de salida
- file_header header;
-
-
- /*** Metodos ***/
-
- // Lee el archivo PNG y almacena los pixeles de la imagen en el buffer
- int32_t ReadPNG(std::string filename, std::vector &data);
-
- // Graba el archivo empaquetado
- int32_t WriteFile(std::string filename);
-
- // Lee un pixel del buffer especificado
- uint32_t GetPixel(std::vector &data, uint32_t offset);
-
- // Genera el la paleta y el bitmap de colisiones
- int32_t GenerateBitmap();
-
- // Genera la cabecera del archivo
- void GenerateHeader();
-
- // Genera los tiles y el mapa
- void GenerateMap();
-
- // Obten un tile del bitmap
- void GetTile(uint32_t pos_x, uint32_t pos_y);
-
-};
-
-
-
-#endif // MAP_H_INCLUDED
diff --git a/Tools/NGN_CollisionMap/source/message.cpp b/Tools/NGN_CollisionMap/source/message.cpp
new file mode 100644
index 0000000..7e93b74
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/message.cpp
@@ -0,0 +1,104 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+
+// Includes del proyecto
+#include "message.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+Message::Message(std::string pname) {
+
+ // Guarda el nombre del ejecutable del programa
+ program_name = pname;
+
+}
+
+
+
+/*** Destructor ***/
+Message::~Message() {
+
+}
+
+
+
+/*** Texto de encabezado de la aplicacion ***/
+void Message::AppHeader() {
+
+ // Genera las cadenas de texto adicionales
+ std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
+ std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + PROGRAM_VERSION_METADATA;
+
+ // Imprime el texto
+ std::cout <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl <<
+ std::endl << " " << PROGRAM_NAME << ". (v" << program_version << ")." <<
+ std::endl << " For N'gine Version " << ngn_version << " or higher." <<
+ std::endl << " (cc) " << CC_YEARS << " by Cesar Rincon." <<
+ std::endl << " https://nightfoxandco.com" <<
+ std::endl << " contact@nightfoxandco.com" <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Como obtener ayuda" ***/
+void Message::QuestionMarkForHelp() {
+
+ std::cout << "Type " << program_name << " " << ARG_HELP << " to display the on-screen help manual." << std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Error de uso" ***/
+void Message::UseError() {
+
+ std::cout << "Command line error." << std::endl;
+
+}
+
+
+
+/*** Texto "Manual de uso" ***/
+void Message::UserManual() {
+
+ std::cout << std::endl;
+ std::cout << program_name << " INPUT_FILE.PNG [" << ARG_OUT_FILE << " filename] [" << ARG_TILE_SIZE << " xxxx]" << std::endl;
+ std::cout << std::endl;
+ std::cout << ARG_HELP << " Displays the on-screen user manual (this screen)." << std::endl;
+ std::cout << ARG_OUT_FILE << " Name for the output file, without extension (" << MAP_EXTENSION << " will be added automaticaly)." << std::endl;
+ std::cout << ARG_TILE_SIZE << " Size of the squared tile in pixels (From [" << MIN_TILE_SIZE << "] to [" << MAX_TILE_SIZE << "], " << DEFAULT_TILE_SIZE << " pixels by default)." << std::endl;
+ std::cout << std::endl;
+
+}
diff --git a/Tools/NGN_CollisionMap/source/message.h b/Tools/NGN_CollisionMap/source/message.h
new file mode 100644
index 0000000..ef1fab7
--- /dev/null
+++ b/Tools/NGN_CollisionMap/source/message.h
@@ -0,0 +1,67 @@
+/******************************************************************************
+
+ Conversor de PNG a Mapa de Colisiones (.map) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef MESSAGE_H_INCLUDED
+#define MESSAGE_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class Message {
+
+ public:
+
+ // Constructor
+ Message(std::string pname);
+
+ // Destructor
+ ~Message();
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+ void AppHeader(); // Texto de cabecera de la aplicacion
+ void QuestionMarkForHelp(); // -? para mostrar la ayuda
+ void UseError(); // Error del uso
+ void UserManual(); // Manual del usuario
+
+
+ private:
+
+ /*** Propiedades ***/
+ std::string program_name; // Nombre del archivo ejecutable
+
+
+
+ /*** Metodos ***/
+
+};
+
+
+
+#endif // MESSAGE_H_INCLUDED
diff --git a/Tools/NGN_FileSystem/NGN_FileSystem.cbp b/Tools/NGN_FileSystem/NGN_FileSystem.cbp
index c41bd59..9b5adb2 100644
--- a/Tools/NGN_FileSystem/NGN_FileSystem.cbp
+++ b/Tools/NGN_FileSystem/NGN_FileSystem.cbp
@@ -61,7 +61,7 @@
-
+
diff --git a/Tools/NGN_FileSystem/source/cryptography.cpp b/Tools/NGN_FileSystem/source/cryptography.cpp
index a52d32f..3e3843d 100644
--- a/Tools/NGN_FileSystem/source/cryptography.cpp
+++ b/Tools/NGN_FileSystem/source/cryptography.cpp
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
- Funciones criptograficas
+ Sistema de empaquetado de archivos para N'gine
+ - Funciones criptograficas -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_FileSystem/source/cryptography.h b/Tools/NGN_FileSystem/source/cryptography.h
index feb7bb2..c5ae246 100644
--- a/Tools/NGN_FileSystem/source/cryptography.h
+++ b/Tools/NGN_FileSystem/source/cryptography.h
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
- Funciones criptograficas
+ Sistema de empaquetado de archivos para N'gine
+ - Funciones criptograficas -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_FileSystem/source/defines.h b/Tools/NGN_FileSystem/source/defines.h
index 7de2d99..fbbab0d 100644
--- a/Tools/NGN_FileSystem/source/defines.h
+++ b/Tools/NGN_FileSystem/source/defines.h
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
- Definiciones
+ Sistema de empaquetado de archivos para N'gine
+ - Definiciones -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -23,51 +22,51 @@
/*** Codigos de ERROR ***/
-static const int32_t ERR_CODE_OK = 0x00;
-static const int32_t ERR_CODE_BOOTFAILURE = 0x01;
-static const int32_t ERR_CODE_ARG_INVALID = 0x02;
-static const int32_t ERR_CODE_INDIR_EMPTY = 0x03;
-static const int32_t ERR_CODE_OUTFILE_FAILS = 0x04;
-static const int32_t ERR_CODE_EXTRACT_FAILS = 0x05;
-static const int32_t ERR_CODE_INFILE_EMPTY = 0x06;
+const int32_t ERR_CODE_OK = 0x00;
+const int32_t ERR_CODE_BOOTFAILURE = 0x01;
+const int32_t ERR_CODE_ARG_INVALID = 0x02;
+const int32_t ERR_CODE_INDIR_EMPTY = 0x03;
+const int32_t ERR_CODE_OUTFILE_FAILS = 0x04;
+const int32_t ERR_CODE_EXTRACT_FAILS = 0x05;
+const int32_t ERR_CODE_INFILE_EMPTY = 0x06;
/*** Version de N'gine ***/
-static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 6; // Version menor
-static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "beta"; // Version metadatos
+const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
+const int32_t NGN_VERSION_MINOR = 11; // Version menor
+const int32_t NGN_VERSION_PATCH = 0; // Version parche
+const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
/*** Version del programa ***/
-static const std::string PROGRAM_NAME = "N'gine file system manager"; // Nombre del programa
-static const std::string CC_YEARS = "2021-2022"; // Años en el texto CREATIVE COMMONS
-static const int32_t PROGRAM_VERSION_MAJOR = 1; // Version mayor
-static const int32_t PROGRAM_VERSION_MINOR = 1; // Version menor
-static const int32_t PROGRAM_VERSION_PATCH = 1; // Version parche
-static const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
-static const std::string MAGIC_STRING = "NGN FILE SYSTEM"; // Magic string
-static const uint8_t MS_LENGTH = 15; // Logitud del magic string
-static const uint8_t VERSION = 2; // Version del archivo
+const std::string PROGRAM_NAME = "N'gine file system manager"; // Nombre del programa
+const std::string CC_YEARS = "2021-2023"; // Años en el texto CREATIVE COMMONS
+const int32_t PROGRAM_VERSION_MAJOR = 1; // Version mayor
+const int32_t PROGRAM_VERSION_MINOR = 3; // Version menor
+const int32_t PROGRAM_VERSION_PATCH = 0; // Version parche
+const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
+const std::string MAGIC_STRING = "NGN FILE SYSTEM"; // Magic string
+const uint8_t MS_LENGTH = 15; // Logitud del magic string
+const uint8_t VERSION = 2; // Version del archivo
/*** Textos recurrentes ***/
-static const std::string TEXT_DASHED_LINE = "------------------------------------------------------------";
+const std::string TEXT_DASHED_LINE = "------------------------------------------------------------";
/*** Listado de argumentos disponibles ***/
-static const int32_t ARG_MIN_NUM = 2; // Numero minimo de argumentos
-static const int32_t ARG_MAX_NUM = 7; // Numero maximo de argumentos
-static const std::string ARG_HELP = "-?"; // Ayuda
-static const std::string ARG_IN_DIR = "-idir"; // Define el directorio de origen
-static const std::string ARG_OUT_DIR = "-odir"; // Define el directorio de destino
-static const std::string ARG_IN_FILE = "-ifile"; // Define el archivo de origen
-static const std::string ARG_OUT_FILE = "-ofile"; // Define el archivo de destino
-static const std::string ARG_KEY = "-key"; // Define la clave de encriptado
+const int32_t ARG_MIN_NUM = 2; // Numero minimo de argumentos
+const int32_t ARG_MAX_NUM = 7; // Numero maximo de argumentos
+const std::string ARG_HELP = "-?"; // Ayuda
+const std::string ARG_IN_DIR = "-idir"; // Define el directorio de origen
+const std::string ARG_OUT_DIR = "-odir"; // Define el directorio de destino
+const std::string ARG_IN_FILE = "-ifile"; // Define el archivo de origen
+const std::string ARG_OUT_FILE = "-ofile"; // Define el archivo de destino
+const std::string ARG_KEY = "-key"; // Define la clave de encriptado
/*** Estructuras de datos ***/
-static const uint8_t CHK_SIZE = 32;
+const uint8_t CHK_SIZE = 32;
struct FatNode {
uint32_t next_node_offset; // Posicion del siguiente nodo
uint32_t path_length; // Numero de caracteres de la ruta
@@ -78,7 +77,7 @@ struct FatNode {
};
// Tamaño de los datos estaticos del nodo
-static const uint32_t NODE_SIZE = ((sizeof(uint32_t) * 4) + (sizeof(uint8_t) * CHK_SIZE));
+const uint32_t NODE_SIZE = ((sizeof(uint32_t) * 4) + (sizeof(uint8_t) * CHK_SIZE));
/*
diff --git a/Tools/NGN_FileSystem/source/file_system.cpp b/Tools/NGN_FileSystem/source/file_system.cpp
index d58dd45..abd03f1 100644
--- a/Tools/NGN_FileSystem/source/file_system.cpp
+++ b/Tools/NGN_FileSystem/source/file_system.cpp
@@ -1,10 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
+ - Sistema de archivos -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -370,7 +370,7 @@ int32_t FileSystem::CreatePackage() {
void FileSystem::GenerateFileHeader() {
// Borra el contenido de la estructura
- memset(&file_header, 0, sizeof(file_header));
+ memset((void*)&file_header, 0, sizeof(file_header));
// Datos de la cabecera
file_header.version = VERSION;
@@ -721,7 +721,7 @@ int32_t FileSystem::ExtractPackage() {
int32_t FileSystem::ReadFileHeader() {
// Borra el contenido de la estructura
- memset(&file_header, 0, sizeof(file_header));
+ memset((void*)&file_header, 0, sizeof(file_header));
// Intenta abrir el archivo en modo binario
const char* path = arg_in_file.value.c_str();
diff --git a/Tools/NGN_FileSystem/source/file_system.h b/Tools/NGN_FileSystem/source/file_system.h
index 5c57034..cc65a02 100644
--- a/Tools/NGN_FileSystem/source/file_system.h
+++ b/Tools/NGN_FileSystem/source/file_system.h
@@ -1,10 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
+ - Sistema de archivos -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_FileSystem/source/fs_manager.cpp b/Tools/NGN_FileSystem/source/fs_manager.cpp
index 557203f..fc09cd2 100644
--- a/Tools/NGN_FileSystem/source/fs_manager.cpp
+++ b/Tools/NGN_FileSystem/source/fs_manager.cpp
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
- Gestor de sistema de archivos del sistema -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_FileSystem/source/fs_manager.h b/Tools/NGN_FileSystem/source/fs_manager.h
index 0df1f0f..f925ff5 100644
--- a/Tools/NGN_FileSystem/source/fs_manager.h
+++ b/Tools/NGN_FileSystem/source/fs_manager.h
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
- Gestor de sistema de archivos del sistema -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_FileSystem/source/main.cpp b/Tools/NGN_FileSystem/source/main.cpp
index 17ff610..028429d 100644
--- a/Tools/NGN_FileSystem/source/main.cpp
+++ b/Tools/NGN_FileSystem/source/main.cpp
@@ -1,16 +1,41 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a Mapa de Colisiones (.map)
+ Sistema de empaquetado de archivos para N'gine
- Proyecto iniciado el 8 de Abril del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ Proyecto iniciado el 14 de Febrero del 2021
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
- http://lodev.org/lodepng/
+
+ N'gine se distribuye bajo la licencia CREATIVE COMMONS
+ "Attribution-NonCommercial 4.0 International"
+ https://creativecommons.org/licenses/by-nc/4.0/
+
+ You are free to:
+
+ - Share
+ copy and redistribute the material in any medium or format.
+ - Adapt
+ remix, transform, and build upon the material.
+
+ The licensor cannot revoke these freedoms as long as you follow
+ the license terms.
+
+ Under the following terms:
+
+ - Attribution
+ You must give appropriate credit, provide a link to the license,
+ and indicate if changes were made. You may do so in any reasonable
+ manner, but not in any way that suggests the licensor endorses you
+ or your use.
+
+ - NonCommercial
+ You may not use the material for commercial purposes.
+
+ - No additional restrictions
+ You may not apply legal terms or technological measures that
+ legally restrict others from doing anything the license permits.
******************************************************************************/
diff --git a/Tools/NGN_FileSystem/source/message.cpp b/Tools/NGN_FileSystem/source/message.cpp
index 16aafea..346eff4 100644
--- a/Tools/NGN_FileSystem/source/message.cpp
+++ b/Tools/NGN_FileSystem/source/message.cpp
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
- Sistema de mensages -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
@@ -56,11 +55,11 @@ void Message::AppHeader() {
std::endl <<
std::endl << TEXT_DASHED_LINE <<
std::endl <<
- std::endl << " " << PROGRAM_NAME << ". (v" << program_version << ")." <<
- std::endl << " For N'gine Version " << ngn_version << " or higher." <<
- std::endl << " (cc) " << CC_YEARS << " by Cesar Rincon." <<
- std::endl << " https://nightfoxandco.com" <<
- std::endl << " contact@nightfoxandco.com" <<
+ std::endl << " " << PROGRAM_NAME << ". (v" << program_version << ")." <<
+ std::endl << " For N'gine Version " << ngn_version << " or higher." <<
+ std::endl << " (cc) " << CC_YEARS << " by Cesar Rincon." <<
+ std::endl << " https://nightfoxandco.com" <<
+ std::endl << " contact@nightfoxandco.com" <<
std::endl <<
std::endl << TEXT_DASHED_LINE <<
std::endl << std::endl;
@@ -91,8 +90,8 @@ void Message::UseError() {
void Message::UserManual() {
std::cout << std::endl;
- std::cout << program_name << " -idir DIRECTORY -ofile FILE [-key ENCRYPTION_KEY]" << std::endl;
- std::cout << program_name << " -ifile FILE -odir DIRECTORY [-key ENCRYPTION_KEY]" << std::endl;
+ std::cout << program_name << " " << ARG_IN_DIR << " DIRECTORY " << ARG_OUT_FILE << " FILE [" << ARG_KEY << " ENCRYPTION_KEY]" << std::endl;
+ std::cout << program_name << " " << ARG_IN_FILE << " FILE " << ARG_OUT_DIR << " DIRECTORY [" << ARG_KEY << " ENCRYPTION_KEY]" << std::endl;
std::cout << std::endl;
std::cout << ARG_HELP << " Displays the on-screen user manual (this screen)." << std::endl;
std::cout << ARG_IN_DIR << " Source folder with the files to add (and encrypt)." << std::endl;
diff --git a/Tools/NGN_FileSystem/source/message.h b/Tools/NGN_FileSystem/source/message.h
index 6dcfb48..9202f1d 100644
--- a/Tools/NGN_FileSystem/source/message.h
+++ b/Tools/NGN_FileSystem/source/message.h
@@ -1,11 +1,10 @@
/******************************************************************************
- N'gine Lib for C++
- Sistema de archivos
+ Sistema de empaquetado de archivos para N'gine
- Sistema de mensages -
Proyecto iniciado el 14 de Febrero del 2021
- (cc) 2021 by Cesar Rincon "NightFox"
+ (cc) 2021 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
diff --git a/Tools/NGN_Sprite/NGN_Sprite.cbp b/Tools/NGN_Sprite/NGN_Sprite.cbp
index 9b7573c..d3a1c29 100644
--- a/Tools/NGN_Sprite/NGN_Sprite.cbp
+++ b/Tools/NGN_Sprite/NGN_Sprite.cbp
@@ -13,6 +13,8 @@
+
+
@@ -23,6 +25,8 @@
+
+
@@ -35,6 +39,8 @@
+
+
@@ -45,6 +51,8 @@
+
+
@@ -53,22 +61,26 @@
-
+
+
+
+
+
+
+
+
-
-
-
diff --git a/Tools/NGN_Sprite/source/convert_to_sprite.cpp b/Tools/NGN_Sprite/source/convert_to_sprite.cpp
new file mode 100644
index 0000000..3d4f903
--- /dev/null
+++ b/Tools/NGN_Sprite/source/convert_to_sprite.cpp
@@ -0,0 +1,308 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - ConvertToSprite -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+#include
+
+// LodePNG
+#include "lodepng/lodepng.h"
+
+// Includes del proyecto
+#include "convert_to_sprite.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+ConvertToSprite::ConvertToSprite() {
+
+ in_width = 0;
+ in_height = 0;
+ out_width = 0;
+ out_height = 0;
+
+ frame_width = 0;
+ frame_height = 0;
+ total_frames = 0;
+
+ sprite_strip = false;
+
+ sheet.clear();
+
+}
+
+
+
+/*** Destructor ***/
+ConvertToSprite::~ConvertToSprite() {
+
+ sheet.clear();
+
+}
+
+
+/*** Convierte un archivo PNG en un Sprite ***/
+bool ConvertToSprite::Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t frame_w, // Tamaño del tile
+ uint32_t frame_h, // Nivel de optimizacion
+ bool strip // Generar archivos adicionales?
+) {
+
+ // Prepara el buffer para los pixeles de la imagen
+ std::vector png_pixels;
+ png_pixels.clear();
+
+ // Intenta abrir y decodificar el archivo PNG
+ if (!ReadPng(in_file, png_pixels)) return false;
+
+ // Verifica que el tamaño de imagen coincida con los datos del tamaño de fotograma
+ if (
+ (frame_w > in_width)
+ ||
+ (frame_h > in_height)
+ ||
+ ((in_width % frame_w) != 0)
+ ||
+ ((in_height % frame_h) != 0)
+ ) {
+ std::cout << "Image size doesn't fits the sprite frame size." << std::endl;
+ png_pixels.clear();
+ return false;
+ }
+
+ // Guarda los parametros del fotograma
+ frame_width = frame_w;
+ frame_height = frame_h;
+
+ // Guarda los datos adicionales
+ sprite_strip = strip;
+
+ // Corta el PNG en los diversos fotogramas que contiene y colocalos en una tira
+ CutFrames(png_pixels);
+
+ // Guarda en el archivo empaquetado los datos generados
+ bool r = WriteFile(out_file);
+
+ // Vacia los buffers usados
+ sheet.clear();
+ png_pixels.clear();
+
+ // Conversion con exito
+ return r;
+
+}
+
+
+/*** Corta y almacena los diferentes fotogramas del sprite ***/
+void ConvertToSprite::CutFrames(std::vector &data) {
+
+ // Variables
+ uint32_t img_x = 0, img_y = 0; // Punto de corte
+ uint32_t _frames_w = (uint32_t)std::floor(in_width / frame_width); // Numero de columnas de frames
+ uint32_t _frames_h = (uint32_t)std::floor(in_height / frame_height); // Numero de filas de frames
+ uint32_t _total_frames = (_frames_w * _frames_h); // Numero total de frames
+ uint32_t _current_frame = 0; // Fotograma actual
+
+ // Calcula el tamaño del archivo de salida
+ out_width = frame_width;
+ out_height = (_total_frames * frame_height);
+ // Y guarda el numero total de frames
+ total_frames = _total_frames;
+
+ // Prepara los bufferes a usar
+ sheet.clear();
+ sheet.resize(((out_width * out_height) << 2), 0); // * 4
+
+ // Marcador
+ std::cout << "This image contains " << _total_frames << " frames of " << frame_width << "x" << frame_height << " pixels." << std::endl;
+
+ // Variables del control de corte del frame
+ uint32_t src_pointer = 0, dst_pointer = 0;
+ uint32_t cut_x = 0, cut_y = 0;
+ uint32_t cut_start_x = 0, cut_end_x = 0, cut_start_y = 0, cut_end_y = 0;
+
+ // Corta la imagen en una tira de frames
+ for (img_y = 0; img_y <= (in_height - frame_height); img_y += frame_height) {
+ // Calcula el punto de corte (Y)
+ cut_start_y = img_y; cut_end_y = (cut_start_y + frame_height);
+ for (img_x = 0; img_x <= (in_width - frame_width); img_x += frame_width) {
+ // Contador de frames cortados
+ _current_frame ++;
+ std::cout << "\x0d" << "Cutting off " << _current_frame << " of " << _total_frames << " frames... ";
+ // Calcula el punto de corte (X)
+ cut_start_x = img_x; cut_end_x = (cut_start_x + frame_width);
+ // Bucle de corte
+ for (cut_y = cut_start_y; cut_y < cut_end_y; cut_y ++) {
+ for (cut_x = cut_start_x; cut_x < cut_end_x; cut_x ++) {
+ // Calcula el puntero de lectura
+ src_pointer = (((cut_y * in_width) + cut_x) << 2);
+ // Copia los 4 bytes del pixel de origen al buffer de destino
+ for (uint32_t n = src_pointer; n < (src_pointer + 4); n ++) {
+ sheet[dst_pointer] = data[n];
+ dst_pointer ++;
+ }
+ }
+ }
+ }
+ }
+
+ // Ok
+ std::cout << "done!" << std::endl;
+ std::cout << "Output sprite sheet size is " << out_width << "x" << out_height << " pixels." << std::endl;
+
+}
+
+
+
+/*** Graba el archivo empaquetado ***/
+bool ConvertToSprite::WriteFile(std::string filename) {
+
+ // Prepara el buffer temporal
+ std::vector spritesheet_png;
+ spritesheet_png.clear();
+
+ // Intenta codificar el Tileset a PNG
+ if (lodepng::encode(spritesheet_png, sheet, out_width, out_height) != 0) {
+ std::cout << "Error encoding the spritesheet image data." << std::endl;
+ spritesheet_png.clear();
+ return false;
+ }
+
+ // Guarda la informacion para la cabecera del archivo
+ FileHeader header;
+ memset((void*)&header, 0, sizeof(header));
+ header.version = VERSION; // Version del programa
+ strncpy(header.magic, MAGIC_STRING.c_str(), MAGIC_STRING.length()); // Magic String
+ header.sheet_width = out_width; // Dimensiones del strip
+ header.sheet_height = out_height;
+ header.frame_width = frame_width; // Dimensiones del frame
+ header.frame_height = frame_height;
+ header.total_frames = total_frames; // Numero de frames del sprite
+
+ // Genera el nombre de archivo
+ std::string fname = filename + SPR_EXTENSION;
+ const char* sprite_filename = fname.c_str();
+
+ // Graba el archivo principal
+ std::ofstream file;
+ file.open(sprite_filename, std::ofstream::out | std::ofstream::binary);
+ if (file.is_open()) {
+ file.write((char*)&header, sizeof(header)); // Cabecera
+ file.write((char*)&spritesheet_png[0], spritesheet_png.capacity()); // Sprite sheet en PNG
+ file.close();
+ std::cout << "File " << fname << " successfully saved." << std::endl;
+ } else {
+ std::cout << "Error saving " << fname << "." << std::endl;
+ return false;
+ }
+
+ // Elimia los datos del PNG del spritesheet
+ spritesheet_png.clear();
+
+ // Si no se requiere el archivo de tira de fotogramas, termina
+ if (!sprite_strip) return true;
+
+ // Guarda el tileset en PNG
+ fname = (filename + STRIP_EXTENSION);
+ if (!WritePng(fname, sheet, out_width, out_height)) return false;
+
+ // Todo correcto
+ return true;
+
+}
+
+
+
+/*** Lee un archivo .PNG y coloca los pixeles en un buffer ***/
+bool ConvertToSprite::ReadPng(std::string filename, std::vector &data) {
+
+ // Variables
+ uint32_t width = 0, height = 0; // Tamaño del archivo cargado
+
+ // Prepara el buffer temporal
+ std::vector png_data;
+ png_data.clear();
+
+ // Prepara el buffer para los datos decodificados
+ data.clear();
+
+ // Carga el archivo PNG
+ if (lodepng::load_file(png_data, filename) != 0) {
+ std::cout << "Error loading " << filename << "." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Si se ha cargado correctamente, decodifica la imagen
+ if (lodepng::decode(data, width, height, png_data) != 0) {
+ std::cout << "Error decoding " << filename << "." << std::endl;
+ png_data.clear();
+ data.clear();
+ return false;
+ }
+
+ // Guarda los tamaños de la imagen a convertir
+ in_width = width;
+ in_height = height;
+
+ // Borra el buffer temporal
+ png_data.clear();
+
+ // Fin de la funcion de carga
+ return true;
+
+}
+
+
+
+/*** Graba un buffer de pixeles en un archivo PNG ***/
+bool ConvertToSprite::WritePng(std::string filename, std::vector &data, uint32_t width, uint32_t height) {
+
+ // Prepara el buffer temporal
+ std::vector png_data;
+ png_data.clear();
+
+ // Intenta codificar los pixeles del buffer a PNG
+ if (lodepng::encode(png_data, data, width, height) != 0) {
+ std::cout << "Error encoding the .PNG image data." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Intenta guardar el archivo .PNG
+ if (lodepng::save_file(png_data, filename) != 0) {
+ std::cout << "Error saving " << filename << " file." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Grabacion correcta
+ std::cout << "File " << filename << " successfully saved." << std::endl;
+ png_data.clear();
+ return true;
+
+}
diff --git a/Tools/NGN_Sprite/source/convert_to_sprite.h b/Tools/NGN_Sprite/source/convert_to_sprite.h
new file mode 100644
index 0000000..f816124
--- /dev/null
+++ b/Tools/NGN_Sprite/source/convert_to_sprite.h
@@ -0,0 +1,95 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - ConvertToSprite -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef CONVERT_TO_SPRITE_H_INCLUDED
+#define CONVERT_TO_SPRITE_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class ConvertToSprite {
+
+ public:
+
+ // Constructor
+ ConvertToSprite();
+
+ // Destructor
+ ~ConvertToSprite();
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+ // Convierte un archivo PNG en un Sprite
+ bool Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t frame_w, // Tamaño del tile
+ uint32_t frame_h, // Nivel de optimizacion
+ bool strip // Generar archivos adicionales?
+ );
+
+
+ private:
+
+ /*** Propiedades ***/
+
+ // Parametros de las imagenes
+ uint32_t in_width, in_height; // Tamaño del archivo de entrada
+ uint32_t out_width, out_height; // Tamaño del archivo de salida
+
+ // Parametros de los fotogramas
+ uint32_t frame_width; // Tamaño del frame
+ uint32_t frame_height;
+ uint32_t total_frames;
+
+ // Parametros adicionales
+ bool sprite_strip;
+
+ // Buffers
+ std::vector sheet; // Buffer para almacenar la composicion del Sprite Sheet
+
+
+ /*** Metodos ***/
+
+ // Corta y almacena los diferentes fotogramas del sprite
+ void CutFrames(std::vector &data);
+
+ // Graba el archivo empaquetado
+ bool WriteFile(std::string filename);
+
+ // Lee el archivo .PNG y almacena los pixeles de la imagen en el buffer
+ bool ReadPng(std::string filename, std::vector &data);
+ // Graba un buffer de pixeles en un archivo PNG
+ bool WritePng(std::string filename, std::vector &data, uint32_t width, uint32_t height);
+
+};
+
+
+
+#endif // CONVERT_TO_SPRITE_H_INCLUDED
diff --git a/Tools/NGN_Sprite/source/defines.h b/Tools/NGN_Sprite/source/defines.h
new file mode 100644
index 0000000..ab04076
--- /dev/null
+++ b/Tools/NGN_Sprite/source/defines.h
@@ -0,0 +1,94 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Definiciones -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+#ifndef DEFINES_H_INCLUDED
+#define DEFINES_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+
+
+
+/*** Codigos de ERROR ***/
+const int32_t ERR_CODE_OK = 0x00;
+const int32_t ERR_CODE_BOOTFAILURE = 0x01;
+const int32_t ERR_CODE_ARG_INVALID = 0x02;
+const int32_t ERR_CODE_CONVERSION_FAILURE = 0x03;
+
+
+/*** Version de N'gine ***/
+const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
+const int32_t NGN_VERSION_MINOR = 11; // Version menor
+const int32_t NGN_VERSION_PATCH = 0; // Version parche
+const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
+
+
+/*** Version del programa ***/
+const std::string PROGRAM_NAME = "N'gine PNG to Sprite converter"; // Nombre del programa
+const std::string CC_YEARS = "2016-2023"; // Años en el texto CREATIVE COMMONS
+const int32_t PROGRAM_VERSION_MAJOR = 2; // Version mayor
+const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
+const int32_t PROGRAM_VERSION_PATCH = 0; // Version parche
+const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
+const std::string MAGIC_STRING = "NGN SPRITE"; // Magic string
+const uint8_t MS_LENGTH = 10; // Logitud del magic string
+const uint8_t VERSION = 2; // Version del archivo
+
+
+/*** Textos recurrentes ***/
+const std::string TEXT_DASHED_LINE = "------------------------------------------------------------";
+
+
+/*** Listado de argumentos disponibles ***/
+const int32_t ARG_MIN_NUM = 2; // Numero minimo de argumentos
+const int32_t ARG_MAX_NUM = 10; // Numero maximo de argumentos
+const std::string ARG_HELP = "-?"; // Ayuda
+const std::string ARG_WIDTH = "-w"; // Ancho del fotograma
+const std::string ARG_HEIGHT = "-h"; // Alto del fotograma
+const std::string ARG_OUT_FILE = "-o"; // Define el archivo de salida
+const std::string ARG_STRIP = "-s"; // Genera un PNG con la tira de fotogramas
+
+
+/*** Extensiones ***/
+const std::string SPR_EXTENSION = ".spr"; // Extension de archivo: Archivo tilemap
+const std::string STRIP_EXTENSION = "_strip.png"; // Extension de archivo: Tileset en PNG
+
+
+/*** Parametros de funcionamiento ***/
+const int32_t MIN_FRAME_SIZE = 1; // Tamaño minimo del fotograma
+const int32_t MAX_FRAME_SIZE = 8192; // Tamaño maximo del fotograma
+
+
+
+/*** Estructuras personalizadas ***/
+
+// Cabecera del archivo
+struct FileHeader {
+ uint8_t version; // Version del programa de conversion
+ char magic[32]; // Magic String
+ uint32_t sheet_width; // Tamaño del sheet completo
+ uint32_t sheet_height;
+ uint32_t frame_width; // Tamaño del frame
+ uint32_t frame_height;
+ uint32_t total_frames; // Numero total de frames de la imagen
+ uint8_t reserve[256]; // Posible uso futuro
+};
+
+
+#endif // DEFINES_H_INCLUDED
diff --git a/Tools/NGN_Sprite/source/fs_manager.cpp b/Tools/NGN_Sprite/source/fs_manager.cpp
new file mode 100644
index 0000000..6cdd68f
--- /dev/null
+++ b/Tools/NGN_Sprite/source/fs_manager.cpp
@@ -0,0 +1,171 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+// C
+#include
+#include
+#include
+// Includes del proyecto
+#include "fs_manager.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+FsManager::FsManager() {
+
+}
+
+
+
+/*** Destructor ***/
+FsManager::~FsManager() {
+
+}
+
+
+
+/*** Crea una lista de archivos de un directorio concreto ***/
+std::vector FsManager::GetListOfFiles(std::string path) {
+
+ // Crea una lista temporal
+ std::vector file_list;
+ file_list.clear();
+
+ // Lista recursiva
+ if (path.length() > 0) GetFilesRecursive(path, file_list);
+
+ // Devuelve la lista creada
+ return file_list;
+
+}
+
+
+
+/*** Crea un directorio a partir de un path, si este no existe ***/
+int32_t FsManager::MakePath(std::string path) {
+
+ // Caracter de referencia
+ std::string getchar = "";
+
+ // Genera una lista de directorios
+ std::vector directory;
+ directory.clear();
+ for (uint32_t i = 0; i < path.length(); i ++) {
+ getchar = path.at(i);
+ if (getchar == "/") {
+ directory.push_back(path.substr(0, i));
+ }
+ }
+
+ // Genera un path sin el nombre de archivo
+ for (uint32_t i = 0; i < directory.size(); i ++) {
+ if (directory[i] == ".") continue;
+ if (i == (directory.size() - 1)) std::cout << "Attempting to create [" << directory[i] << "]" << std::endl;
+ const char* p = directory[i].c_str();
+ #if defined (OS_WINDOWS)
+ mkdir(p);
+ #elif defined (OS_LINUX)
+ mkdir(p, 0777);
+ #else
+ mkdir(p, 0777);
+ #endif
+ }
+
+ // Devuelve el resultado
+ return directory.size();
+
+}
+
+
+
+/*** Crea una lista recursiva de los archivos ***/
+void FsManager::GetFilesRecursive(std::string path, std::vector &files) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Estructura de datos de "dirent"
+ struct dirent* dp;
+ // Variable de control de los metodos
+ DIR *dir;
+
+ // Intenta abrir el directorio
+ dir = opendir(_path);
+ // Si no puedes, asume que es un archivo y registralo
+ if (!dir) {
+ if (CheckIfFileExist(path)) files.push_back(path);
+ return;
+ }
+
+ // Variables
+ std::string file_name = "";
+
+ // Lee el directorio hasta que te quedes sin datos
+ while ((dp = readdir(dir)) != NULL) {
+
+ // Nombre del archivo actual
+ file_name = dp->d_name;
+
+ // Si es el indicador de raiz (.) o subir un nivel (..), saltatelo
+ if ((file_name == ".") || (file_name == "..")) continue;
+
+ // Genera una nueva ruta, por si es un directorio y no un archivo
+ std::string new_path = "";
+ if (path.substr(0, 1) != ".") new_path += (path + "/");
+ new_path += dp->d_name;
+
+ // Recursividad
+ GetFilesRecursive(new_path, files);
+
+ }
+
+ // Cierra el directorio
+ closedir(dir);
+
+}
+
+
+
+/*** Verifica que el archivo existe ***/
+bool FsManager::CheckIfFileExist(std::string path) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Intenta abrir el archivo en modo binario
+ std::ifstream file;
+ file.open(_path, std::ifstream::in | std::ifstream::binary);
+
+ // Segun si has podido o no abrirlo...
+ if (file.is_open()) {
+ file.close();
+ return true;
+ } else {
+ return false;
+ }
+
+}
diff --git a/Tools/NGN_Sprite/source/fs_manager.h b/Tools/NGN_Sprite/source/fs_manager.h
new file mode 100644
index 0000000..342f93b
--- /dev/null
+++ b/Tools/NGN_Sprite/source/fs_manager.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef FS_MANAGER_H_INCLUDED
+#define FS_MANAGER_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class FsManager {
+
+ public:
+
+ // Constructor
+ FsManager();
+
+ // Destructor
+ ~FsManager();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+
+ // Crea una lista con los archivos contenidos en un directorio
+ std::vector GetListOfFiles(std::string path);
+
+ // Crea un directorio a partir de un path, si este no existe
+ int32_t MakePath(std::string path);
+
+
+ // Verifica si un archivo existe
+ bool CheckIfFileExist(std::string path);
+
+
+ private:
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+
+ // Metodo recursivo para listar todos los archivos de todos los directorios
+ void GetFilesRecursive(std::string path, std::vector &files);
+
+};
+
+
+
+#endif // FS_MANAGER_H_INCLUDED
diff --git a/Tools/NGN_Sprite/source/lodepng/lodepng.cpp b/Tools/NGN_Sprite/source/lodepng/lodepng.cpp
index ee8cf33..1f89677 100644
--- a/Tools/NGN_Sprite/source/lodepng/lodepng.cpp
+++ b/Tools/NGN_Sprite/source/lodepng/lodepng.cpp
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,10 +44,10 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
#endif /*_MSC_VER */
-const char* LODEPNG_VERSION_STRING = "20200306";
+const char* LODEPNG_VERSION_STRING = "20220717";
/*
-This source file is built up in the following large parts. The code sections
+This source file is divided into the following large parts. The code sections
with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way.
-Tools for C and common code for PNG and Zlib
-C Code for Zlib (huffman, deflate, ...)
@@ -267,7 +267,7 @@ typedef struct ucvector {
} ucvector;
/*returns 1 if success, 0 if failure ==> nothing done*/
-static unsigned ucvector_resize(ucvector* p, size_t size) {
+static unsigned ucvector_reserve(ucvector* p, size_t size) {
if(size > p->allocsize) {
size_t newsize = size + (p->allocsize >> 1u);
void* data = lodepng_realloc(p->data, newsize);
@@ -277,10 +277,15 @@ static unsigned ucvector_resize(ucvector* p, size_t size) {
}
else return 0; /*error: not enough memory*/
}
- p->size = size;
return 1; /*success*/
}
+/*returns 1 if success, 0 if failure ==> nothing done*/
+static unsigned ucvector_resize(ucvector* p, size_t size) {
+ p->size = size;
+ return ucvector_reserve(p, size);
+}
+
static ucvector ucvector_init(unsigned char* buffer, size_t size) {
ucvector v;
v.data = buffer;
@@ -299,6 +304,7 @@ static void string_cleanup(char** out) {
*out = NULL;
}
+/*also appends null termination character*/
static char* alloc_string_sized(const char* in, size_t insize) {
char* out = (char*)lodepng_malloc(insize + 1);
if(out) {
@@ -479,71 +485,62 @@ static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned c
ensureBits functions:
Ensures the reader can at least read nbits bits in one or more readBits calls,
safely even if not enough bits are available.
-Returns 1 if there are enough bits available, 0 if not.
+The nbits parameter is unused but is given for documentation purposes, error
+checking for amount of bits must be done beforehand.
*/
-/*See ensureBits documentation above. This one ensures exactly 1 bit */
-/*static unsigned ensureBits1(LodePNGBitReader* reader) {
- if(reader->bp >= reader->bitsize) return 0;
- reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u);
- return 1;
-}*/
-
/*See ensureBits documentation above. This one ensures up to 9 bits */
-static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits9(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 1u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
- if(start + 0u < size) reader->buffer |= reader->data[start + 0];
+ if(start + 0u < size) reader->buffer = reader->data[start + 0];
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 17 bits */
-static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits17(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 2u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 25 bits */
-static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits25(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 3u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 32 bits */
-static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits32(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 4u < size) {
@@ -551,7 +548,6 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u)));
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
@@ -559,48 +555,28 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */
-static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
/* The shift allows nbits to be only up to 31. */
return reader->buffer & ((1u << nbits) - 1u);
}
/* Must have enough bits available with ensureBits */
-static void advanceBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void advanceBits(LodePNGBitReader* reader, size_t nbits) {
reader->buffer >>= nbits;
reader->bp += nbits;
}
/* Must have enough bits available with ensureBits */
-static unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
unsigned result = peekBits(reader, nbits);
advanceBits(reader, nbits);
return result;
}
-
-/* Public for testing only. steps and result must have numsteps values. */
-unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
- size_t numsteps, const size_t* steps, unsigned* result) {
- size_t i;
- LodePNGBitReader reader;
- unsigned error = LodePNGBitReader_init(&reader, data, size);
- if(error) return 0;
- for(i = 0; i < numsteps; i++) {
- size_t step = steps[i];
- unsigned ok;
- if(step > 25) ok = ensureBits32(&reader, step);
- else if(step > 17) ok = ensureBits25(&reader, step);
- else if(step > 9) ok = ensureBits17(&reader, step);
- else ok = ensureBits9(&reader, step);
- if(!ok) return 0;
- result[i] = readBits(&reader, step);
- }
- return 1;
-}
#endif /*LODEPNG_COMPILE_DECODER*/
static unsigned reverseBits(unsigned bits, unsigned num) {
@@ -735,10 +711,11 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) {
numpresent = 0;
for(i = 0; i < tree->numcodes; ++i) {
unsigned l = tree->lengths[i];
- unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
- /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
- unsigned reverse = reverseBits(symbol, l);
+ unsigned symbol, reverse;
if(l == 0) continue;
+ symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
+ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
+ reverse = reverseBits(symbol, l);
numpresent++;
if(l <= FIRSTBITS) {
@@ -1102,11 +1079,10 @@ static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree*
advanceBits(reader, l);
return value;
} else {
- unsigned index2;
advanceBits(reader, FIRSTBITS);
- index2 = value + peekBits(reader, l - FIRSTBITS);
- advanceBits(reader, codetree->table_len[index2] - FIRSTBITS);
- return codetree->table_value[index2];
+ value += peekBits(reader, l - FIRSTBITS);
+ advanceBits(reader, codetree->table_len[value] - FIRSTBITS);
+ return codetree->table_value[value];
}
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -1139,7 +1115,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
unsigned* bitlen_cl = 0;
HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/
- if(!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/
+ if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the memory*/
+ ensureBits17(reader, 14);
/*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/
HLIT = readBits(reader, 5) + 257;
@@ -1260,10 +1237,14 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/
static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
- unsigned btype) {
+ unsigned btype, size_t max_output_size) {
unsigned error = 0;
HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/
HuffmanTree tree_d; /*the huffman tree for distance codes*/
+ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */
+ int done = 0;
+
+ if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
HuffmanTree_init(&tree_ll);
HuffmanTree_init(&tree_d);
@@ -1271,14 +1252,21 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d);
else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader);
- while(!error) /*decode all symbols until end reached, breaks at end code*/ {
+
+ while(!error && !done) /*decode all symbols until end reached, breaks at end code*/ {
/*code_ll is literal, length or end code*/
unsigned code_ll;
- ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */
+ /* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second literal is read at once. This
+ appears to be slightly faster, than ensuring 20 bits here for 1 huffman symbol and the potential 5 extra bits for the length symbol.*/
+ ensureBits32(reader, 30);
code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ if(code_ll <= 255) {
+ /*slightly faster code path if multiple literals in a row*/
+ out->data[out->size++] = (unsigned char)code_ll;
+ code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ }
if(code_ll <= 255) /*literal symbol*/ {
- if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/);
- out->data[out->size - 1] = (unsigned char)code_ll;
+ out->data[out->size++] = (unsigned char)code_ll;
} else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ {
unsigned code_d, distance;
unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/
@@ -1291,6 +1279,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX];
if(numextrabits_l != 0) {
/* bits already ensured above */
+ ensureBits25(reader, 5);
length += readBits(reader, numextrabits_l);
}
@@ -1318,7 +1307,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(distance > start) ERROR_BREAK(52); /*too long backward distance*/
backward = start - distance;
- if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/);
+ out->size += length;
if(distance < length) {
size_t forward;
lodepng_memcpy(out->data + start, out->data + backward, distance);
@@ -1330,10 +1319,13 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
lodepng_memcpy(out->data + start, out->data + backward, length);
}
} else if(code_ll == 256) {
- break; /*end code, break the loop*/
+ done = 1; /*end code, finish the loop*/
} else /*if(code_ll == INVALIDSYMBOL)*/ {
ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
}
+ if(out->allocsize - out->size < reserved_size) {
+ if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
+ }
/*check if any of the ensureBits above went out of bounds*/
if(reader->bp > reader->bitsize) {
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
@@ -1341,6 +1333,9 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
/* TODO: revise error codes 10,11,50: the above comment is no longer valid */
ERROR_BREAK(51); /*error, bit pointer jumps past memory*/
}
+ if(max_output_size && out->size > max_output_size) {
+ ERROR_BREAK(109); /*error, larger than max size*/
+ }
}
HuffmanTree_cleanup(&tree_ll);
@@ -1373,8 +1368,11 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
- lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
- bytepos += LEN;
+ /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
+ if (LEN) {
+ lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
+ bytepos += LEN;
+ }
reader->bp = bytepos << 3u;
@@ -1392,15 +1390,16 @@ static unsigned lodepng_inflatev(ucvector* out,
while(!BFINAL) {
unsigned BTYPE;
- if(!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/
+ if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/
+ ensureBits9(&reader, 3);
BFINAL = readBits(&reader, 1);
BTYPE = readBits(&reader, 2);
if(BTYPE == 3) return 20; /*error: invalid BTYPE*/
else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/
- else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/
-
- if(error) return error;
+ else error = inflateHuffmanBlock(out, &reader, BTYPE, settings->max_output_size); /*compression, BTYPE 01 or 10*/
+ if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ if(error) break;
}
return error;
@@ -1421,6 +1420,12 @@ static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize,
if(settings->custom_inflate) {
unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings);
out->allocsize = out->size;
+ if(error) {
+ /*the custom inflate is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ }
return error;
} else {
return lodepng_inflatev(out, in, insize, settings);
@@ -2116,7 +2121,9 @@ static unsigned deflate(unsigned char** out, size_t* outsize,
const unsigned char* in, size_t insize,
const LodePNGCompressSettings* settings) {
if(settings->custom_deflate) {
- return settings->custom_deflate(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_deflate(out, outsize, in, insize, settings);
+ /*the custom deflate is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_deflate(out, outsize, in, insize, settings);
}
@@ -2213,10 +2220,16 @@ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const uns
/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
+ unsigned error;
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ error = settings->custom_zlib(out, outsize, in, insize, settings);
+ if(error) {
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
+ }
} else {
- unsigned error;
ucvector v = ucvector_init(*out, *outsize);
if(expected_size) {
/*reserve the memory to avoid intermediate reallocations*/
@@ -2226,8 +2239,8 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t exp
error = lodepng_zlib_decompressv(&v, in, insize, settings);
*out = v.data;
*outsize = v.size;
- return error;
}
+ return error;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2275,7 +2288,9 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in,
size_t insize, const LodePNGCompressSettings* settings) {
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_zlib(out, outsize, in, insize, settings);
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_zlib_compress(out, outsize, in, insize, settings);
}
@@ -2334,13 +2349,14 @@ const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT
void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) {
settings->ignore_adler32 = 0;
settings->ignore_nlen = 0;
+ settings->max_output_size = 0;
settings->custom_zlib = 0;
settings->custom_inflate = 0;
settings->custom_context = 0;
}
-const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0};
+const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0, 0};
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2357,7 +2373,7 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
/* ////////////////////////////////////////////////////////////////////////// */
-#ifndef LODEPNG_NO_COMPILE_CRC
+#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
@@ -2403,9 +2419,11 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) {
}
return r ^ 0xffffffffu;
}
-#else /* !LODEPNG_NO_COMPILE_CRC */
+#else /* LODEPNG_COMPILE_CRC */
+/*in this case, the function is only declared here, and must be defined externally
+so that it will be linked in*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
-#endif /* !LODEPNG_NO_COMPILE_CRC */
+#endif /* LODEPNG_COMPILE_CRC */
/* ////////////////////////////////////////////////////////////////////////// */
/* / Reading and writing PNG color channel bits / */
@@ -2443,7 +2461,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream,
/* ////////////////////////////////////////////////////////////////////////// */
unsigned lodepng_chunk_length(const unsigned char* chunk) {
- return lodepng_read32bitInt(&chunk[0]);
+ return lodepng_read32bitInt(chunk);
}
void lodepng_chunk_type(char type[5], const unsigned char* chunk) {
@@ -2493,34 +2511,32 @@ void lodepng_chunk_generate_crc(unsigned char* chunk) {
}
unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- const unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
@@ -2872,8 +2888,8 @@ static void LodePNGText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->text_keys = 0;
- dest->text_strings = 0;
+ dest->text_keys = NULL;
+ dest->text_strings = NULL;
dest->text_num = 0;
for(i = 0; i != source->text_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i]));
@@ -2932,10 +2948,10 @@ static void LodePNGIText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->itext_keys = 0;
- dest->itext_langtags = 0;
- dest->itext_transkeys = 0;
- dest->itext_strings = 0;
+ dest->itext_keys = NULL;
+ dest->itext_langtags = NULL;
+ dest->itext_transkeys = NULL;
+ dest->itext_strings = NULL;
dest->itext_num = 0;
for(i = 0; i != source->itext_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i],
@@ -3030,6 +3046,9 @@ void lodepng_info_init(LodePNGInfo* info) {
info->iccp_name = NULL;
info->iccp_profile = NULL;
+ info->sbit_defined = 0;
+ info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0;
+
LodePNGUnknownChunks_init(info);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
}
@@ -3924,7 +3943,7 @@ static unsigned auto_choose_color(LodePNGColorMode* mode_out,
if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize
&& mode_in->bitdepth == mode_out->bitdepth) {
/*If input should have same palette colors, keep original to preserve its order and prevent conversion*/
- lodepng_color_mode_cleanup(mode_out);
+ lodepng_color_mode_cleanup(mode_out); /*clears palette, keeps the above set colortype and bitdepth fields as-is*/
lodepng_color_mode_copy(mode_out, mode_in);
}
} else /*8-bit or 16-bit per channel*/ {
@@ -4093,10 +4112,12 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
case 0:
for(i = 0; i != length; ++i) recon[i] = scanline[i];
break;
- case 1:
+ case 1: {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth];
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + recon[j];
break;
+ }
case 2:
if(precon) {
for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i];
@@ -4106,24 +4127,56 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
break;
case 3:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u);
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u);
+ /* Unroll independent paths of this predictor. A 6x and 8x version is also possible but that adds
+ too much code. Whether this speeds up anything depends on compiler and settings. */
+ if(bytewidth >= 4) {
+ for(; i + 3 < length; i += 4, j += 4) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ recon[i + 3] = s3 + ((r3 + p3) >> 1u);
+ }
+ } else if(bytewidth >= 3) {
+ for(; i + 2 < length; i += 3, j += 3) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ }
+ } else if(bytewidth >= 2) {
+ for(; i + 1 < length; i += 2, j += 2) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ }
+ }
+ for(; i != length; ++i, ++j) recon[i] = scanline[i] + ((recon[j] + precon[i]) >> 1u);
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u);
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + (recon[j] >> 1u);
}
break;
case 4:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
- /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that
- adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */
+ /* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that
+ adds too much code. Whether this speeds up anything depends on compiler and settings. */
if(bytewidth >= 4) {
- for(; i + 3 < length; i += 4) {
- size_t j = i - bytewidth;
+ for(; i + 3 < length; i += 4, j += 4) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
@@ -4134,8 +4187,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 3] = s3 + paethPredictor(r3, p3, q3);
}
} else if(bytewidth >= 3) {
- for(; i + 2 < length; i += 3) {
- size_t j = i - bytewidth;
+ for(; i + 2 < length; i += 3, j += 3) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
@@ -4145,8 +4197,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
}
} else if(bytewidth >= 2) {
- for(; i + 1 < length; i += 2) {
- size_t j = i - bytewidth;
+ for(; i + 1 < length; i += 2, j += 2) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
@@ -4156,16 +4207,17 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
}
}
- for(; i != length; ++i) {
- recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
+ for(; i != length; ++i, ++j) {
+ recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j]));
}
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = scanline[i];
}
- for(i = bytewidth; i < length; ++i) {
+ for(i = bytewidth; i != length; ++i, ++j) {
/*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
- recon[i] = (scanline[i] + recon[i - bytewidth]);
+ recon[i] = (scanline[i] + recon[j]);
}
}
break;
@@ -4447,10 +4499,13 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
}
/*compressed text chunk (zTXt)*/
-static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, string2_begin;
char *key = 0;
unsigned char* str = 0;
@@ -4473,12 +4528,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(error) break;
error = lodepng_add_text_sized(info, key, (char*)str, size);
-
break;
}
@@ -4489,11 +4546,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
}
/*international text chunk (iTXt)*/
-static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, begin, compressed;
char *key = 0, *langtag = 0, *transkey = 0;
@@ -4550,9 +4610,12 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(compressed) {
unsigned char* str = 0;
size_t size = 0;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
lodepng_free(str);
} else {
@@ -4628,11 +4691,13 @@ static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, siz
return 0; /* OK */
}
-static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
size_t size = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
unsigned length, string2_begin;
@@ -4655,13 +4720,57 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_icc_size;
error = zlib_decompress(&info->iccp_profile, &size, 0,
&data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: ICC profile larger than decoder->max_icc_size*/
+ if(error && size > zlibsettings.max_output_size) error = 113;
info->iccp_profile_size = size;
if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
return error;
}
+
+/*significant bits chunk (sBIT)*/
+static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ if(info->color.colortype == LCT_GREY) {
+ /*error: this chunk must be 1 bytes for grayscale image*/
+ if(chunkLength != 1) return 114;
+ if(data[0] == 0 || data[0] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ /*error: this chunk must be 3 bytes for RGB and palette image*/
+ if(chunkLength != 3) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ /*error: this chunk must be 2 byte for grayscale with alpha image*/
+ if(chunkLength != 2) return 114;
+ if(data[0] == 0 || data[1] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ info->sbit_a = data[1];
+ } else if(info->color.colortype == LCT_RGBA) {
+ /*error: this chunk must be 4 bytes for grayscale image*/
+ if(chunkLength != 4) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ info->sbit_a = data[3];
+ }
+
+ return 0; /* OK */
+}
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
@@ -4676,7 +4785,7 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
chunkLength = lodepng_chunk_length(chunk);
if(chunkLength > 2147483647) return 63;
data = lodepng_chunk_data_const(chunk);
- if(data + chunkLength + 4 > in + insize) return 30;
+ if(chunkLength + 12 > insize - pos) return 30;
if(lodepng_chunk_type_equals(chunk, "PLTE")) {
error = readChunk_PLTE(&state->info_png.color, data, chunkLength);
@@ -4688,9 +4797,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "tEXt")) {
error = readChunk_tEXt(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
- error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
- error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
error = readChunk_tIME(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "pHYs")) {
@@ -4702,7 +4811,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "sRGB")) {
error = readChunk_sRGB(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ error = readChunk_sBIT(&state->info_png, data, chunkLength);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else {
/* unhandled chunk is ok (is not an error) */
@@ -4721,7 +4832,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
LodePNGState* state,
const unsigned char* in, size_t insize) {
unsigned char IEND = 0;
- const unsigned char* chunk;
+ const unsigned char* chunk; /*points to beginning of next chunk*/
unsigned char* idat; /*the data from idat chunks, zlib compressed*/
size_t idatsize = 0;
unsigned char* scanlines = 0;
@@ -4757,14 +4868,15 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
while(!IEND && !state->error) {
unsigned chunkLength;
const unsigned char* data; /*the data in the chunk*/
+ size_t pos = (size_t)(chunk - in);
- /*error: size of the in buffer too small to contain next chunk*/
- if((size_t)((chunk - in) + 12) > insize || chunk < in) {
+ /*error: next chunk out of bounds of the in buffer*/
+ if(chunk < in || pos + 12 > insize) {
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 30);
}
- /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
+ /*length of the data of the chunk, excluding the 12 bytes for length, chunk type and CRC*/
chunkLength = lodepng_chunk_length(chunk);
/*error: chunk length larger than the max PNG chunk size*/
if(chunkLength > 2147483647) {
@@ -4772,8 +4884,8 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
CERROR_BREAK(state->error, 63);
}
- if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) {
- CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
+ if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) {
+ CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk (or int overflow)*/
}
data = lodepng_chunk_data_const(chunk);
@@ -4820,13 +4932,13 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
/*compressed text chunk (zTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
/*international text chunk (iTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
@@ -4845,7 +4957,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
state->error = readChunk_sRGB(&state->info_png, data, chunkLength);
if(state->error) break;
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- state->error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ if(state->error) break;
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ state->error = readChunk_sBIT(&state->info_png, data, chunkLength);
if(state->error) break;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else /*it's not an implemented chunk type, so ignore it: skip over the data*/ {
@@ -4871,7 +4986,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize);
}
- if(state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
+ if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */
}
@@ -4955,6 +5070,11 @@ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, co
lodepng_state_init(&state);
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*disable reading things that this function doesn't output*/
+ state.decoder.read_text_chunks = 0;
+ state.decoder.remember_unknown_chunks = 0;
+#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
error = lodepng_decode(out, w, h, &state, in, insize);
lodepng_state_cleanup(&state);
return error;
@@ -4997,6 +5117,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
settings->read_text_chunks = 1;
settings->remember_unknown_chunks = 0;
+ settings->max_text_size = 16777216;
+ settings->max_icc_size = 16777216; /* 16MB is much more than enough for any reasonable ICC profile */
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
settings->ignore_crc = 0;
settings->ignore_critical = 0;
@@ -5075,6 +5197,10 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) {
unsigned char* chunk;
size_t i, j = 8;
+ if(info->palettesize == 0 || info->palettesize > 256) {
+ return 68; /*invalid palette size, it is only allowed to be 1-256*/
+ }
+
CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE"));
for(i = 0; i != info->palettesize; ++i) {
@@ -5330,6 +5456,42 @@ static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCom
return error;
}
+static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ unsigned char* chunk = 0;
+ if(info->color.colortype == LCT_GREY) {
+ if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT"));
+ chunk[8] = info->sbit_r;
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ if(info->sbit_r == 0 || info->sbit_a == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_a;
+ } else if(info->color.colortype == LCT_RGBA) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 ||
+ info->sbit_r > bitdepth || info->sbit_g > bitdepth ||
+ info->sbit_b > bitdepth || info->sbit_a > bitdepth) {
+ return 115;
+ }
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ chunk[11] = info->sbit_a;
+ }
+ if(chunk) lodepng_chunk_generate_crc(chunk);
+ return 0;
+}
+
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline,
@@ -5775,8 +5937,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
ucvector outv = ucvector_init(NULL, 0);
LodePNGInfo info;
const LodePNGInfo* info_png = &state->info_png;
+ LodePNGColorMode auto_color;
lodepng_info_init(&info);
+ lodepng_color_mode_init(&auto_color);
/*provide some proper output values if error will happen*/
*out = 0;
@@ -5786,6 +5950,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*check input values validity*/
if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
&& (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) {
+ /*this error is returned even if auto_convert is enabled and thus encoder could
+ generate the palette by itself: while allowing this could be possible in theory,
+ it may complicate the code or edge cases, and always requiring to give a palette
+ when setting this color type is a simpler contract*/
state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
goto cleanup;
}
@@ -5806,6 +5974,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
lodepng_info_copy(&info, &state->info_png);
if(state->encoder.auto_convert) {
LodePNGColorStats stats;
+ unsigned allow_convert = 1;
lodepng_color_stats_init(&stats);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined &&
@@ -5827,23 +5996,85 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*the background chunk's color must be taken into account as well*/
unsigned r = 0, g = 0, b = 0;
LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
- lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
+ lodepng_convert_rgb(&r, &g, &b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
state->error = lodepng_color_stats_add(&stats, r, g, b, 65535);
if(state->error) goto cleanup;
}
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
- state->error = auto_choose_color(&info.color, &state->info_raw, &stats);
+ state->error = auto_choose_color(&auto_color, &state->info_raw, &stats);
if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
- /*also convert the background chunk*/
- if(info_png->background_defined) {
- if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
- info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
- state->error = 104;
- goto cleanup;
+ if(info_png->sbit_defined) {
+ /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes,
+ auto_convert can't be done in many cases. However, do support a few cases here.
+ TODO: more conversions may be possible, and it may also be possible to get a more appropriate color type out of
+ auto_choose_color if knowledge about sbit is used beforehand
+ */
+ unsigned sbit_max = LODEPNG_MAX(LODEPNG_MAX(LODEPNG_MAX(info_png->sbit_r, info_png->sbit_g),
+ info_png->sbit_b), info_png->sbit_a);
+ unsigned equal = (!info_png->sbit_g || info_png->sbit_g == info_png->sbit_r)
+ && (!info_png->sbit_b || info_png->sbit_b == info_png->sbit_r)
+ && (!info_png->sbit_a || info_png->sbit_a == info_png->sbit_r);
+ allow_convert = 0;
+ if(info.color.colortype == LCT_PALETTE &&
+ auto_color.colortype == LCT_PALETTE) {
+ /* input and output are palette, and in this case it may happen that palette data is
+ expected to be copied from info_raw into the info_png */
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGB to palette (or 16-bit as long as sbit_max <= 8) is possible
+ since both are 8-bit RGB for sBIT's purposes*/
+ if(info.color.colortype == LCT_RGB &&
+ auto_color.colortype == LCT_PALETTE && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/
+ if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE &&
+ info_png->sbit_a == 8 && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/
+ if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth == 16 &&
+ auto_color.colortype == info.color.colortype && auto_color.bitdepth == 8 &&
+ sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going to less channels is ok if all bit values are equal (all possible values in sbit,
+ as well as the chosen bitdepth of the result). Due to how auto_convert works,
+ we already know that auto_color.colortype has less than or equal amount of channels than
+ info.colortype. Palette is not used here. This conversion is not allowed if
+ info_png->sbit_r < auto_color.bitdepth, because specifically for alpha, non-presence of
+ an sbit value heavily implies that alpha's bit depth is equal to the PNG bit depth (rather
+ than the bit depths set in the r, g and b sbit values, by how the PNG specification describes
+ handling tRNS chunk case with sBIT), so be conservative here about ignoring user input.*/
+ if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE &&
+ equal && info_png->sbit_r == auto_color.bitdepth) {
+ allow_convert = 1;
}
}
+#endif
+ if(state->encoder.force_palette) {
+ if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
+ (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
+ /*user speficially forced a PLTE palette, so cannot convert to grayscale types because
+ the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
+ allow_convert = 0;
+ }
+ }
+ if(allow_convert) {
+ lodepng_color_mode_copy(&info.color, &auto_color);
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*also convert the background chunk*/
+ if(info_png->background_defined) {
+ if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
+ state->error = 104;
+ goto cleanup;
+ }
+ }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+ }
}
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined) {
@@ -5914,6 +6145,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
state->error = addChunk_cHRM(&outv, &info);
if(state->error) goto cleanup;
}
+ if(info_png->sbit_defined) {
+ state->error = addChunk_sBIT(&outv, &info);
+ if(state->error) goto cleanup;
+ }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
/*PLTE*/
if(info.color.colortype == LCT_PALETTE) {
@@ -6020,6 +6255,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
cleanup:
lodepng_info_cleanup(&info);
lodepng_free(data);
+ lodepng_color_mode_cleanup(&auto_color);
/*instead of cleaning the vector up, give it to the output*/
*out = outv.data;
@@ -6204,6 +6440,18 @@ const char* lodepng_error_text(unsigned code) {
case 106: return "PNG file must have PLTE chunk if color type is palette";
case 107: return "color convert from palette mode requested without setting the palette data in it";
case 108: return "tried to add more than 256 values to a palette";
+ /*this limit can be configured in LodePNGDecompressSettings*/
+ case 109: return "tried to decompress zlib or deflate data larger than desired max_output_size";
+ case 110: return "custom zlib or inflate decompression failed";
+ case 111: return "custom zlib or deflate compression failed";
+ /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large text sizes.*/
+ case 112: return "compressed text unreasonably large";
+ /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large ICC profile*/
+ case 113: return "ICC profile unreasonably large";
+ case 114: return "sBIT chunk has wrong size for the color type of the image";
+ case 115: return "sBIT value out of range";
}
return "unknown error code";
}
@@ -6240,7 +6488,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si
size_t buffersize = 0;
unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6259,7 +6507,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size
size_t buffersize = 0;
unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6304,7 +6552,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6322,7 +6570,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize);
if(buffer && !error) {
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6354,7 +6602,7 @@ unsigned encode(std::vector& out, const unsigned char* in, unsign
size_t buffersize;
unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6374,7 +6622,7 @@ unsigned encode(std::vector& out,
size_t buffersize;
unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
diff --git a/Tools/NGN_Sprite/source/lodepng/lodepng.h b/Tools/NGN_Sprite/source/lodepng/lodepng.h
index a386459..fdafc77 100644
--- a/Tools/NGN_Sprite/source/lodepng/lodepng.h
+++ b/Tools/NGN_Sprite/source/lodepng/lodepng.h
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
@@ -142,16 +161,24 @@ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,
/*
Load PNG from disk, from file with given name.
Same as the other decode functions, but instead takes a filename as input.
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
-/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -191,17 +218,26 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize,
/*
Converts raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode32_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
-/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode24_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -223,6 +259,9 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
/*
Converts PNG file from disk to raw pixel data in memory.
Same as the other decode functions, but instead takes a filename as input.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned decode(std::vector& out, unsigned& w, unsigned& h,
const std::string& filename,
@@ -243,7 +282,11 @@ unsigned encode(std::vector& out,
/*
Converts 32-bit RGBA raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned encode(const std::string& filename,
const unsigned char* in, unsigned w, unsigned h,
@@ -270,12 +313,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -341,8 +393,10 @@ typedef struct LodePNGColorMode {
The alpha channels must be set as well, set them to 255 for opaque images.
- When decoding, by default you can ignore this palette, since LodePNG already
- fills the palette colors in the pixels of the raw RGBA output.
+ When decoding, with the default settings you can ignore this palette, since
+ LodePNG already fills the palette colors in the pixels of the raw RGBA output,
+ but when decoding to the original PNG color mode it is needed to reconstruct
+ the colors.
The palette is only supported for color type 3.
*/
@@ -432,10 +486,12 @@ typedef struct LodePNGInfo {
with values truncated to the bit depth in the unsigned integer.
For grayscale and palette PNGs, the value is stored in background_r. The values
- in background_g and background_b are then unused.
+ in background_g and background_b are then unused. The decoder will set them
+ equal to background_r, the encoder ignores them in this case.
- So when decoding, you may get these in a different color mode than the one you requested
- for the raw pixels.
+ When decoding, you may get these in a different color mode than the one you requested
+ for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the
+ ones defined in the header of the PNG image, are used.
When encoding with auto_convert, you must use the color model defined in info_png.color for
these values. The encoder normally ignores info_png.color when auto_convert is on, but will
@@ -454,30 +510,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -496,7 +558,7 @@ typedef struct LodePNGInfo {
unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
/*
- Color profile related chunks: gAMA, cHRM, sRGB, iCPP
+ Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
@@ -559,6 +621,45 @@ typedef struct LodePNGInfo {
unsigned char* iccp_profile;
unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+ /*
+ sBIT chunk: significant bits. Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+ sample depth, such as 10 or 12.
+
+ Encoders using this value, when storing the pixel data, should use the most significant bits
+ of the data to store the original bits, and use a good sample depth scaling method such as
+ "left bit replication" to fill in the least significant bits, rather than fill zeroes.
+
+ Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right
+ shift the data to go back to the original bit depth, but decoders are also allowed to ignore
+ sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks
+ to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.
+
+ For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color
+ type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with
+ translucent palette values, or images with color key). The values that are used must be
+ greater than zero and smaller than or equal to the PNG bit depth.
+
+ The color type from the header in the PNG image defines these used and unused fields: if
+ decoding with a color mode conversion, such as always decoding to RGBA, this metadata still
+ only uses the color type of the original PNG, and may e.g. lack the alpha channel info
+ if the PNG was RGB. When encoding with auto_convert (as well as without), also always the
+ color model defined in info_png.color determines this.
+
+ NOTE: enabling sbit can hurt compression, because the encoder can then not always use
+ auto_convert to choose a more optimal color mode for the data, because the PNG format has
+ strict requirements for the allowed sbit values in combination with color modes.
+ For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel
+ color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.
+ */
+ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/
+ unsigned sbit_r; /*red or gray component of significant bits*/
+ unsigned sbit_g; /*green component of significant bits*/
+ unsigned sbit_b; /*blue component of significant bits*/
+ unsigned sbit_a; /*alpha component of significant bits*/
+
/* End of color profile related chunks */
@@ -639,8 +740,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -720,7 +832,11 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
- If colortype is 3, PLTE is _always_ created.*/
+ If colortype is 3, PLTE is always created. If color type is explicitely set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+ optimal color mode, because it cannot use grayscale color modes in this case*/
unsigned force_palette;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
/*add LodePNG identifier and version as a text chunk, for debugging*/
@@ -774,8 +890,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h,
#endif /*LODEPNG_COMPILE_DECODER*/
/*
-Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it
-read in the state. Returns error code on failure.
+Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)
+of the PNG file and outputs what it read in the state. Returns error code on failure.
Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const
to find the desired chunk type, and if non null use lodepng_inspect_chunk (with
chunk_pointer - start_of_file as pos).
@@ -950,6 +1066,9 @@ out: output parameter, contains pointer to loaded buffer.
outsize: output parameter, size of the allocated out buffer
filename: the path to the file to load
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);
@@ -960,6 +1079,9 @@ buffer: the buffer to write
buffersize: size of the buffer to write
filename: the path to the file to save to
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -1000,12 +1122,18 @@ unsigned encode(std::vector& out,
/*
Load a file from disk into an std::vector.
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory
*/
unsigned load_file(std::vector& buffer, const std::string& filename);
/*
Save the binary data in an std::vector to a file on disk. The file is overwritten
without warning.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned save_file(const std::vector& buffer, const std::string& filename);
#endif /* LODEPNG_COMPILE_DISK */
@@ -1041,7 +1169,7 @@ unsigned compress(std::vector& out, const std::vector (2^31)-1
[ ] partial decoding (stream processing)
[X] let the "isFullyOpaque" function check color keys and transparent palettes too
@@ -1168,18 +1296,16 @@ The following features are supported by the decoder:
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
+ sBIT: significant bits
1.2. features not supported
---------------------------
-The following features are _not_ supported:
+The following features are not (yet) supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
-*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
- sBIT
- hIST
- sPLT
+*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks
2. C and C++ version
@@ -1505,6 +1631,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1678,6 +1809,9 @@ try to fix it if the compiler is modern and standards compliant.
This decoder example shows the most basic usage of LodePNG. More complex
examples can be found on the LodePNG website.
+NOTE: these examples do not support wide-character filenames, you can use an
+external method to handle such files and encode or decode in-memory
+
10.1. decoder C++ example
-------------------------
@@ -1775,6 +1909,12 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 13 jun 2022: added support for the sBIT chunk.
+*) 09 jan 2022: minor decoder speed improvements.
+*) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.
@@ -1941,5 +2081,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
*/
diff --git a/Tools/NGN_Sprite/source/main.cpp b/Tools/NGN_Sprite/source/main.cpp
index 7790dd6..6931823 100644
--- a/Tools/NGN_Sprite/source/main.cpp
+++ b/Tools/NGN_Sprite/source/main.cpp
@@ -1,15 +1,15 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a Sprite sheet (.spr)
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Archivo principal -
- Proyecto iniciado el 3 de Marzo del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
@@ -22,170 +22,29 @@
#include
#include
#include
-#include
-// LodePNG
-#include "lodepng/lodepng.h"
-
-// Sprite class
+// Programa
#include "sprite.h"
+#include "defines.h"
-/*** Version de N'gine ***/
-static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 0; // Version menor
-static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
-/*** Version del programa ***/
-static const int32_t PROGRAM_VERSION_MAJOR = 1; // Version mayor
-static const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
-static const int32_t PROGRAM_VERSION_PATCH = 2; // Version parche
-static const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
-
-
-
-/*** Mensages de error ***/
-void ErrorMsg() {
- std::cout << "Command line error." << std::endl;
- std::cout << "Usage: NGN_Sprite INPUT_FILE.PNG -w xx -h xx [-o filename] [-s]" << std::endl;
- std::cout << "-w xx Width of the sprite frame." << std::endl;
- std::cout << "-h xx Height of the sprite frame." << std::endl;
- std::cout << "-o filename Name for the output file, without extension (.spr will be added automaticaly)." << std::endl;
- std::cout << "-s Generates a PNG file with the sprite strip." << std::endl << std::endl;
-}
-
+/*** Main ***/
+int32_t main(int32_t argc, char* args[]) {
+ // Crea el objeto principal del programa
+ Sprite* spr = new Sprite(argc, args);
+ // Si no se crea con exito, sal del programa
+ if (!spr) return ERR_CODE_BOOTFAILURE;
-/*** Main ***/
-int32_t main(int32_t argc, char* args[]) {
+ // Transfiere el control del objeto principal
+ int32_t r = spr->Run();
- // Variables
- std::string in_file = ""; // Nombre del archivo de entrada
- std::string out_file = ""; // Nombre base de los archivos de salida
- int32_t width = -1; // Ancho del frame
- int32_t height = -1; // Altura del frame
-
- // Variables de control
- bool _out_file = false;
- bool _width = false;
- bool _height = false;
- bool _strip = false;
- bool _err = false;
-
- // Texto de bienvenida
- std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::cout <<
- std::endl << "N'gine PNG to Sprite converter. (v" << program_version << ")." <<
- std::endl << "For N'gine Version " << ngn_version << " or higher." <<
- std::endl << "(cc) 2016 - 2022 by Cesar Rincon." <<
- std::endl << "https://nightfoxandco.com" <<
- std::endl << "contact@nightfoxandco.com" <<
- std::endl << std::endl;
-
- // Verifica la linea de comandos
- if ((argc < 2) || (argc > 9)) { // Nº de argumentos incorrecto
-
- ErrorMsg();
- return 1;
-
- } else {
-
- // Archivo de entrada
- in_file = args[1];
- if ((in_file.length() < 5) || (in_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
-
- // Analiza los argumentos extra
- for (int32_t i = 2; i < argc; i ++) {
- _err = true;
- if (strcmp(args[i], "-o") == 0) { // Comando -O
- if (((i + 1) < argc) && !_out_file) {
- _out_file = true;
- _err = false;
- out_file = args[(i + 1)];
- i ++;
- if ((out_file.length() < 1) || (out_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-w") == 0) { // Comando -W
- if (((i + 1) < argc) && !_width) {
- _width = true;
- _err = false;
- width = atoi(args[(i + 1)]);
- i ++;
- if (width < 1) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-h") == 0) { // Comando -H
- if (((i + 1) < argc) && !_height) {
- _height = true;
- _err = false;
- height = atoi(args[(i + 1)]);
- i ++;
- if (height < 1) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-s") == 0) { // Comando -S
- _strip = true;
- _err = false;
- }
- }
- // Error de uso incorrecto de argumentos
- if (_err) {
- ErrorMsg();
- return 1;
- }
- }
- std::cout << std::endl;
-
- // Analiza si hay el minimo de parametros requeridos introducidos correctamente
- if (!_width || !_height) {
- ErrorMsg();
- return 1;
- }
-
- // Nombre del archivo de salida
- if (out_file == "") out_file = in_file.substr(0, (in_file.length() - 4));
-
-
- /*** Parametros aceptados, crea el objeto principal ***/
- SpriteSheet* spr = new SpriteSheet();
-
- // Registra los parametros del Sprite a convertir
- spr->input_filename = in_file;
- spr->output_filename = out_file;
- spr->frame_width = width;
- spr->frame_height = height;
- if (_strip) spr->strip = true;
-
- // Carga y convierte la imagen PNG en una tira de sprites
- spr->ConvertPng();
-
- /*** Proceso completado, destruye el objeto principal ***/
+ // Elimina el objeto principal
delete spr;
-
- // Fin del programa
- return 0;
+ // Devuelve el resultado de ejecucion del programa
+ return r;
}
diff --git a/Tools/NGN_Sprite/source/message.cpp b/Tools/NGN_Sprite/source/message.cpp
new file mode 100644
index 0000000..3327278
--- /dev/null
+++ b/Tools/NGN_Sprite/source/message.cpp
@@ -0,0 +1,106 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+
+// Includes del proyecto
+#include "message.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+Message::Message(std::string pname) {
+
+ // Guarda el nombre del ejecutable del programa
+ program_name = pname;
+
+}
+
+
+
+/*** Destructor ***/
+Message::~Message() {
+
+}
+
+
+
+/*** Texto de encabezado de la aplicacion ***/
+void Message::AppHeader() {
+
+ // Genera las cadenas de texto adicionales
+ std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
+ std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + PROGRAM_VERSION_METADATA;
+
+ // Imprime el texto
+ std::cout <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl <<
+ std::endl << " " << PROGRAM_NAME << ". (v" << program_version << ")." <<
+ std::endl << " For N'gine Version " << ngn_version << " or higher." <<
+ std::endl << " (cc) " << CC_YEARS << " by Cesar Rincon." <<
+ std::endl << " https://nightfoxandco.com" <<
+ std::endl << " contact@nightfoxandco.com" <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Como obtener ayuda" ***/
+void Message::QuestionMarkForHelp() {
+
+ std::cout << "Type " << program_name << " " << ARG_HELP << " to display the on-screen help manual." << std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Error de uso" ***/
+void Message::UseError() {
+
+ std::cout << "Command line error." << std::endl;
+
+}
+
+
+
+/*** Texto "Manual de uso" ***/
+void Message::UserManual() {
+
+ std::cout << std::endl;
+ std::cout << program_name << " INPUT_FILE.PNG " << ARG_WIDTH << " xxxx " << ARG_HEIGHT << " xxxx [" << ARG_OUT_FILE << " filename] [" << ARG_STRIP << "]" << std::endl;
+ std::cout << std::endl;
+ std::cout << ARG_HELP << " Displays the on-screen user manual (this screen)." << std::endl;
+ std::cout << ARG_WIDTH << " WIDTH of the frame. (From [" << MIN_FRAME_SIZE << "] to [" << MAX_FRAME_SIZE << "] pixels)." << std::endl;
+ std::cout << ARG_HEIGHT << " HEIGHT of the frame. (From [" << MIN_FRAME_SIZE << "] to [" << MAX_FRAME_SIZE << "] pixels)." << std::endl;
+ std::cout << ARG_OUT_FILE << " Name for the output file, without extension (" << SPR_EXTENSION << " will be added automaticaly)." << std::endl;
+ std::cout << ARG_STRIP << " Generates a PNG file with the frames of the sprite in strip format." << std::endl;
+ std::cout << std::endl;
+
+}
diff --git a/Tools/NGN_Sprite/source/message.h b/Tools/NGN_Sprite/source/message.h
new file mode 100644
index 0000000..58318a1
--- /dev/null
+++ b/Tools/NGN_Sprite/source/message.h
@@ -0,0 +1,67 @@
+/******************************************************************************
+
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef MESSAGE_H_INCLUDED
+#define MESSAGE_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class Message {
+
+ public:
+
+ // Constructor
+ Message(std::string pname);
+
+ // Destructor
+ ~Message();
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+ void AppHeader(); // Texto de cabecera de la aplicacion
+ void QuestionMarkForHelp(); // -? para mostrar la ayuda
+ void UseError(); // Error del uso
+ void UserManual(); // Manual del usuario
+
+
+ private:
+
+ /*** Propiedades ***/
+ std::string program_name; // Nombre del archivo ejecutable
+
+
+
+ /*** Metodos ***/
+
+};
+
+
+
+#endif // MESSAGE_H_INCLUDED
diff --git a/Tools/NGN_Sprite/source/sprite.cpp b/Tools/NGN_Sprite/source/sprite.cpp
index ab58730..71b79a0 100644
--- a/Tools/NGN_Sprite/source/sprite.cpp
+++ b/Tools/NGN_Sprite/source/sprite.cpp
@@ -1,15 +1,15 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a Sprite sheet (.spr)
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Nucleo del programa -
- Proyecto iniciado el 3 de Marzo del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
@@ -20,294 +20,293 @@
// C++
#include
+#include
#include
-#include
#include
#include
+#include
-// LodePNG
-#include "lodepng/lodepng.h"
-// Sprite class
+// Includes del proyecto
#include "sprite.h"
+#include "defines.h"
+#include "message.h"
+
/*** Constructor ***/
-SpriteSheet::SpriteSheet() {
+Sprite::Sprite(int32_t argc, char* args[]) {
- // Inicializa variables
- strip = false;
-}
+ // Guarda el numero de argumentos
+ argument_count = argc;
+ // General al lista de argumentos
+ argument_list.clear();
+ argument_list.resize(argument_count);
+ for (int32_t i = 0; i < argument_count; i ++) argument_list[i] = args[i];
+ // Parametros
+ parameter.in_file = "";
+ parameter.out_file = "";
+ parameter.width = 0;
+ parameter.height = 0;
+ parameter.generate_strip = false;
-/*** Destructor ***/
-SpriteSheet::~SpriteSheet() {
+ // Crea los objetos adicionales
+ msg = new Message(argument_list[0]);
+ fs = new FsManager();
+ png2sprite = new ConvertToSprite();
- // Borra los buffers de memoria
- png.clear();
- raw.clear();
- sheet.clear();
- out.clear();
+ // Flags de argumentos
+ arg_help.state = false; arg_help.value = "";
+ arg_in_file.state = false; arg_in_file.value = "";
+ arg_out_file.state = false; arg_out_file.value = "";
+ arg_width.state = false; arg_width.value = "";
+ arg_height.state = false; arg_height.value = "";
+ arg_strip.state = false; arg_strip.value = "";
}
-/*** Convierte el archivo a un Sprite Sheet del tamaño solicitado ***/
-int32_t SpriteSheet::ConvertPng() {
-
- // Intenta cargar el archivo PNG, si hay error sal e informa.
- if (ReadPNG(input_filename, raw) > 0) return 1;
-
- // Genera la plantilla
- GenerateSpriteSheet();
+/*** Destructor ***/
+Sprite::~Sprite() {
- // Graba los archivos de salida
- if (WriteFile(output_filename) > 0) return 1;
+ // Elimina la lista de argumentos
+ argument_list.clear();
- // Devuelve el resultado
- return 0;
+ // Elimina los objetos adicionales
+ delete png2sprite; png2sprite = NULL;
+ delete fs; fs = NULL;
+ delete msg; msg = NULL;
}
-/*** Lee el archivo PNG y almacena los pixeles de la imagen en el buffer ***/
-int32_t SpriteSheet::ReadPNG(std::string filename, std::vector &data) {
+/*** Programa principal ***/
+int32_t Sprite::Run() {
- // Borra los buffers
- png.clear();
+ // Resultado de la ejecucion
+ int32_t r = ERR_CODE_OK;
- // Carga el archivo PNG
- uint32_t _error = lodepng::load_file(png, filename);
+ // Texto de cabecera
+ msg->AppHeader();
- // Si se ha cargado correctamente, decodifica la imagen
- if (_error == 0) {
- _error = lodepng::decode(raw, in_width, in_height, png);
- } else {
- std::cout << "Error loading " << filename << "." << std::endl;
- png.clear();
- return 1;
- }
+ // Analiza la lista de argumentos
+ int32_t arglist = CheckArguments();
+ //DebugArgList();
- // Verifica que la decodificacion sea la correcta
- if (_error == 0) {
- std::cout << "File " << filename << " loaded & decoded successfully." << std::endl;
- std::cout << "Image size is " << in_width << "x" << in_height << " pixels." << std::endl;
- // Aviso de tamaño no exacto
- if (((in_width % frame_width) != 0) || ((in_height % frame_height) != 0)) {
- std::cout << "WARNING: Image size doesn't fits the sprite frame size." << std::endl;
- }
- png.clear();
- return 0;
+ // Analisis de los posibles errores en la linea de comandos / peticion de ayuda
+ if (arglist == 0) {
+ // Si no se ha especificado ningun argumento
+ msg->QuestionMarkForHelp();
+ } else if (arglist < 0) {
+ // Uso incorrecto
+ msg->UseError();
+ msg->UserManual();
+ r = ERR_CODE_ARG_INVALID;
+ } else if (arg_help.state) {
+ // Manual en pantalla
+ msg->UserManual();
} else {
- std::cout << "Error decoding " << filename << "." << std::endl;
- png.clear();
- return 1;
+ // Valida los parametros de entrada
+ if (ValidateParameters()) {
+ Report();
+ if (
+ !png2sprite->Convert(
+ parameter.in_file,
+ parameter.out_file,
+ parameter.width,
+ parameter.height,
+ parameter.generate_strip
+ )
+ ) r = ERR_CODE_CONVERSION_FAILURE;
+ } else {
+ msg->QuestionMarkForHelp();
+ r = ERR_CODE_ARG_INVALID;
+ }
}
+ // Resultado de la ejecucion
+ return r;
}
-/*** Graba el buffer a un archivo PNG ***/
-int32_t SpriteSheet::WritePNG(std::string filename, std::vector &data) {
- // Borra los bufferes
- out.clear();
+/*** Analiza la lista de argumentos proporcionados ***/
+int32_t Sprite::CheckArguments() {
- uint32_t _error = lodepng::encode(out, data, out_width, out_height);
+ // Si no hay argumentos, muestra el texto de ayuda
+ if (argument_count == 1) return 0;
- // Si se ha codificado correctamente, graba el archivo
- if (_error == 0) {
- _error = lodepng::save_file(out, filename);
- if (_error == 0) {
- std::cout << "File " << filename << " successfully saved." << std::endl;
- out.clear();
- return 0;
- } else {
- std::cout << "Error saving " << filename << "." << std::endl;
- out.clear();
- return 1;
- }
- } else {
- std::cout << "Error encoding the RAW data." << std::endl;
- out.clear();
- return 1;
- }
+ // Si el numero de argumentos es incorrecto
+ if ((argument_count < ARG_MIN_NUM) || (argument_count > ARG_MAX_NUM)) return -1;
-}
+ // Flag de argumentos validos
+ bool arg = false;
+ bool valid = false;
+ // Analiza la lista de argumentos
+ for (uint32_t i = 1; i < argument_list.size(); i ++) {
+ valid = false;
-/*** Graba el archivo empaquetado ***/
-int32_t SpriteSheet::WriteFile(std::string filename) {
+ if (argument_list[i] == ARG_HELP) { // Texto de ayuda
- // Proteccion de path
- if (filename.length() >= 246) {
- std::cout << "Error saving " << filename << "." << std::endl;
- std::cout << "Path too long." << std::endl;
- return 1;
- }
+ if (arg_help.state) return -1;
+ arg_help.state = true;
+ valid = true;
- // Variables
- uint32_t i = 0;
-
- // Intenta codificar el Tileset a PNG
- out.clear();
- if (lodepng::encode(out, sheet, out_width, out_height) > 0) return 1;
-
- for (i = 0; i < sizeof(header.reserve); i ++) header.reserve[i] = 0;
-
- // Genera el nombre de archivo
- char f[256];
- char basename[246];
- for (i = 0; i < filename.length(); i ++) basename[i] = filename[i]; // Nombre base
- basename[i] = '\0'; // Terminador
-
- //std::cout << filename << std::endl;
- //std::cout << basename << std::endl;
-
- // Graba el archivo principal
- sprintf(f, "%s.spr", basename);
- std::ofstream file;
- file.open(f, std::ofstream::out | std::ofstream::binary);
- if (file.is_open()) {
- file.write((char*)&header, sizeof(header)); // Cabecera
- file.write((char*)&out[0], out.capacity()); // Sprite sheet en PNG
- file.close();
- std::cout << "File " << f << " successfully saved." << std::endl;
- } else {
- std::cout << "Error saving " << f << "." << std::endl;
- return 1;
- }
+ } else if (argument_list[i] == ARG_OUT_FILE) { // Archivo de salida
- // Si es necesario, guarda el archivo PNG extra
- if (strip) {
- sprintf(f, "%s_sheet.png", basename);
- if (WritePNG(f, sheet) > 0) return 1;
- }
+ if (arg_out_file.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_out_file.state = true;
+ i ++;
+ arg_out_file.value = argument_list[i];
+ valid = true;
- // Todo correcto
- return 0;
+ } else if (argument_list[i] == ARG_WIDTH) { // Ancho del fotograma
-}
+ if (arg_width.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_width.state = true;
+ i ++;
+ arg_width.value = argument_list[i];
+ valid = true;
+
+ } else if (argument_list[i] == ARG_HEIGHT) { // Altura del fotograma
+ if (arg_height.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_height.state = true;
+ i ++;
+ arg_height.value = argument_list[i];
+ valid = true;
+ } else if (argument_list[i] == ARG_STRIP) { // Genera la tira de fotogramas?
+ if (arg_strip.state) return -1;
+ arg_strip.state = true;
+ valid = true;
-/*** Lee un pixel del buffer especificado ***/
-rgba_pixel SpriteSheet::GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w) {
+ } else if (i == 1) {
+
+ if (arg_in_file.state) return -1;
+ arg_in_file.state = true;
+ arg_in_file.value = argument_list[i];
+ valid = true;
+
+ }
- // Variables
- rgba_pixel pixel;
+ // Si el argumento no se reconoce...
+ if (!valid) return -1;
- // Calcula el offset
- uint32_t offset = (((y * w) + x) << 2); // * 4
+ // Argumento valido?
+ arg |= valid;
- // Lee los bits del pixel
- /*if ((offset + 3) < data.capacity()) {*/
- pixel.r = data[offset];
- pixel.g = data[(offset + 1)];
- pixel.b = data[(offset + 2)];
- pixel.a = data[(offset + 3)];
- /*} else {
- pixel.r = pixel.g = pixel.b = pixel.a = 0;
- std::cout << "Pixel read out of range." << std::endl;
- }*/
+ }
- return pixel;
+ // Indica los argumentos se han leido correctamente
+ return (arg) ? 1:-1;
}
-/*** Escribe el pixel en el buffer especificado ***/
-void SpriteSheet::PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, rgba_pixel pixel) {
+/*** Valida los parametros de entrada ***/
+bool Sprite::ValidateParameters() {
- // Variables
- uint32_t offset = (((y * w) + x) << 2); // * 4
+ // Resultado
+ bool r = true;
- /*if ((offset + 3) < data.capacity()) {*/
- data[offset] = pixel.r;
- data[(offset + 1)] = pixel.g;
- data[(offset + 2)] = pixel.b;
- data[(offset + 3)] = pixel.a;
- /*} else {
- std::cout << "Pixel write out of range." << std::endl;
- }*/
+ // Verifica si el archivo de origen existe
+ if (!fs->CheckIfFileExist(arg_in_file.value)) {
+ std::cout << arg_in_file.value << " file not found." << std::endl;
+ r = false;
+ } else {
+ parameter.in_file = arg_in_file.value;
+ }
-}
+ // Nombre base de los archivos de salida
+ if (arg_out_file.state) {
+ parameter.out_file = arg_out_file.value;
+ } else {
+ parameter.out_file = parameter.in_file.substr(0, (parameter.in_file.length() - 4));
+ }
+ // Tamaño del fotograma (ancho)
+ if (arg_width.state) {
+ parameter.width = std::stoi(arg_width.value);
+ if ((parameter.width < MIN_FRAME_SIZE) || (parameter.width > MAX_FRAME_SIZE)) {
+ std::cout << "Frame WIDTH out of range." << std::endl;
+ r = false;
+ }
+ } else {
+ std::cout << "Frame WIDTH not set." << std::endl;
+ r = false;
+ }
-/*** Genera la plantilla de frames del sprite ***/
-void SpriteSheet::GenerateSpriteSheet() {
-
- // Variables
- uint32_t img_x = 0, img_y = 0; // Punto de corte
- uint32_t _frames_w = (uint32_t)floor(in_width / frame_width); // Numero de columnas de frames
- uint32_t _frames_h = (uint32_t)floor(in_height / frame_height); // Numero de filas de frames
- uint32_t _total_frames = (_frames_w * _frames_h); // Numero total de frames
- uint32_t _current_frame = 0;
-
- // Calcula el tamaño del archivo de salida
- out_width = frame_width;
- out_height = (_total_frames * frame_height);
-
- // Prepara los bufferes a usar
- sheet.clear();
- sheet.resize(((out_width * out_height) << 2), 0); // * 4
-
- // Marcador
- std::cout << "This image contains " << _total_frames << " frames of " << frame_width << "x" << frame_height << " pixels." << std::endl;
-
- // Variables del control de corte del frame
- uint32_t src_pointer = 0, dst_pointer = 0;
- uint32_t cut_x = 0, cut_y = 0;
- uint32_t cut_start_x = 0, cut_end_x = 0, cut_start_y = 0, cut_end_y = 0;
-
- // Corta la imagen en una tira de frames
- for (img_y = 0; img_y <= (in_height - frame_height); img_y += frame_height) {
- // Calcula el punto de corte (Y)
- cut_start_y = img_y; cut_end_y = (cut_start_y + frame_height);
- for (img_x = 0; img_x <= (in_width - frame_width); img_x += frame_width) {
- // Contador de frames cortados
- _current_frame ++;
- std::cout << "\x0d" << "Cutting off " << _current_frame << " of " << _total_frames << " frames... ";
- // Calcula el punto de corte (X)
- cut_start_x = img_x; cut_end_x = (cut_start_x + frame_width);
- // Bucle de corte
- for (cut_y = cut_start_y; cut_y < cut_end_y; cut_y ++) {
- for (cut_x = cut_start_x; cut_x < cut_end_x; cut_x ++) {
- // Calcula el puntero de lectura
- src_pointer = (((cut_y * in_width) + cut_x) << 2);
- // Copia los 4 bytes del pixel de origen al buffer de destino
- for (uint32_t n = src_pointer; n < (src_pointer + 4); n ++) {
- sheet[dst_pointer] = raw[n];
- dst_pointer ++;
- }
- }
- }
+ // Tamaño del fotograma (altura)
+ if (arg_height.state) {
+ parameter.height = std::stoi(arg_height.value);
+ if ((parameter.height < MIN_FRAME_SIZE) || (parameter.height > MAX_FRAME_SIZE)) {
+ std::cout << "Frame HEIGHT out of range." << std::endl;
+ r = false;
}
+ } else {
+ std::cout << "Frame HEIGHT not set." << std::endl;
+ r = false;
}
- // Ok
- std::cout << "done!" << std::endl;
- std::cout << "Output sprite sheet size is " << out_width << "x" << out_height << " pixels." << std::endl;
-
- // Actualiza la informacion de la cabecera
- header.version = VERSION; // Version del programa
- sprintf(header.magic, "%s", MAGIC_STRING.c_str()); // Magic String
- header.sheet_width = out_width; // Dimensiones del strip
- header.sheet_height = out_height;
- header.frame_width = frame_width; // Dimensiones del frame
- header.frame_height = frame_height;
- header.total_frames = _total_frames; // Numero de frames del sprite
- for (uint32_t i = 0; i < sizeof(header.reserve); i ++) header.reserve[i] = 0; // Espacio reservado
+ // Generacion de la tira de fotogramas en un PNG
+ parameter.generate_strip = arg_strip.state;
+
+ // Parametros validados
+ return r;
+
+}
+
+
+
+/*** Resumen de los datos recopilados ***/
+void Sprite::Report() {
+
+ // Informacion de los parametros introducidos
+ std::cout << "Output filename: " << parameter.out_file << SPR_EXTENSION << std::endl;
+ std::cout << "Frame size: " << parameter.width << "x" << parameter.height << " pixels." << std::endl;
+ std::cout << "Generation of sprite strip: ";
+ if (parameter.generate_strip) {
+ std::cout << "enabled." << std::endl;
+ } else {
+ std::cout << "disabled." << std::endl;
+ }
+ std::cout << std::endl;
+
+}
+
+
+
+/*** DEBUG: Imprime la lista de argumentos introducidos ***/
+void Sprite::DebugArgList() {
+
+ std::cout << std::endl;
+ std::cout << "Argument list" << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << "Executable name: " << argument_list[0] << std::endl;
+ std::cout << "Input file: " << arg_in_file.state << " " << arg_in_file.value << std::endl;
+ std::cout << ARG_HELP << " " << arg_help.state << " " << arg_help.value << std::endl;
+ std::cout << ARG_OUT_FILE << " " << arg_out_file.state << " " << arg_out_file.value << std::endl;
+ std::cout << ARG_WIDTH << " " << arg_width.state << " " << arg_width.value << std::endl;
+ std::cout << ARG_HEIGHT << " " << arg_height.state << " " << arg_height.value << std::endl;
+ std::cout << ARG_STRIP << " " << arg_strip.state << " " << arg_strip.value << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << std::endl;
}
diff --git a/Tools/NGN_Sprite/source/sprite.h b/Tools/NGN_Sprite/source/sprite.h
index 7f1d088..c9d14a6 100644
--- a/Tools/NGN_Sprite/source/sprite.h
+++ b/Tools/NGN_Sprite/source/sprite.h
@@ -1,133 +1,105 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a Sprite sheet (.spr)
+ Conversor de PNG a Sprite (.spr) para N'gine
+ - Nucleo del programa -
- Proyecto iniciado el 3 de Marzo del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
-#ifndef SPRITE_H_INCLUDED
-#define SPRITE_H_INCLUDED
-
-
-
-/*** Defines ***/
-static const int32_t VERSION = 2; // Version del archivo
-static const std::string MAGIC_STRING = "NGN SPRITE"; // Magic string
+#ifndef TILE_MAP_H_INCLUDED
+#define TILE_MAP_H_INCLUDED
/*** Includes ***/
+// C++
#include
#include
-
-
-
-/*** Estructuras personalizadas ***/
-
-// Pixel RGBA
-struct rgba_pixel {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
-};
-
-// Cabecera del archivo
-struct file_header {
- uint8_t version; // Version del programa de conversion
- char magic[32]; // Magic String
- uint32_t sheet_width; // Tamaño del sheet completo
- uint32_t sheet_height;
- uint32_t frame_width; // Tamaño del frame
- uint32_t frame_height;
- uint32_t total_frames; // Numero total de frames de la imagen
- uint8_t reserve[256]; // Posible uso futuro
-};
+// Proyecto
+#include "defines.h"
+#include "message.h"
+#include "fs_manager.h"
+#include "convert_to_sprite.h"
/*** Declaracion de la clase ***/
-class SpriteSheet {
+class Sprite {
- // Public
public:
// Constructor
- SpriteSheet();
+ Sprite(int32_t argc, char* args[]);
// Destructor
- ~SpriteSheet();
+ ~Sprite();
/*** Propiedades ***/
- std::string input_filename; // Fichero de entrada
- std::string output_filename; // Nombre base del archivo de salida
- uint32_t frame_width; // Tamaño del frame
- uint32_t frame_height;
-
- bool strip; // Debe generarse el PNG con el Strip?
/*** Metodos ***/
-
- // Convierte el archivo
- int32_t ConvertPng();
+ int32_t Run(); // Programa principal
-
- // Private
private:
/*** Propiedades ***/
- // Define los vectores de memoria
- std::vector png; // Buffer para almacenar la imagen PNG
- std::vector raw; // Buffer para almacenar los pixeles de la imagen de entrada
- std::vector sheet; // Buffer para almacenar la composicion del Sprite Sheet
- std::vector out; // Buffer para almacenar la imagen de salida
-
- // Parametros de las imagenes
- uint32_t in_width, in_height; // Tamaño del archivo de entrada
- uint32_t out_width, out_height; // Tamaño del archivo de salida
+ // Flags de los argumentos
+ struct argument {
+ bool state;
+ std::string value;
+ };
+ argument arg_help; // Ayuda
+ argument arg_in_file; // Archivo de origen
+ argument arg_out_file; // Archivo de salida
+ argument arg_width; // Tamaño del tile
+ argument arg_height; // Nivel de optimizacion
+ argument arg_strip; // Generacion de un PNG con la tira de fotogramas
- // Cabecera del archivo de salida
- file_header header;
+ // Argumentos introducidos
+ int32_t argument_count; // Numero de argumentos en la linea de comandos
+ std::vector argument_list; // Lista con los argumentos proporcionados
- /*** Metodos ***/
-
- // Lee el archivo PNG y almacena los pixeles de la imagen en el buffer
- int32_t ReadPNG(std::string filename, std::vector &data);
+ // Parametros de la conversion
+ struct {
+ std::string in_file; // Archivo de entrada
+ std::string out_file; // Archivo de salida
+ int32_t width; // Tamaño del tile
+ int32_t height; // Nivel de optimizacion
+ bool generate_strip; // Generar la tira de fotogramas?
+ } parameter;
- // Graba el buffer a un archivo PNG
- int32_t WritePNG(std::string filename, std::vector &data);
- // Graba el archivo empaquetado
- int32_t WriteFile(std::string filename);
+ /*** Objetos ***/
+ Message* msg; // Gestor de mensages
+ FsManager* fs; // Gestor de archivos del sistema
+ ConvertToSprite* png2sprite; // Conversor de PNG a Sprite
- // Lee un pixel del buffer especificado
- rgba_pixel GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w);
- // Escribe el pixel en el buffer especificado
- void PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, rgba_pixel pixel);
+ /*** Metodos para la lectura de parametros***/
+ int32_t CheckArguments(); // Analiza la lista de argumentos proporcionados
+ bool ValidateParameters(); // Valida los parametros de entrada
+ void Report(); // Resumen de los datos
- // Corta la imagen de izquierda a derecha y de arriba a abajo, en bloques del tamaño del frame
- void GenerateSpriteSheet();
+ /*** Metodos de depuracion ***/
+ void DebugArgList(); // Imprime la lista de argumentos introducidos
};
-#endif // SPRITE_H_INCLUDED
+#endif // TILE_MAP_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/NGN_Tilemap.cbp b/Tools/NGN_Tilemap/NGN_Tilemap.cbp
index 7cb1ce0..8ea5b97 100644
--- a/Tools/NGN_Tilemap/NGN_Tilemap.cbp
+++ b/Tools/NGN_Tilemap/NGN_Tilemap.cbp
@@ -2,47 +2,57 @@
-
+
-
+
+
+
-
+
+
+
+
-
+
+
+
-
+
+
+
+
@@ -51,22 +61,27 @@
-
+
+
+
+
+
+
-
-
+
+
+
+
-
-
-
+
diff --git a/Tools/NGN_Tilemap/source/tilemap.cpp b/Tools/NGN_Tilemap/source/convert_to_tiles.cpp
similarity index 68%
rename from Tools/NGN_Tilemap/source/tilemap.cpp
rename to Tools/NGN_Tilemap/source/convert_to_tiles.cpp
index 8bbf925..8988cef 100644
--- a/Tools/NGN_Tilemap/source/tilemap.cpp
+++ b/Tools/NGN_Tilemap/source/convert_to_tiles.cpp
@@ -1,15 +1,15 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a TILES + MAP [Funciones]
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Convierte un archivo PNG en tiles -
Proyecto iniciado el 11 de Febrero del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
@@ -21,32 +21,35 @@
// C++
#include
#include
-#include
#include
#include
-
+#include
+#include
// LodePNG
#include "lodepng/lodepng.h"
-// Tilemap
-#include "tilemap.h"
+// Includes del proyecto
+#include "convert_to_tiles.h"
+#include "defines.h"
-/*** Contructor ***/
-PngToTiles::PngToTiles() {
-}
+/*** Constructor ***/
+ConvertToTiles::ConvertToTiles() {
+ size_of_tile = 0;
+ optimize = 0;
+ extra_files = false;
+ bg_width = 0;
+ bg_height = 0;
+ map_width = 0;
+ map_height = 0;
+ out_width = 0;
+ out_height = 0;
+ tileset_length = 0;
-/*** Destructor ***/
-PngToTiles::~PngToTiles() {
-
- // Borra todos los vectores de memoria
- png.clear();
- raw.clear();
- out.clear();
tiles.clear();
tmap.clear();
img_tile.clear();
@@ -57,163 +60,62 @@ PngToTiles::~PngToTiles() {
-/*** Convierte el archivo ***/
-int32_t PngToTiles::ConvertPng() {
-
- // Intenta cargar el archivo PNG, si hay error sal e informa.
- if (ReadPNG(input_filename, raw) > 0) return 1;
-
- // Convierte la imagen a tiles
- GenerateTileset();
-
- // Graba los archivos de salida
- if (WriteFile(output_filename) > 0) return 1;
-
- return 0;
-
-}
-
-
-
-/*** Lee el archivo PNG y almacena los pixeles de la imagen en el buffer ***/
-int32_t PngToTiles::ReadPNG(std::string filename, std::vector &data) {
-
- // Variables
- uint32_t width, height; // Tamaño del archivo cargado
-
- // Borra los buffers
- png.clear();
-
- // Carga el archivo PNG
- uint32_t _error = lodepng::load_file(png, filename);
-
- // Si se ha cargado correctamente, decodifica la imagen
- if (_error == 0) {
- _error = lodepng::decode(raw, width, height, png);
- } else {
- std::cout << "Error loading " << filename << "." << std::endl;
- png.clear();
- return 1;
- }
-
- // Guarda los tamaños de la imagen a convertir
- bg_width = width;
- bg_height = height;
-
- // Calcula el tamaño del mapa necesario
- if ((width % size_of_tile) == 0) {
- map_width = width;
- } else {
- map_width = ((((uint32_t)(width / size_of_tile)) + 1) * size_of_tile);
- }
- if ((height % size_of_tile) == 0) {
- map_height = height;
- } else {
- map_height = ((((uint32_t)(height / size_of_tile)) + 1) * size_of_tile);
- }
-
-
- // Verifica que la decodificacion sea la correcta
- if (_error == 0) {
- std::cout << "File " << filename << " loaded & decoded successfully." << std::endl;
- std::cout << "Image size is " << width << "x" << height << " pixels." << std::endl;
- // Aviso de tamaño no exacto
- if (((width % size_of_tile) != 0) || ((height % size_of_tile) != 0)) {
- std::cout << std::endl;
- std::cout << "WARNING: Image size doesn't fits the tile size." << std::endl;
- std::cout << "Half tiles will be filled with blank spaces." << std::endl;
- std::cout << "New image size is " << map_width << "x" << map_height << " pixels." << std::endl;
- std::cout << std::endl;
- }
- png.clear();
- return 0;
- } else {
- std::cout << "Error decoding " << filename << "." << std::endl;
- png.clear();
- return 1;
- }
-
-
-}
-
-
-/*** Graba el buffer a un archivo PNG ***/
-int32_t PngToTiles::WritePNG(std::string filename, std::vector &data) {
-
- // Borra los bufferes
- out.clear();
-
- uint32_t _error = lodepng::encode(out, data, out_width, out_height);
+/*** Destructor ***/
+ConvertToTiles::~ConvertToTiles() {
- // Si se ha codificado correctamente, graba el archivo
- if (_error == 0) {
- _error = lodepng::save_file(out, filename);
- if (_error == 0) {
- std::cout << "File " << filename << " successfully saved." << std::endl;
- out.clear();
- return 0;
- } else {
- std::cout << "Error saving " << filename << "." << std::endl;
- out.clear();
- return 1;
- }
- } else {
- std::cout << "Error encoding the RAW data." << std::endl;
- out.clear();
- return 1;
- }
+ tiles.clear();
+ tmap.clear();
+ img_tile.clear();
+ map_tile.clear();
+ buffer.clear();
}
-/*** Lee un pixel del buffer especificado ***/
-rgba_pixel PngToTiles::GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w) {
+/*** Convierte un archivo PNG en tiles ***/
+bool ConvertToTiles::Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t tile_size, // Tamaño del tile
+ uint32_t op_level, // Nivel de optimizacion
+ bool ex_files // Generar archivos adicionales?
+) {
- // Variables
- rgba_pixel pixel;
+ // Guarda los parametros
+ size_of_tile = tile_size;
+ optimize = op_level;
+ extra_files = ex_files;
- // Calcula el offset
- uint32_t offset = (((y * w) + x) << 2); // * 4
+ // Prepara el buffer para los pixeles de la imagen
+ std::vector png_pixels;
+ png_pixels.clear();
- // Lee los bits del pixel
- /*if ((offset + 3) < data.capacity()) {*/
- pixel.r = data[offset];
- pixel.g = data[(offset + 1)];
- pixel.b = data[(offset + 2)];
- pixel.a = data[(offset + 3)];
- /*} else {
- pixel.r = pixel.g = pixel.b = pixel.a = 0;
- std::cout << "Pixel read out of range." << std::endl;
- }*/
+ // Intenta abrir y decodificar el archivo PNG
+ if (!ReadPng(in_file, png_pixels)) return false;
- return pixel;
+ // Convierte la imagen cargada a un conjunto de TILES + MAPA, guardado los datos en sus correspondientes buffers
+ GenerateTileset(png_pixels);
-}
+ // Guarda en el archivo empaquetado los datos generados
+ bool r = WriteFile(out_file);
+ // Elimina los datos de todos los buffers usados
+ tiles.clear();
+ tmap.clear();
+ img_tile.clear();
+ map_tile.clear();
+ buffer.clear();
-
-/*** Escribe el pixel en el buffer especificado ***/
-void PngToTiles::PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, rgba_pixel pixel) {
-
- // Variables
- uint32_t offset = (((y * w) + x) << 2); // * 4
-
- /*if ((offset + 3) < data.capacity()) {*/
- data[offset] = pixel.r;
- data[(offset + 1)] = pixel.g;
- data[(offset + 2)] = pixel.b;
- data[(offset + 3)] = pixel.a;
- /*} else {
- std::cout << "Pixel write out of range." << std::endl;
- }*/
+ // Conversion correcta
+ return r;
}
/*** Convierte la imagen en tiles + mapa ***/
-void PngToTiles::GenerateTileset() {
+void ConvertToTiles::GenerateTileset(std::vector &data) {
// Inicializa las variables
tileset_length = 0;
@@ -260,7 +162,7 @@ void PngToTiles::GenerateTileset() {
for (img_y = 0; img_y <= (map_height - size_of_tile); img_y += size_of_tile) {
for (img_x = 0; img_x <= (map_width - size_of_tile); img_x += size_of_tile) {
// Obten un tile
- GetTile(img_tile, raw, img_x, img_y, bg_width, bg_height);
+ GetTile(img_tile, data, img_x, img_y, bg_width, bg_height);
// Comparalo con los tiles existentes y añadelo si no existe. Registra el resultado en el mapa
t = OptimizeTiles();
// Codifica el WORD con la info del tile
@@ -325,98 +227,229 @@ void PngToTiles::GenerateTileset() {
/*** Graba el archivo empaquetado ***/
-int32_t PngToTiles::WriteFile(std::string filename) {
+bool ConvertToTiles::WriteFile(std::string filename) {
- // Proteccion de path
- if (filename.length() >= 244) {
- std::cout << "Error saving " << filename << "." << std::endl;
- std::cout << "Path too long." << std::endl;
- return 1;
- }
-
- // Variables
- uint32_t i = 0;
+ // Prepara el buffer temporal
+ std::vector tileset_png;
+ tileset_png.clear();
// Intenta codificar el Tileset a PNG
- out.clear();
- if (lodepng::encode(out, tiles, out_width, out_height) > 0) return 1;
-
+ if (lodepng::encode(tileset_png, tiles, out_width, out_height) != 0) {
+ std::cout << "Error encoding the tileset image data." << std::endl;
+ tileset_png.clear();
+ return false;
+ }
// Guarda la informacion para la cabecera del archivo
-
+ FileHeader header;
+ memset((void*)&header, 0, sizeof(header));
+ // Datos de version
header.version = VERSION;
-
- sprintf(header.magic, "%s", MAGIC_STRING.c_str());
-
+ strncpy(header.magic, MAGIC_STRING.c_str(), MAGIC_STRING.length());
+ // Datos del fondo original
header.bg_width = bg_width;
header.bg_height = bg_height;
-
+ // Datos del mapa
header.map_width = map_width;
header.map_height = map_height;
header.map_length = tmap.capacity();
-
+ // Datos del tileset
header.tileset_width = out_width;
header.tileset_height = out_height;
- header.tileset_length = out.capacity();
+ header.tileset_length = tileset_png.capacity();
header.tile_size = size_of_tile;
- for (i = 0; i < sizeof(header.reserve); i ++) header.reserve[i] = 0;
-
- // Genera el nombre de archivo
- char f[256];
- char basename[244];
- for (i = 0; i < filename.length(); i ++) basename[i] = filename[i]; // Nombre base
- basename[i] = '\0'; // Terminador
-
- //std::cout << filename << std::endl;
- //std::cout << basename << std::endl;
+ // Genera el nombres de archivo
+ std::string fname = filename + TBG_EXTENSION;
+ const char* tilemap_filename = fname.c_str();
// Graba el archivo principal
- sprintf(f, "%s.tbg", basename);
std::ofstream file;
- file.open(f, std::ofstream::out | std::ofstream::binary);
+ file.open(tilemap_filename, std::ofstream::out | std::ofstream::binary);
if (file.is_open()) {
- file.write((char*)&header, sizeof(header)); // Cabecera
- file.write((char*)&out[0], out.capacity()); // Tileset en PNG
- file.write((char*)&tmap[0], tmap.capacity()); // Mapa
+ file.write((char*)&header, sizeof(header)); // Cabecera
+ file.write((char*)&tileset_png[0], tileset_png.capacity()); // Tileset en PNG
+ file.write((char*)&tmap[0], tmap.capacity()); // Mapa
file.close();
- std::cout << "File " << f << " successfully saved." << std::endl;
+ std::cout << "File " << fname << " successfully saved." << std::endl;
} else {
- std::cout << "Error saving " << f << "." << std::endl;
- return 1;
+ std::cout << "Error saving " << fname << "." << std::endl;
+ return false;
}
+ // Elimia los datos del PNG del tileset
+ tileset_png.clear();
- // Si se han pedido los archivos extra...
- if (extra_files) {
-
- // Graba la imagen con el tileset
- sprintf(f, "%s_tileset.png", basename);
- if (WritePNG(f, tiles) > 0) return 1;
+ // Si no se requieren los archivos adicionales, termina
+ if (!extra_files) return true;
- // Graba el mapa del tileset en formato binario
- sprintf(f, "%s_map.bin", basename);
- file.open(f, std::ofstream::out | std::ofstream::binary);
- if (file.is_open()) {
- file.write((char*)&tmap[0], tmap.capacity());
- file.close();
- std::cout << "File " << f << " successfully saved." << std::endl;
- } else {
- std::cout << "Error saving " << f << "." << std::endl;
- return 1;
- }
+ // Guarda el tileset en PNG
+ fname = (filename + TILESET_EXTENSION);
+ if (!WritePng(fname, tiles, out_width, out_height)) return false;
+ // Guarda el mapa en formato binario
+ fname = (filename + MAP_EXTENSION);
+ const char* map_filename = fname.c_str();
+ file.open(map_filename, std::ofstream::out | std::ofstream::binary);
+ if (file.is_open()) {
+ file.write((char*)&tmap[0], tmap.capacity());
+ file.close();
+ std::cout << "File " << fname << " successfully saved." << std::endl;
+ } else {
+ std::cout << "Error saving " << fname << "." << std::endl;
+ return false;
}
// Todo correcto
- return 0;
+ return true;
+
+}
+
+
+
+/*** Lee un archivo .PNG y coloca los pixeles en un buffer ***/
+bool ConvertToTiles::ReadPng(std::string filename, std::vector &data) {
+
+ // Variables
+ uint32_t width = 0, height = 0; // Tamaño del archivo cargado
+
+ // Prepara el buffer temporal
+ std::vector png_data;
+ png_data.clear();
+
+ // Prepara el buffer para los datos decodificados
+ data.clear();
+
+ // Carga el archivo PNG
+ if (lodepng::load_file(png_data, filename) != 0) {
+ std::cout << "Error loading " << filename << "." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Si se ha cargado correctamente, decodifica la imagen
+ if (lodepng::decode(data, width, height, png_data) != 0) {
+ std::cout << "Error decoding " << filename << "." << std::endl;
+ png_data.clear();
+ data.clear();
+ return false;
+ }
+
+ // Guarda los tamaños de la imagen a convertir
+ bg_width = width;
+ bg_height = height;
+
+ // Calcula el tamaño del mapa necesario
+ if ((width % size_of_tile) == 0) {
+ map_width = width;
+ } else {
+ map_width = ((((uint32_t)(width / size_of_tile)) + 1) * size_of_tile);
+ }
+ if ((height % size_of_tile) == 0) {
+ map_height = height;
+ } else {
+ map_height = ((((uint32_t)(height / size_of_tile)) + 1) * size_of_tile);
+ }
+
+ // Informacion del archivo cargado
+ std::cout << "File " << filename << " loaded & decoded successfully." << std::endl;
+ std::cout << "Image size is " << width << "x" << height << " pixels." << std::endl;
+ // Aviso de tamaño no exacto
+ if (((width % size_of_tile) != 0) || ((height % size_of_tile) != 0)) {
+ std::cout << std::endl;
+ std::cout << "WARNING: Image size doesn't fits the tile size." << std::endl;
+ std::cout << "Half tiles will be filled with blank space." << std::endl;
+ std::cout << "New image size is " << map_width << "x" << map_height << " pixels." << std::endl;
+ std::cout << std::endl;
+ }
+
+ // Limpia el buffer temporal
+ png_data.clear();
+
+ // Fin de la funcion de carga
+ return true;
+
+}
+
+
+
+/*** Graba un buffer de pixeles en un archivo PNG ***/
+bool ConvertToTiles::WritePng(std::string filename, std::vector &data, uint32_t width, uint32_t height) {
+
+ // Prepara el buffer temporal
+ std::vector png_data;
+ png_data.clear();
+
+ // Intenta codificar los pixeles del buffer a PNG
+ if (lodepng::encode(png_data, data, width, height) != 0) {
+ std::cout << "Error encoding the .PNG image data." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Intenta guardar el archivo .PNG
+ if (lodepng::save_file(png_data, filename) != 0) {
+ std::cout << "Error saving " << filename << " file." << std::endl;
+ png_data.clear();
+ return false;
+ }
+
+ // Grabacion correcta
+ std::cout << "File " << filename << " successfully saved." << std::endl;
+ png_data.clear();
+ return true;
+
+}
+
+
+
+/*** Lee un pixel del buffer especificado ***/
+RgbaPixel ConvertToTiles::GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w) {
+
+ // Variables
+ RgbaPixel pixel;
+
+ // Calcula el offset
+ uint32_t offset = (((y * w) + x) << 2); // * 4
+
+ // Lee los bits del pixel
+ /*if ((offset + 3) < data.capacity()) {*/
+ pixel.r = data[offset];
+ pixel.g = data[(offset + 1)];
+ pixel.b = data[(offset + 2)];
+ pixel.a = data[(offset + 3)];
+ /*} else {
+ pixel.r = pixel.g = pixel.b = pixel.a = 0;
+ std::cout << "Pixel read out of range." << std::endl;
+ }*/
+
+ return pixel;
+
+}
+
+
+
+/*** Escribe el pixel en el buffer especificado ***/
+void ConvertToTiles::PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, RgbaPixel pixel) {
+
+ // Variables
+ uint32_t offset = (((y * w) + x) << 2); // * 4
+
+ /*if ((offset + 3) < data.capacity()) {*/
+ data[offset] = pixel.r;
+ data[(offset + 1)] = pixel.g;
+ data[(offset + 2)] = pixel.b;
+ data[(offset + 3)] = pixel.a;
+ /*} else {
+ std::cout << "Pixel write out of range." << std::endl;
+ }*/
}
/*** Genera un tile del buffer especificado ***/
-void PngToTiles::GetTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t max_w, uint32_t max_h) {
+void ConvertToTiles::GetTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t max_w, uint32_t max_h) {
// Borra el buffer de salida
//tl.clear();
@@ -454,7 +487,7 @@ void PngToTiles::GetTile(std::vector &tl, std::vector &img, ui
/*** Escribe un tile en el buffer especificado ***/
-void PngToTiles::PutTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t w) {
+void ConvertToTiles::PutTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t w) {
// Lee el tile del buffer de origen y guardalo en el de destino
uint32_t o_offset = 0, d_offset = 0;
@@ -476,9 +509,8 @@ void PngToTiles::PutTile(std::vector &tl, std::vector &img, ui
}
-
/*** Realiza la optimizacion de tiles unicos ***/
-uint32_t PngToTiles::OptimizeTiles() {
+uint32_t ConvertToTiles::OptimizeTiles() {
// Variables
uint32_t i = 0;
@@ -537,7 +569,7 @@ uint32_t PngToTiles::OptimizeTiles() {
/*** Compara si 2 tiles son identicos (img_tile vs map_tile) ***/
-bool PngToTiles::CompareNormal() {
+bool ConvertToTiles::CompareNormal() {
//bool r = true; // Son iguales?
uint32_t i = 0;
@@ -559,7 +591,7 @@ bool PngToTiles::CompareNormal() {
/*** Compara si 2 tiles estan en espejo horizontal (H FLIP) ***/
-bool PngToTiles::CompareFlipH() {
+bool ConvertToTiles::CompareFlipH() {
//bool r = true; // Son iguales?
@@ -568,7 +600,7 @@ bool PngToTiles::CompareFlipH() {
uint32_t x, y, _x;
uint32_t last = size_of_tile - 1;
- rgba_pixel p, _p;
+ RgbaPixel p, _p;
// Compara todos los pixels de las tiles
for (y = 0; y < size_of_tile; y ++) {
@@ -600,7 +632,7 @@ bool PngToTiles::CompareFlipH() {
/*** Compara si 2 tiles estan en espejo vertical (V FLIP) ***/
-bool PngToTiles::CompareFlipV() {
+bool ConvertToTiles::CompareFlipV() {
//bool r = true; // Son iguales?
@@ -609,7 +641,7 @@ bool PngToTiles::CompareFlipV() {
uint32_t x, y, _y;
uint32_t last = size_of_tile - 1;
- rgba_pixel p, _p;
+ RgbaPixel p, _p;
// Compara todos los pixels de las tiles
for (y = 0; y < size_of_tile; y ++) {
@@ -641,7 +673,7 @@ bool PngToTiles::CompareFlipV() {
/*** Compara si 2 tiles estan en espejo completo (H & V FLIP) ***/
-bool PngToTiles::Compare180deg() {
+bool ConvertToTiles::Compare180deg() {
//bool r = true; // Son iguales?
@@ -650,7 +682,7 @@ bool PngToTiles::Compare180deg() {
uint32_t x, y, _x, _y;
uint32_t last = size_of_tile - 1;
- rgba_pixel p, _p;
+ RgbaPixel p, _p;
// Compara todos los pixels de las tiles
for (y = 0; y < size_of_tile; y ++) {
@@ -683,7 +715,7 @@ bool PngToTiles::Compare180deg() {
/*** Compara si 2 tiles estan rotadas 90º a la derecha (90º Clock Wise) ***/
-bool PngToTiles::Compare90degCW() {
+bool ConvertToTiles::Compare90degCW() {
//bool r = true; // Son iguales?
@@ -692,7 +724,7 @@ bool PngToTiles::Compare90degCW() {
uint32_t x, y, _x, _y;
uint32_t last = size_of_tile - 1;
- rgba_pixel p, _p;
+ RgbaPixel p, _p;
// Compara todos los pixels de las tiles
for (y = 0; y < size_of_tile; y ++) {
@@ -725,7 +757,7 @@ bool PngToTiles::Compare90degCW() {
/*** Compara si 2 tiles estan rotadas 90º a la izquierda (90º Anti Clock Wise) ***/
-bool PngToTiles::Compare90degACW() {
+bool ConvertToTiles::Compare90degACW() {
//bool r = true; // Son iguales?
@@ -734,7 +766,7 @@ bool PngToTiles::Compare90degACW() {
uint32_t x, y, _x, _y;
uint32_t last = size_of_tile - 1;
- rgba_pixel p, _p;
+ RgbaPixel p, _p;
// Compara todos los pixels de las tiles
for (y = 0; y < size_of_tile; y ++) {
@@ -763,4 +795,3 @@ bool PngToTiles::Compare90degACW() {
return true;
}
-
diff --git a/Tools/NGN_Tilemap/source/convert_to_tiles.h b/Tools/NGN_Tilemap/source/convert_to_tiles.h
new file mode 100644
index 0000000..557b27b
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/convert_to_tiles.h
@@ -0,0 +1,125 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Convierte un archivo PNG en tiles -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef CONVERT_TO_TILES_H_INCLUDED
+#define CONVERT_TO_TILES_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class ConvertToTiles {
+
+ public:
+
+ // Constructor
+ ConvertToTiles();
+
+ // Destructor
+ ~ConvertToTiles();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+
+ // Convierte un archivo PNG en tiles
+ bool Convert(
+ std::string in_file, // Archivo PNG a convertir
+ std::string out_file, // Nombre base de los archivos de salida
+ uint32_t tile_size, // Tamaño del tile
+ uint32_t op_level, // Nivel de optimizacion
+ bool ex_files // Generar archivos adicionales?
+ );
+
+
+ private:
+
+ /*** Propiedades ***/
+
+ // Parametros de funcionamiento
+ uint32_t size_of_tile; // Tamaño del tile [32x32 por defecto]
+ uint32_t optimize; // Nivel de optimizacion
+ bool extra_files; // Generar archivos adicionales?
+
+ // Parametros de las imagenes
+ uint32_t bg_width, bg_height; // Tamaño real del fondo
+ uint32_t map_width, map_height; // Tamaño del mapa a generar
+ uint32_t out_width, out_height; // Tamaño del archivo de salida
+ uint32_t tileset_length; // Numero de tiles unicos del tileset
+
+ // Buffers de datos
+ std::vector tiles; // Buffer para almacenar los tiles del tileset
+ std::vector tmap; // Buffer para almacenar el mapa
+ std::vector img_tile; // Almacena un tile de la imagen de Origen
+ std::vector map_tile; // Almacena un tile del mapa de destino
+ std::vector buffer; // Buffer temporal de datos
+
+
+ /*** Metodos ***/
+
+ // Convierte la imagen en tiles + mapa
+ void GenerateTileset(std::vector &data);
+
+ // Graba el archivo empaquetado
+ bool WriteFile(std::string filename);
+
+ // Lee el archivo .PNG y almacena los pixeles de la imagen en el buffer
+ bool ReadPng(std::string filename, std::vector &data);
+ // Graba un buffer de pixeles en un archivo PNG
+ bool WritePng(std::string filename, std::vector &data, uint32_t width, uint32_t height);
+
+ // Lee un pixel del buffer especificado
+ RgbaPixel GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w);
+ // Escribe el pixel en el buffer especificado
+ void PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, RgbaPixel pixel);
+
+ // Lee un tile del buffer especificado
+ void GetTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t max_w, uint32_t max_h);
+ // Escribe un tile en el buffer especificado
+ void PutTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t w);
+
+ // Realiza la optimizacion de tiles unicos
+ uint32_t OptimizeTiles();
+ // Compara si 2 tiles son identicos (img_tile vs map_tile)
+ bool CompareNormal();
+ // Compara si 2 tiles estan en espejo horizontal (H FLIP)
+ bool CompareFlipH();
+ // Compara si 2 tiles estan en espejo vertical (V FLIP)
+ bool CompareFlipV();
+ // Compara si 2 tiles estan en espejo completo (H & V FLIP)
+ bool Compare180deg();
+ // Compara si 2 tiles estan rotadas 90º a la derecha (90º Clock Wise)
+ bool Compare90degCW();
+ // Compara si 2 tiles estan rotadas 90º a la izquierda (90º Anti Clock Wise)
+ bool Compare90degACW();
+
+};
+
+
+
+#endif // CONVERT_TO_TILES_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/source/defines.h b/Tools/NGN_Tilemap/source/defines.h
new file mode 100644
index 0000000..476f253
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/defines.h
@@ -0,0 +1,107 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Definiciones -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+#ifndef DEFINES_H_INCLUDED
+#define DEFINES_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+
+
+
+/*** Codigos de ERROR ***/
+const int32_t ERR_CODE_OK = 0x00;
+const int32_t ERR_CODE_BOOTFAILURE = 0x01;
+const int32_t ERR_CODE_ARG_INVALID = 0x02;
+const int32_t ERR_CODE_CONVERSION_FAILURE = 0x03;
+
+
+/*** Version de N'gine ***/
+const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
+const int32_t NGN_VERSION_MINOR = 11; // Version menor
+const int32_t NGN_VERSION_PATCH = 0; // Version parche
+const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
+
+
+/*** Version del programa ***/
+const std::string PROGRAM_NAME = "N'gine PNG to Tile Map converter"; // Nombre del programa
+const std::string CC_YEARS = "2016-2023"; // Años en el texto CREATIVE COMMONS
+const int32_t PROGRAM_VERSION_MAJOR = 2; // Version mayor
+const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
+const int32_t PROGRAM_VERSION_PATCH = 0; // Version parche
+const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
+const std::string MAGIC_STRING = "NGN TILEDBG"; // Magic string
+const uint8_t MS_LENGTH = 11; // Logitud del magic string
+const uint8_t VERSION = 2; // Version del archivo
+
+
+/*** Textos recurrentes ***/
+const std::string TEXT_DASHED_LINE = "------------------------------------------------------------";
+
+
+/*** Listado de argumentos disponibles ***/
+const int32_t ARG_MIN_NUM = 2; // Numero minimo de argumentos
+const int32_t ARG_MAX_NUM = 10; // Numero maximo de argumentos
+const std::string ARG_HELP = "-?"; // Ayuda
+const std::string ARG_OUT_FILE = "-o"; // Define el archivo de salida
+const std::string ARG_TILE_SIZE = "-ts"; // Define el tamaño del tile
+const std::string ARG_OP_LEVEL = "-lv"; // Nivel de optimizacion
+const std::string ARG_EXTRA_FILES = "-ef"; // Genera los archivos de salida adicionales
+
+/*** Parametros de los argumentos ***/
+const int32_t MIN_TILE_SIZE = 8; // Tamaño minimo del tile
+const int32_t MAX_TILE_SIZE = 1024; // Tamaño maximo del tile
+const int32_t DEFAULT_TILE_SIZE = 32; // Tamaño por defecto del tile
+const int32_t DEFAULT_OP_LEVEL = 2; // Valor de optimizacion por defecto
+
+/*** Extensiones ***/
+const std::string TBG_EXTENSION = ".tbg"; // Extension de archivo: Archivo tilemap
+const std::string TILESET_EXTENSION = "_tileset.png"; // Extension de archivo: Tileset en PNG
+const std::string MAP_EXTENSION = "_map.bin"; // Extension de archivo: Mapa en formato binario
+
+
+
+/*** Estructuras personalizadas ***/
+
+// Pixel RGBA
+struct RgbaPixel {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+};
+
+// Cabecera del archivo
+struct FileHeader {
+ uint8_t version; // Version del programa de mapeado
+ char magic[32]; // Magic string
+ uint32_t bg_width; // Ancho del fondo (imagen original)
+ uint32_t bg_height; // Alto del fondo (imagen original)
+ uint32_t tileset_width; // Ancho del Tileset en pixeles
+ uint32_t tileset_height; // Ancho del Tileset en pixeles
+ uint32_t map_width; // Ancho del mapa (segun los tiles) en pixeles
+ uint32_t map_height; // Alto del mapa (segun los tiles) en pixeles
+ uint32_t tile_size; // Tamaño del tile
+ uint32_t tileset_length; // Tamaño de los datos del tileset
+ uint32_t map_length; // Tamaño de los datos del mapa
+ char reserve[256]; // Posible uso futuro
+};
+
+
+#endif // DEFINES_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/source/fs_manager.cpp b/Tools/NGN_Tilemap/source/fs_manager.cpp
new file mode 100644
index 0000000..83bbe9b
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/fs_manager.cpp
@@ -0,0 +1,171 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+// C
+#include
+#include
+#include
+// Includes del proyecto
+#include "fs_manager.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+FsManager::FsManager() {
+
+}
+
+
+
+/*** Destructor ***/
+FsManager::~FsManager() {
+
+}
+
+
+
+/*** Crea una lista de archivos de un directorio concreto ***/
+std::vector FsManager::GetListOfFiles(std::string path) {
+
+ // Crea una lista temporal
+ std::vector file_list;
+ file_list.clear();
+
+ // Lista recursiva
+ if (path.length() > 0) GetFilesRecursive(path, file_list);
+
+ // Devuelve la lista creada
+ return file_list;
+
+}
+
+
+
+/*** Crea un directorio a partir de un path, si este no existe ***/
+int32_t FsManager::MakePath(std::string path) {
+
+ // Caracter de referencia
+ std::string getchar = "";
+
+ // Genera una lista de directorios
+ std::vector directory;
+ directory.clear();
+ for (uint32_t i = 0; i < path.length(); i ++) {
+ getchar = path.at(i);
+ if (getchar == "/") {
+ directory.push_back(path.substr(0, i));
+ }
+ }
+
+ // Genera un path sin el nombre de archivo
+ for (uint32_t i = 0; i < directory.size(); i ++) {
+ if (directory[i] == ".") continue;
+ if (i == (directory.size() - 1)) std::cout << "Attempting to create [" << directory[i] << "]" << std::endl;
+ const char* p = directory[i].c_str();
+ #if defined (OS_WINDOWS)
+ mkdir(p);
+ #elif defined (OS_LINUX)
+ mkdir(p, 0777);
+ #else
+ mkdir(p, 0777);
+ #endif
+ }
+
+ // Devuelve el resultado
+ return directory.size();
+
+}
+
+
+
+/*** Crea una lista recursiva de los archivos ***/
+void FsManager::GetFilesRecursive(std::string path, std::vector &files) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Estructura de datos de "dirent"
+ struct dirent* dp;
+ // Variable de control de los metodos
+ DIR *dir;
+
+ // Intenta abrir el directorio
+ dir = opendir(_path);
+ // Si no puedes, asume que es un archivo y registralo
+ if (!dir) {
+ if (CheckIfFileExist(path)) files.push_back(path);
+ return;
+ }
+
+ // Variables
+ std::string file_name = "";
+
+ // Lee el directorio hasta que te quedes sin datos
+ while ((dp = readdir(dir)) != NULL) {
+
+ // Nombre del archivo actual
+ file_name = dp->d_name;
+
+ // Si es el indicador de raiz (.) o subir un nivel (..), saltatelo
+ if ((file_name == ".") || (file_name == "..")) continue;
+
+ // Genera una nueva ruta, por si es un directorio y no un archivo
+ std::string new_path = "";
+ if (path.substr(0, 1) != ".") new_path += (path + "/");
+ new_path += dp->d_name;
+
+ // Recursividad
+ GetFilesRecursive(new_path, files);
+
+ }
+
+ // Cierra el directorio
+ closedir(dir);
+
+}
+
+
+
+/*** Verifica que el archivo existe ***/
+bool FsManager::CheckIfFileExist(std::string path) {
+
+ // Convierte la ruta de archivo a constante
+ const char* _path = path.c_str();
+
+ // Intenta abrir el archivo en modo binario
+ std::ifstream file;
+ file.open(_path, std::ifstream::in | std::ifstream::binary);
+
+ // Segun si has podido o no abrirlo...
+ if (file.is_open()) {
+ file.close();
+ return true;
+ } else {
+ return false;
+ }
+
+}
diff --git a/Tools/NGN_Tilemap/source/fs_manager.h b/Tools/NGN_Tilemap/source/fs_manager.h
new file mode 100644
index 0000000..a89cf92
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/fs_manager.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Gestor de sistema de archivos del sistema -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef FS_MANAGER_H_INCLUDED
+#define FS_MANAGER_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class FsManager {
+
+ public:
+
+ // Constructor
+ FsManager();
+
+ // Destructor
+ ~FsManager();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+
+ // Crea una lista con los archivos contenidos en un directorio
+ std::vector GetListOfFiles(std::string path);
+
+ // Crea un directorio a partir de un path, si este no existe
+ int32_t MakePath(std::string path);
+
+
+ // Verifica si un archivo existe
+ bool CheckIfFileExist(std::string path);
+
+
+ private:
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+
+ // Metodo recursivo para listar todos los archivos de todos los directorios
+ void GetFilesRecursive(std::string path, std::vector &files);
+
+};
+
+
+
+#endif // FS_MANAGER_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/source/lodepng/lodepng.cpp b/Tools/NGN_Tilemap/source/lodepng/lodepng.cpp
index ee8cf33..1f89677 100644
--- a/Tools/NGN_Tilemap/source/lodepng/lodepng.cpp
+++ b/Tools/NGN_Tilemap/source/lodepng/lodepng.cpp
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,10 +44,10 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
#endif /*_MSC_VER */
-const char* LODEPNG_VERSION_STRING = "20200306";
+const char* LODEPNG_VERSION_STRING = "20220717";
/*
-This source file is built up in the following large parts. The code sections
+This source file is divided into the following large parts. The code sections
with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way.
-Tools for C and common code for PNG and Zlib
-C Code for Zlib (huffman, deflate, ...)
@@ -267,7 +267,7 @@ typedef struct ucvector {
} ucvector;
/*returns 1 if success, 0 if failure ==> nothing done*/
-static unsigned ucvector_resize(ucvector* p, size_t size) {
+static unsigned ucvector_reserve(ucvector* p, size_t size) {
if(size > p->allocsize) {
size_t newsize = size + (p->allocsize >> 1u);
void* data = lodepng_realloc(p->data, newsize);
@@ -277,10 +277,15 @@ static unsigned ucvector_resize(ucvector* p, size_t size) {
}
else return 0; /*error: not enough memory*/
}
- p->size = size;
return 1; /*success*/
}
+/*returns 1 if success, 0 if failure ==> nothing done*/
+static unsigned ucvector_resize(ucvector* p, size_t size) {
+ p->size = size;
+ return ucvector_reserve(p, size);
+}
+
static ucvector ucvector_init(unsigned char* buffer, size_t size) {
ucvector v;
v.data = buffer;
@@ -299,6 +304,7 @@ static void string_cleanup(char** out) {
*out = NULL;
}
+/*also appends null termination character*/
static char* alloc_string_sized(const char* in, size_t insize) {
char* out = (char*)lodepng_malloc(insize + 1);
if(out) {
@@ -479,71 +485,62 @@ static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned c
ensureBits functions:
Ensures the reader can at least read nbits bits in one or more readBits calls,
safely even if not enough bits are available.
-Returns 1 if there are enough bits available, 0 if not.
+The nbits parameter is unused but is given for documentation purposes, error
+checking for amount of bits must be done beforehand.
*/
-/*See ensureBits documentation above. This one ensures exactly 1 bit */
-/*static unsigned ensureBits1(LodePNGBitReader* reader) {
- if(reader->bp >= reader->bitsize) return 0;
- reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u);
- return 1;
-}*/
-
/*See ensureBits documentation above. This one ensures up to 9 bits */
-static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits9(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 1u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
- if(start + 0u < size) reader->buffer |= reader->data[start + 0];
+ if(start + 0u < size) reader->buffer = reader->data[start + 0];
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 17 bits */
-static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits17(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 2u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 25 bits */
-static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits25(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 3u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 32 bits */
-static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits32(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 4u < size) {
@@ -551,7 +548,6 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u)));
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
@@ -559,48 +555,28 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */
-static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
/* The shift allows nbits to be only up to 31. */
return reader->buffer & ((1u << nbits) - 1u);
}
/* Must have enough bits available with ensureBits */
-static void advanceBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void advanceBits(LodePNGBitReader* reader, size_t nbits) {
reader->buffer >>= nbits;
reader->bp += nbits;
}
/* Must have enough bits available with ensureBits */
-static unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
unsigned result = peekBits(reader, nbits);
advanceBits(reader, nbits);
return result;
}
-
-/* Public for testing only. steps and result must have numsteps values. */
-unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
- size_t numsteps, const size_t* steps, unsigned* result) {
- size_t i;
- LodePNGBitReader reader;
- unsigned error = LodePNGBitReader_init(&reader, data, size);
- if(error) return 0;
- for(i = 0; i < numsteps; i++) {
- size_t step = steps[i];
- unsigned ok;
- if(step > 25) ok = ensureBits32(&reader, step);
- else if(step > 17) ok = ensureBits25(&reader, step);
- else if(step > 9) ok = ensureBits17(&reader, step);
- else ok = ensureBits9(&reader, step);
- if(!ok) return 0;
- result[i] = readBits(&reader, step);
- }
- return 1;
-}
#endif /*LODEPNG_COMPILE_DECODER*/
static unsigned reverseBits(unsigned bits, unsigned num) {
@@ -735,10 +711,11 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) {
numpresent = 0;
for(i = 0; i < tree->numcodes; ++i) {
unsigned l = tree->lengths[i];
- unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
- /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
- unsigned reverse = reverseBits(symbol, l);
+ unsigned symbol, reverse;
if(l == 0) continue;
+ symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
+ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
+ reverse = reverseBits(symbol, l);
numpresent++;
if(l <= FIRSTBITS) {
@@ -1102,11 +1079,10 @@ static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree*
advanceBits(reader, l);
return value;
} else {
- unsigned index2;
advanceBits(reader, FIRSTBITS);
- index2 = value + peekBits(reader, l - FIRSTBITS);
- advanceBits(reader, codetree->table_len[index2] - FIRSTBITS);
- return codetree->table_value[index2];
+ value += peekBits(reader, l - FIRSTBITS);
+ advanceBits(reader, codetree->table_len[value] - FIRSTBITS);
+ return codetree->table_value[value];
}
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -1139,7 +1115,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
unsigned* bitlen_cl = 0;
HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/
- if(!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/
+ if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the memory*/
+ ensureBits17(reader, 14);
/*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/
HLIT = readBits(reader, 5) + 257;
@@ -1260,10 +1237,14 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/
static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
- unsigned btype) {
+ unsigned btype, size_t max_output_size) {
unsigned error = 0;
HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/
HuffmanTree tree_d; /*the huffman tree for distance codes*/
+ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */
+ int done = 0;
+
+ if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
HuffmanTree_init(&tree_ll);
HuffmanTree_init(&tree_d);
@@ -1271,14 +1252,21 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d);
else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader);
- while(!error) /*decode all symbols until end reached, breaks at end code*/ {
+
+ while(!error && !done) /*decode all symbols until end reached, breaks at end code*/ {
/*code_ll is literal, length or end code*/
unsigned code_ll;
- ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */
+ /* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second literal is read at once. This
+ appears to be slightly faster, than ensuring 20 bits here for 1 huffman symbol and the potential 5 extra bits for the length symbol.*/
+ ensureBits32(reader, 30);
code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ if(code_ll <= 255) {
+ /*slightly faster code path if multiple literals in a row*/
+ out->data[out->size++] = (unsigned char)code_ll;
+ code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ }
if(code_ll <= 255) /*literal symbol*/ {
- if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/);
- out->data[out->size - 1] = (unsigned char)code_ll;
+ out->data[out->size++] = (unsigned char)code_ll;
} else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ {
unsigned code_d, distance;
unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/
@@ -1291,6 +1279,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX];
if(numextrabits_l != 0) {
/* bits already ensured above */
+ ensureBits25(reader, 5);
length += readBits(reader, numextrabits_l);
}
@@ -1318,7 +1307,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(distance > start) ERROR_BREAK(52); /*too long backward distance*/
backward = start - distance;
- if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/);
+ out->size += length;
if(distance < length) {
size_t forward;
lodepng_memcpy(out->data + start, out->data + backward, distance);
@@ -1330,10 +1319,13 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
lodepng_memcpy(out->data + start, out->data + backward, length);
}
} else if(code_ll == 256) {
- break; /*end code, break the loop*/
+ done = 1; /*end code, finish the loop*/
} else /*if(code_ll == INVALIDSYMBOL)*/ {
ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
}
+ if(out->allocsize - out->size < reserved_size) {
+ if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
+ }
/*check if any of the ensureBits above went out of bounds*/
if(reader->bp > reader->bitsize) {
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
@@ -1341,6 +1333,9 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
/* TODO: revise error codes 10,11,50: the above comment is no longer valid */
ERROR_BREAK(51); /*error, bit pointer jumps past memory*/
}
+ if(max_output_size && out->size > max_output_size) {
+ ERROR_BREAK(109); /*error, larger than max size*/
+ }
}
HuffmanTree_cleanup(&tree_ll);
@@ -1373,8 +1368,11 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
- lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
- bytepos += LEN;
+ /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
+ if (LEN) {
+ lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
+ bytepos += LEN;
+ }
reader->bp = bytepos << 3u;
@@ -1392,15 +1390,16 @@ static unsigned lodepng_inflatev(ucvector* out,
while(!BFINAL) {
unsigned BTYPE;
- if(!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/
+ if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/
+ ensureBits9(&reader, 3);
BFINAL = readBits(&reader, 1);
BTYPE = readBits(&reader, 2);
if(BTYPE == 3) return 20; /*error: invalid BTYPE*/
else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/
- else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/
-
- if(error) return error;
+ else error = inflateHuffmanBlock(out, &reader, BTYPE, settings->max_output_size); /*compression, BTYPE 01 or 10*/
+ if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ if(error) break;
}
return error;
@@ -1421,6 +1420,12 @@ static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize,
if(settings->custom_inflate) {
unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings);
out->allocsize = out->size;
+ if(error) {
+ /*the custom inflate is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ }
return error;
} else {
return lodepng_inflatev(out, in, insize, settings);
@@ -2116,7 +2121,9 @@ static unsigned deflate(unsigned char** out, size_t* outsize,
const unsigned char* in, size_t insize,
const LodePNGCompressSettings* settings) {
if(settings->custom_deflate) {
- return settings->custom_deflate(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_deflate(out, outsize, in, insize, settings);
+ /*the custom deflate is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_deflate(out, outsize, in, insize, settings);
}
@@ -2213,10 +2220,16 @@ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const uns
/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
+ unsigned error;
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ error = settings->custom_zlib(out, outsize, in, insize, settings);
+ if(error) {
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
+ }
} else {
- unsigned error;
ucvector v = ucvector_init(*out, *outsize);
if(expected_size) {
/*reserve the memory to avoid intermediate reallocations*/
@@ -2226,8 +2239,8 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t exp
error = lodepng_zlib_decompressv(&v, in, insize, settings);
*out = v.data;
*outsize = v.size;
- return error;
}
+ return error;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2275,7 +2288,9 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in,
size_t insize, const LodePNGCompressSettings* settings) {
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_zlib(out, outsize, in, insize, settings);
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_zlib_compress(out, outsize, in, insize, settings);
}
@@ -2334,13 +2349,14 @@ const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT
void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) {
settings->ignore_adler32 = 0;
settings->ignore_nlen = 0;
+ settings->max_output_size = 0;
settings->custom_zlib = 0;
settings->custom_inflate = 0;
settings->custom_context = 0;
}
-const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0};
+const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0, 0};
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2357,7 +2373,7 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
/* ////////////////////////////////////////////////////////////////////////// */
-#ifndef LODEPNG_NO_COMPILE_CRC
+#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
@@ -2403,9 +2419,11 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) {
}
return r ^ 0xffffffffu;
}
-#else /* !LODEPNG_NO_COMPILE_CRC */
+#else /* LODEPNG_COMPILE_CRC */
+/*in this case, the function is only declared here, and must be defined externally
+so that it will be linked in*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
-#endif /* !LODEPNG_NO_COMPILE_CRC */
+#endif /* LODEPNG_COMPILE_CRC */
/* ////////////////////////////////////////////////////////////////////////// */
/* / Reading and writing PNG color channel bits / */
@@ -2443,7 +2461,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream,
/* ////////////////////////////////////////////////////////////////////////// */
unsigned lodepng_chunk_length(const unsigned char* chunk) {
- return lodepng_read32bitInt(&chunk[0]);
+ return lodepng_read32bitInt(chunk);
}
void lodepng_chunk_type(char type[5], const unsigned char* chunk) {
@@ -2493,34 +2511,32 @@ void lodepng_chunk_generate_crc(unsigned char* chunk) {
}
unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- const unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
@@ -2872,8 +2888,8 @@ static void LodePNGText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->text_keys = 0;
- dest->text_strings = 0;
+ dest->text_keys = NULL;
+ dest->text_strings = NULL;
dest->text_num = 0;
for(i = 0; i != source->text_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i]));
@@ -2932,10 +2948,10 @@ static void LodePNGIText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->itext_keys = 0;
- dest->itext_langtags = 0;
- dest->itext_transkeys = 0;
- dest->itext_strings = 0;
+ dest->itext_keys = NULL;
+ dest->itext_langtags = NULL;
+ dest->itext_transkeys = NULL;
+ dest->itext_strings = NULL;
dest->itext_num = 0;
for(i = 0; i != source->itext_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i],
@@ -3030,6 +3046,9 @@ void lodepng_info_init(LodePNGInfo* info) {
info->iccp_name = NULL;
info->iccp_profile = NULL;
+ info->sbit_defined = 0;
+ info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0;
+
LodePNGUnknownChunks_init(info);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
}
@@ -3924,7 +3943,7 @@ static unsigned auto_choose_color(LodePNGColorMode* mode_out,
if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize
&& mode_in->bitdepth == mode_out->bitdepth) {
/*If input should have same palette colors, keep original to preserve its order and prevent conversion*/
- lodepng_color_mode_cleanup(mode_out);
+ lodepng_color_mode_cleanup(mode_out); /*clears palette, keeps the above set colortype and bitdepth fields as-is*/
lodepng_color_mode_copy(mode_out, mode_in);
}
} else /*8-bit or 16-bit per channel*/ {
@@ -4093,10 +4112,12 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
case 0:
for(i = 0; i != length; ++i) recon[i] = scanline[i];
break;
- case 1:
+ case 1: {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth];
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + recon[j];
break;
+ }
case 2:
if(precon) {
for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i];
@@ -4106,24 +4127,56 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
break;
case 3:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u);
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u);
+ /* Unroll independent paths of this predictor. A 6x and 8x version is also possible but that adds
+ too much code. Whether this speeds up anything depends on compiler and settings. */
+ if(bytewidth >= 4) {
+ for(; i + 3 < length; i += 4, j += 4) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ recon[i + 3] = s3 + ((r3 + p3) >> 1u);
+ }
+ } else if(bytewidth >= 3) {
+ for(; i + 2 < length; i += 3, j += 3) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ }
+ } else if(bytewidth >= 2) {
+ for(; i + 1 < length; i += 2, j += 2) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ }
+ }
+ for(; i != length; ++i, ++j) recon[i] = scanline[i] + ((recon[j] + precon[i]) >> 1u);
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u);
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + (recon[j] >> 1u);
}
break;
case 4:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
- /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that
- adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */
+ /* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that
+ adds too much code. Whether this speeds up anything depends on compiler and settings. */
if(bytewidth >= 4) {
- for(; i + 3 < length; i += 4) {
- size_t j = i - bytewidth;
+ for(; i + 3 < length; i += 4, j += 4) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
@@ -4134,8 +4187,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 3] = s3 + paethPredictor(r3, p3, q3);
}
} else if(bytewidth >= 3) {
- for(; i + 2 < length; i += 3) {
- size_t j = i - bytewidth;
+ for(; i + 2 < length; i += 3, j += 3) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
@@ -4145,8 +4197,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
}
} else if(bytewidth >= 2) {
- for(; i + 1 < length; i += 2) {
- size_t j = i - bytewidth;
+ for(; i + 1 < length; i += 2, j += 2) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
@@ -4156,16 +4207,17 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
}
}
- for(; i != length; ++i) {
- recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
+ for(; i != length; ++i, ++j) {
+ recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j]));
}
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = scanline[i];
}
- for(i = bytewidth; i < length; ++i) {
+ for(i = bytewidth; i != length; ++i, ++j) {
/*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
- recon[i] = (scanline[i] + recon[i - bytewidth]);
+ recon[i] = (scanline[i] + recon[j]);
}
}
break;
@@ -4447,10 +4499,13 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
}
/*compressed text chunk (zTXt)*/
-static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, string2_begin;
char *key = 0;
unsigned char* str = 0;
@@ -4473,12 +4528,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(error) break;
error = lodepng_add_text_sized(info, key, (char*)str, size);
-
break;
}
@@ -4489,11 +4546,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
}
/*international text chunk (iTXt)*/
-static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, begin, compressed;
char *key = 0, *langtag = 0, *transkey = 0;
@@ -4550,9 +4610,12 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(compressed) {
unsigned char* str = 0;
size_t size = 0;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
lodepng_free(str);
} else {
@@ -4628,11 +4691,13 @@ static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, siz
return 0; /* OK */
}
-static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
size_t size = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
unsigned length, string2_begin;
@@ -4655,13 +4720,57 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_icc_size;
error = zlib_decompress(&info->iccp_profile, &size, 0,
&data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: ICC profile larger than decoder->max_icc_size*/
+ if(error && size > zlibsettings.max_output_size) error = 113;
info->iccp_profile_size = size;
if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
return error;
}
+
+/*significant bits chunk (sBIT)*/
+static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ if(info->color.colortype == LCT_GREY) {
+ /*error: this chunk must be 1 bytes for grayscale image*/
+ if(chunkLength != 1) return 114;
+ if(data[0] == 0 || data[0] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ /*error: this chunk must be 3 bytes for RGB and palette image*/
+ if(chunkLength != 3) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ /*error: this chunk must be 2 byte for grayscale with alpha image*/
+ if(chunkLength != 2) return 114;
+ if(data[0] == 0 || data[1] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ info->sbit_a = data[1];
+ } else if(info->color.colortype == LCT_RGBA) {
+ /*error: this chunk must be 4 bytes for grayscale image*/
+ if(chunkLength != 4) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ info->sbit_a = data[3];
+ }
+
+ return 0; /* OK */
+}
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
@@ -4676,7 +4785,7 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
chunkLength = lodepng_chunk_length(chunk);
if(chunkLength > 2147483647) return 63;
data = lodepng_chunk_data_const(chunk);
- if(data + chunkLength + 4 > in + insize) return 30;
+ if(chunkLength + 12 > insize - pos) return 30;
if(lodepng_chunk_type_equals(chunk, "PLTE")) {
error = readChunk_PLTE(&state->info_png.color, data, chunkLength);
@@ -4688,9 +4797,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "tEXt")) {
error = readChunk_tEXt(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
- error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
- error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
error = readChunk_tIME(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "pHYs")) {
@@ -4702,7 +4811,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "sRGB")) {
error = readChunk_sRGB(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ error = readChunk_sBIT(&state->info_png, data, chunkLength);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else {
/* unhandled chunk is ok (is not an error) */
@@ -4721,7 +4832,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
LodePNGState* state,
const unsigned char* in, size_t insize) {
unsigned char IEND = 0;
- const unsigned char* chunk;
+ const unsigned char* chunk; /*points to beginning of next chunk*/
unsigned char* idat; /*the data from idat chunks, zlib compressed*/
size_t idatsize = 0;
unsigned char* scanlines = 0;
@@ -4757,14 +4868,15 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
while(!IEND && !state->error) {
unsigned chunkLength;
const unsigned char* data; /*the data in the chunk*/
+ size_t pos = (size_t)(chunk - in);
- /*error: size of the in buffer too small to contain next chunk*/
- if((size_t)((chunk - in) + 12) > insize || chunk < in) {
+ /*error: next chunk out of bounds of the in buffer*/
+ if(chunk < in || pos + 12 > insize) {
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 30);
}
- /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
+ /*length of the data of the chunk, excluding the 12 bytes for length, chunk type and CRC*/
chunkLength = lodepng_chunk_length(chunk);
/*error: chunk length larger than the max PNG chunk size*/
if(chunkLength > 2147483647) {
@@ -4772,8 +4884,8 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
CERROR_BREAK(state->error, 63);
}
- if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) {
- CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
+ if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) {
+ CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk (or int overflow)*/
}
data = lodepng_chunk_data_const(chunk);
@@ -4820,13 +4932,13 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
/*compressed text chunk (zTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
/*international text chunk (iTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
@@ -4845,7 +4957,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
state->error = readChunk_sRGB(&state->info_png, data, chunkLength);
if(state->error) break;
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- state->error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ if(state->error) break;
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ state->error = readChunk_sBIT(&state->info_png, data, chunkLength);
if(state->error) break;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else /*it's not an implemented chunk type, so ignore it: skip over the data*/ {
@@ -4871,7 +4986,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize);
}
- if(state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
+ if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */
}
@@ -4955,6 +5070,11 @@ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, co
lodepng_state_init(&state);
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*disable reading things that this function doesn't output*/
+ state.decoder.read_text_chunks = 0;
+ state.decoder.remember_unknown_chunks = 0;
+#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
error = lodepng_decode(out, w, h, &state, in, insize);
lodepng_state_cleanup(&state);
return error;
@@ -4997,6 +5117,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
settings->read_text_chunks = 1;
settings->remember_unknown_chunks = 0;
+ settings->max_text_size = 16777216;
+ settings->max_icc_size = 16777216; /* 16MB is much more than enough for any reasonable ICC profile */
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
settings->ignore_crc = 0;
settings->ignore_critical = 0;
@@ -5075,6 +5197,10 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) {
unsigned char* chunk;
size_t i, j = 8;
+ if(info->palettesize == 0 || info->palettesize > 256) {
+ return 68; /*invalid palette size, it is only allowed to be 1-256*/
+ }
+
CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE"));
for(i = 0; i != info->palettesize; ++i) {
@@ -5330,6 +5456,42 @@ static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCom
return error;
}
+static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ unsigned char* chunk = 0;
+ if(info->color.colortype == LCT_GREY) {
+ if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT"));
+ chunk[8] = info->sbit_r;
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ if(info->sbit_r == 0 || info->sbit_a == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_a;
+ } else if(info->color.colortype == LCT_RGBA) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 ||
+ info->sbit_r > bitdepth || info->sbit_g > bitdepth ||
+ info->sbit_b > bitdepth || info->sbit_a > bitdepth) {
+ return 115;
+ }
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ chunk[11] = info->sbit_a;
+ }
+ if(chunk) lodepng_chunk_generate_crc(chunk);
+ return 0;
+}
+
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline,
@@ -5775,8 +5937,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
ucvector outv = ucvector_init(NULL, 0);
LodePNGInfo info;
const LodePNGInfo* info_png = &state->info_png;
+ LodePNGColorMode auto_color;
lodepng_info_init(&info);
+ lodepng_color_mode_init(&auto_color);
/*provide some proper output values if error will happen*/
*out = 0;
@@ -5786,6 +5950,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*check input values validity*/
if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
&& (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) {
+ /*this error is returned even if auto_convert is enabled and thus encoder could
+ generate the palette by itself: while allowing this could be possible in theory,
+ it may complicate the code or edge cases, and always requiring to give a palette
+ when setting this color type is a simpler contract*/
state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
goto cleanup;
}
@@ -5806,6 +5974,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
lodepng_info_copy(&info, &state->info_png);
if(state->encoder.auto_convert) {
LodePNGColorStats stats;
+ unsigned allow_convert = 1;
lodepng_color_stats_init(&stats);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined &&
@@ -5827,23 +5996,85 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*the background chunk's color must be taken into account as well*/
unsigned r = 0, g = 0, b = 0;
LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
- lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
+ lodepng_convert_rgb(&r, &g, &b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
state->error = lodepng_color_stats_add(&stats, r, g, b, 65535);
if(state->error) goto cleanup;
}
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
- state->error = auto_choose_color(&info.color, &state->info_raw, &stats);
+ state->error = auto_choose_color(&auto_color, &state->info_raw, &stats);
if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
- /*also convert the background chunk*/
- if(info_png->background_defined) {
- if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
- info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
- state->error = 104;
- goto cleanup;
+ if(info_png->sbit_defined) {
+ /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes,
+ auto_convert can't be done in many cases. However, do support a few cases here.
+ TODO: more conversions may be possible, and it may also be possible to get a more appropriate color type out of
+ auto_choose_color if knowledge about sbit is used beforehand
+ */
+ unsigned sbit_max = LODEPNG_MAX(LODEPNG_MAX(LODEPNG_MAX(info_png->sbit_r, info_png->sbit_g),
+ info_png->sbit_b), info_png->sbit_a);
+ unsigned equal = (!info_png->sbit_g || info_png->sbit_g == info_png->sbit_r)
+ && (!info_png->sbit_b || info_png->sbit_b == info_png->sbit_r)
+ && (!info_png->sbit_a || info_png->sbit_a == info_png->sbit_r);
+ allow_convert = 0;
+ if(info.color.colortype == LCT_PALETTE &&
+ auto_color.colortype == LCT_PALETTE) {
+ /* input and output are palette, and in this case it may happen that palette data is
+ expected to be copied from info_raw into the info_png */
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGB to palette (or 16-bit as long as sbit_max <= 8) is possible
+ since both are 8-bit RGB for sBIT's purposes*/
+ if(info.color.colortype == LCT_RGB &&
+ auto_color.colortype == LCT_PALETTE && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/
+ if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE &&
+ info_png->sbit_a == 8 && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/
+ if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth == 16 &&
+ auto_color.colortype == info.color.colortype && auto_color.bitdepth == 8 &&
+ sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going to less channels is ok if all bit values are equal (all possible values in sbit,
+ as well as the chosen bitdepth of the result). Due to how auto_convert works,
+ we already know that auto_color.colortype has less than or equal amount of channels than
+ info.colortype. Palette is not used here. This conversion is not allowed if
+ info_png->sbit_r < auto_color.bitdepth, because specifically for alpha, non-presence of
+ an sbit value heavily implies that alpha's bit depth is equal to the PNG bit depth (rather
+ than the bit depths set in the r, g and b sbit values, by how the PNG specification describes
+ handling tRNS chunk case with sBIT), so be conservative here about ignoring user input.*/
+ if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE &&
+ equal && info_png->sbit_r == auto_color.bitdepth) {
+ allow_convert = 1;
}
}
+#endif
+ if(state->encoder.force_palette) {
+ if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
+ (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
+ /*user speficially forced a PLTE palette, so cannot convert to grayscale types because
+ the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
+ allow_convert = 0;
+ }
+ }
+ if(allow_convert) {
+ lodepng_color_mode_copy(&info.color, &auto_color);
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*also convert the background chunk*/
+ if(info_png->background_defined) {
+ if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
+ state->error = 104;
+ goto cleanup;
+ }
+ }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+ }
}
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined) {
@@ -5914,6 +6145,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
state->error = addChunk_cHRM(&outv, &info);
if(state->error) goto cleanup;
}
+ if(info_png->sbit_defined) {
+ state->error = addChunk_sBIT(&outv, &info);
+ if(state->error) goto cleanup;
+ }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
/*PLTE*/
if(info.color.colortype == LCT_PALETTE) {
@@ -6020,6 +6255,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
cleanup:
lodepng_info_cleanup(&info);
lodepng_free(data);
+ lodepng_color_mode_cleanup(&auto_color);
/*instead of cleaning the vector up, give it to the output*/
*out = outv.data;
@@ -6204,6 +6440,18 @@ const char* lodepng_error_text(unsigned code) {
case 106: return "PNG file must have PLTE chunk if color type is palette";
case 107: return "color convert from palette mode requested without setting the palette data in it";
case 108: return "tried to add more than 256 values to a palette";
+ /*this limit can be configured in LodePNGDecompressSettings*/
+ case 109: return "tried to decompress zlib or deflate data larger than desired max_output_size";
+ case 110: return "custom zlib or inflate decompression failed";
+ case 111: return "custom zlib or deflate compression failed";
+ /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large text sizes.*/
+ case 112: return "compressed text unreasonably large";
+ /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large ICC profile*/
+ case 113: return "ICC profile unreasonably large";
+ case 114: return "sBIT chunk has wrong size for the color type of the image";
+ case 115: return "sBIT value out of range";
}
return "unknown error code";
}
@@ -6240,7 +6488,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si
size_t buffersize = 0;
unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6259,7 +6507,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size
size_t buffersize = 0;
unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6304,7 +6552,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6322,7 +6570,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize);
if(buffer && !error) {
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6354,7 +6602,7 @@ unsigned encode(std::vector& out, const unsigned char* in, unsign
size_t buffersize;
unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6374,7 +6622,7 @@ unsigned encode(std::vector& out,
size_t buffersize;
unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
diff --git a/Tools/NGN_Tilemap/source/lodepng/lodepng.h b/Tools/NGN_Tilemap/source/lodepng/lodepng.h
index a386459..fdafc77 100644
--- a/Tools/NGN_Tilemap/source/lodepng/lodepng.h
+++ b/Tools/NGN_Tilemap/source/lodepng/lodepng.h
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
@@ -142,16 +161,24 @@ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,
/*
Load PNG from disk, from file with given name.
Same as the other decode functions, but instead takes a filename as input.
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
-/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/
+/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.*/
unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,
const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -191,17 +218,26 @@ unsigned lodepng_encode24(unsigned char** out, size_t* outsize,
/*
Converts raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
-*/
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h,
LodePNGColorType colortype, unsigned bitdepth);
-/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode32_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
-/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/
+/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory.*/
unsigned lodepng_encode24_file(const char* filename,
const unsigned char* image, unsigned w, unsigned h);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -223,6 +259,9 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
/*
Converts PNG file from disk to raw pixel data in memory.
Same as the other decode functions, but instead takes a filename as input.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned decode(std::vector& out, unsigned& w, unsigned& h,
const std::string& filename,
@@ -243,7 +282,11 @@ unsigned encode(std::vector& out,
/*
Converts 32-bit RGBA raw pixel data into a PNG file on disk.
Same as the other encode functions, but instead takes a filename as output.
+
NOTE: This overwrites existing files without warning!
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned encode(const std::string& filename,
const unsigned char* in, unsigned w, unsigned h,
@@ -270,12 +313,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -341,8 +393,10 @@ typedef struct LodePNGColorMode {
The alpha channels must be set as well, set them to 255 for opaque images.
- When decoding, by default you can ignore this palette, since LodePNG already
- fills the palette colors in the pixels of the raw RGBA output.
+ When decoding, with the default settings you can ignore this palette, since
+ LodePNG already fills the palette colors in the pixels of the raw RGBA output,
+ but when decoding to the original PNG color mode it is needed to reconstruct
+ the colors.
The palette is only supported for color type 3.
*/
@@ -432,10 +486,12 @@ typedef struct LodePNGInfo {
with values truncated to the bit depth in the unsigned integer.
For grayscale and palette PNGs, the value is stored in background_r. The values
- in background_g and background_b are then unused.
+ in background_g and background_b are then unused. The decoder will set them
+ equal to background_r, the encoder ignores them in this case.
- So when decoding, you may get these in a different color mode than the one you requested
- for the raw pixels.
+ When decoding, you may get these in a different color mode than the one you requested
+ for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the
+ ones defined in the header of the PNG image, are used.
When encoding with auto_convert, you must use the color model defined in info_png.color for
these values. The encoder normally ignores info_png.color when auto_convert is on, but will
@@ -454,30 +510,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -496,7 +558,7 @@ typedef struct LodePNGInfo {
unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
/*
- Color profile related chunks: gAMA, cHRM, sRGB, iCPP
+ Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
@@ -559,6 +621,45 @@ typedef struct LodePNGInfo {
unsigned char* iccp_profile;
unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+ /*
+ sBIT chunk: significant bits. Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+ sample depth, such as 10 or 12.
+
+ Encoders using this value, when storing the pixel data, should use the most significant bits
+ of the data to store the original bits, and use a good sample depth scaling method such as
+ "left bit replication" to fill in the least significant bits, rather than fill zeroes.
+
+ Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right
+ shift the data to go back to the original bit depth, but decoders are also allowed to ignore
+ sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks
+ to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.
+
+ For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color
+ type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with
+ translucent palette values, or images with color key). The values that are used must be
+ greater than zero and smaller than or equal to the PNG bit depth.
+
+ The color type from the header in the PNG image defines these used and unused fields: if
+ decoding with a color mode conversion, such as always decoding to RGBA, this metadata still
+ only uses the color type of the original PNG, and may e.g. lack the alpha channel info
+ if the PNG was RGB. When encoding with auto_convert (as well as without), also always the
+ color model defined in info_png.color determines this.
+
+ NOTE: enabling sbit can hurt compression, because the encoder can then not always use
+ auto_convert to choose a more optimal color mode for the data, because the PNG format has
+ strict requirements for the allowed sbit values in combination with color modes.
+ For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel
+ color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.
+ */
+ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/
+ unsigned sbit_r; /*red or gray component of significant bits*/
+ unsigned sbit_g; /*green component of significant bits*/
+ unsigned sbit_b; /*blue component of significant bits*/
+ unsigned sbit_a; /*alpha component of significant bits*/
+
/* End of color profile related chunks */
@@ -639,8 +740,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -720,7 +832,11 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
- If colortype is 3, PLTE is _always_ created.*/
+ If colortype is 3, PLTE is always created. If color type is explicitely set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+ optimal color mode, because it cannot use grayscale color modes in this case*/
unsigned force_palette;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
/*add LodePNG identifier and version as a text chunk, for debugging*/
@@ -774,8 +890,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h,
#endif /*LODEPNG_COMPILE_DECODER*/
/*
-Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it
-read in the state. Returns error code on failure.
+Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)
+of the PNG file and outputs what it read in the state. Returns error code on failure.
Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const
to find the desired chunk type, and if non null use lodepng_inspect_chunk (with
chunk_pointer - start_of_file as pos).
@@ -950,6 +1066,9 @@ out: output parameter, contains pointer to loaded buffer.
outsize: output parameter, size of the allocated out buffer
filename: the path to the file to load
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory.
*/
unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);
@@ -960,6 +1079,9 @@ buffer: the buffer to write
buffersize: size of the buffer to write
filename: the path to the file to save to
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/
@@ -1000,12 +1122,18 @@ unsigned encode(std::vector& out,
/*
Load a file from disk into an std::vector.
return value: error code (0 means ok)
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and decode in-memory
*/
unsigned load_file(std::vector& buffer, const std::string& filename);
/*
Save the binary data in an std::vector to a file on disk. The file is overwritten
without warning.
+
+NOTE: Wide-character filenames are not supported, you can use an external method
+to handle such files and encode in-memory
*/
unsigned save_file(const std::vector& buffer, const std::string& filename);
#endif /* LODEPNG_COMPILE_DISK */
@@ -1041,7 +1169,7 @@ unsigned compress(std::vector& out, const std::vector (2^31)-1
[ ] partial decoding (stream processing)
[X] let the "isFullyOpaque" function check color keys and transparent palettes too
@@ -1168,18 +1296,16 @@ The following features are supported by the decoder:
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
+ sBIT: significant bits
1.2. features not supported
---------------------------
-The following features are _not_ supported:
+The following features are not (yet) supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
-*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
- sBIT
- hIST
- sPLT
+*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks
2. C and C++ version
@@ -1505,6 +1631,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1678,6 +1809,9 @@ try to fix it if the compiler is modern and standards compliant.
This decoder example shows the most basic usage of LodePNG. More complex
examples can be found on the LodePNG website.
+NOTE: these examples do not support wide-character filenames, you can use an
+external method to handle such files and encode or decode in-memory
+
10.1. decoder C++ example
-------------------------
@@ -1775,6 +1909,12 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 13 jun 2022: added support for the sBIT chunk.
+*) 09 jan 2022: minor decoder speed improvements.
+*) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.
@@ -1941,5 +2081,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
*/
diff --git a/Tools/NGN_Tilemap/source/main.cpp b/Tools/NGN_Tilemap/source/main.cpp
index ec6fece..6ecdad8 100644
--- a/Tools/NGN_Tilemap/source/main.cpp
+++ b/Tools/NGN_Tilemap/source/main.cpp
@@ -1,15 +1,15 @@
/******************************************************************************
- N'gine Lib for C++
- Conversor de PNG a TILES + MAP
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Archivo principal -
Proyecto iniciado el 11 de Febrero del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
https://nightfoxandco.com
contact@nightfoxandco.com
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
http://lodev.org/lodepng/
******************************************************************************/
@@ -22,190 +22,29 @@
#include
#include
#include
-#include
-// LodePNG
-#include "lodepng/lodepng.h"
+// Programa
+#include "tile_map.h"
+#include "defines.h"
-// Tielmap
-#include "tilemap.h"
+/*** Main ***/
+int32_t main(int32_t argc, char* args[]) {
-/*** Version de N'gine ***/
-static const int32_t NGN_VERSION_MAJOR = 1; // Version mayor
-static const int32_t NGN_VERSION_MINOR = 0; // Version menor
-static const int32_t NGN_VERSION_PATCH = 0; // Version parche
-static const std::string NGN_VERSION_METADATA = "stable"; // Version metadatos
-/*** Version del programa ***/
-static const int32_t PROGRAM_VERSION_MAJOR = 1; // Version mayor
-static const int32_t PROGRAM_VERSION_MINOR = 0; // Version menor
-static const int32_t PROGRAM_VERSION_PATCH = 2; // Version parche
-static const std::string PROGRAM_VERSION_METADATA = "stable"; // Version metadatos
-
-
-
-/*** Mensages de error ***/
-void ErrorMsg() {
- std::cout << "Command line error." << std::endl;
- std::cout << "Usage: NGN_Tilemap INPUT_FILE.PNG [-o filename] [-ts xx] [-l x] [-ef]" << std::endl;
- std::cout << "-o filename Name for the output file, without extension (.tbg will be added automaticaly)." << std::endl;
- std::cout << "-ts xx Size of the squared tile in pixels (From 8 to 1024, 32 pixels by default)." << std::endl;
- std::cout << "-lv x Optimization level [1] Duplicates [2] Flips (Default) [3] Rotations" << std::endl;
- std::cout << "-ef Generates extra files with the tileset in PNG and the map in binary formats." << std::endl << std::endl;
-}
-
-
+ // Crea el objeto principal del programa
+ TileMap* tm = new TileMap(argc, args);
+ // Si no se crea con exito, sal del programa
+ if (!tm) return ERR_CODE_BOOTFAILURE;
-/*** Main ***/
-int32_t main(int32_t argc, char* args[]) {
+ // Transfiere el control del objeto principal
+ int32_t r = tm->Run();
- // Variables
- std::string in_file = ""; // Nombre del archivo de entrada
- std::string out_file = ""; // Nombre base de los archivos de salida
- uint32_t ts = 32; // Tamaño del tile
- uint32_t lv = 2; // Nivel de optimizacion
- bool ef = false; // Generar archivos extra?
-
- // Variables de control
- bool _filename = false;
- bool _ts = false;
- bool _lv = false;
- bool _ef = false;
- bool _err = false;
-
- // Texto de bienvenida
- std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
- std::cout <<
- std::endl << "N'gine PNG to TiledBG converter. (v" << program_version << ")." <<
- std::endl << "For N'gine Version " << ngn_version << " or higher." <<
- std::endl << "(cc) 2016 - 2022 by Cesar Rincon." <<
- std::endl << "https://nightfoxandco.com" <<
- std::endl << "contact@nightfoxandco.com" <<
- std::endl << std::endl;
-
- // Verifica la linea de comandos
- if ((argc < 2) || (argc > 10)) { // Nº de argumentos incorrecto
-
- ErrorMsg();
- return 1;
-
- } else { // Analiza los argumentos extra
-
- // Archivo de entrada
- in_file = args[1];
- if ((in_file.length() < 5) || (in_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
-
- for (int32_t i = 2; i < argc; i ++) {
- _err = true;
- if (strcmp(args[i], "-o") == 0) { // Comando -O
- if (((i + 1) < argc) && !_filename) {
- _filename = true;
- _err = false;
- out_file = args[(i + 1)];
- i ++;
- if ((out_file.length() < 1) || (out_file.length() > 240)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-ts") == 0) { // Comando -TS
- if (((i + 1) < argc) && !_ts) {
- _ts = true;
- _err = false;
- ts = atoi(args[(i + 1)]);
- i ++;
- if ((ts < 8) || (ts > 1024)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-lv") == 0) { // Comando -LV
- if (((i + 1) < argc) && !_lv) {
- _lv = true;
- _err = false;
- lv = atoi(args[(i + 1)]);
- i ++;
- if ((lv < 1) || (lv > 3)) {
- ErrorMsg();
- return 1;
- }
- } else {
- ErrorMsg();
- return 1;
- }
- } else if (strcmp(args[i], "-ef") == 0) { // Comando -EF
- if (!_ef) {
- ef = _ef = true;
- _err = false;
- } else {
- ErrorMsg();
- return 1;
- }
- }
-
- }
- // Error de uso incorrecto de argumentos
- if (_err) {
- ErrorMsg();
- return 1;
- }
- }
- std::cout << std::endl;
-
- // Nombre del archivo de salida
- if (out_file == "") out_file = in_file.substr(0, (in_file.length() - 4));
-
- // Crea el objeto de la libreria
- PngToTiles* tm = new PngToTiles();
-
- // Aplica los parametros por defecto
- tm->input_filename = in_file;
- tm->output_filename = out_file;
- tm->size_of_tile = ts;
- tm->optimize = lv;
- tm->extra_files = ef;
-
- // Informacion de los parametros introducidos
- std::cout << "Output filename: " << tm->output_filename << ".tbg" << std::endl;
- std::cout << "Tile size: " << tm->size_of_tile << "x" << tm->size_of_tile << " pixels." << std::endl;
- std::cout << "Optimization level: ";
- switch (tm->optimize) {
- case 1:
- std::cout << "Only duplicates." << std::endl;
- break;
- case 2:
- std::cout << "Duplicates & flips." << std::endl;
- break;
- case 3:
- std::cout << "Duplicates, flips & rotations." << std::endl;
- break;
- }
- std::cout << "Generation of extra files ";
- if (tm->extra_files) {
- std::cout << "enabled." << std::endl;
- } else {
- std::cout << "disabled." << std::endl;
- }
- std::cout << std::endl;
-
- // Convierte la imagen solicitada
- tm->ConvertPng();
-
- // Elimina la instancia
+ // Elimina el objeto principal
delete tm;
- return 0;
+ // Devuelve el resultado de ejecucion del programa
+ return r;
}
diff --git a/Tools/NGN_Tilemap/source/message.cpp b/Tools/NGN_Tilemap/source/message.cpp
new file mode 100644
index 0000000..5b360a4
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/message.cpp
@@ -0,0 +1,106 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+
+// Includes del proyecto
+#include "message.h"
+#include "defines.h"
+
+
+
+/*** Constructor ***/
+Message::Message(std::string pname) {
+
+ // Guarda el nombre del ejecutable del programa
+ program_name = pname;
+
+}
+
+
+
+/*** Destructor ***/
+Message::~Message() {
+
+}
+
+
+
+/*** Texto de encabezado de la aplicacion ***/
+void Message::AppHeader() {
+
+ // Genera las cadenas de texto adicionales
+ std::string ngn_version = std::to_string(NGN_VERSION_MAJOR) + "." + std::to_string(NGN_VERSION_MINOR) + "." + std::to_string(NGN_VERSION_PATCH) + "-" + NGN_VERSION_METADATA;
+ std::string program_version = std::to_string(PROGRAM_VERSION_MAJOR) + "." + std::to_string(PROGRAM_VERSION_MINOR) + "." + std::to_string(PROGRAM_VERSION_PATCH) + "-" + PROGRAM_VERSION_METADATA;
+
+ // Imprime el texto
+ std::cout <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl <<
+ std::endl << " " << PROGRAM_NAME << ". (v" << program_version << ")." <<
+ std::endl << " For N'gine Version " << ngn_version << " or higher." <<
+ std::endl << " (cc) " << CC_YEARS << " by Cesar Rincon." <<
+ std::endl << " https://nightfoxandco.com" <<
+ std::endl << " contact@nightfoxandco.com" <<
+ std::endl <<
+ std::endl << TEXT_DASHED_LINE <<
+ std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Como obtener ayuda" ***/
+void Message::QuestionMarkForHelp() {
+
+ std::cout << "Type " << program_name << " " << ARG_HELP << " to display the on-screen help manual." << std::endl << std::endl;
+
+}
+
+
+
+/*** Texto "Error de uso" ***/
+void Message::UseError() {
+
+ std::cout << "Command line error." << std::endl;
+
+}
+
+
+
+/*** Texto "Manual de uso" ***/
+void Message::UserManual() {
+
+ std::cout << std::endl;
+ std::cout << program_name << " INPUT_FILE.PNG [" << ARG_OUT_FILE << " filename] [" << ARG_TILE_SIZE << " xxxx] [" << ARG_OP_LEVEL << " x] [" << ARG_EXTRA_FILES << "]" << std::endl;
+ std::cout << std::endl;
+ std::cout << ARG_HELP << " Displays the on-screen user manual (this screen)." << std::endl;
+ std::cout << ARG_OUT_FILE << " Name for the output file, without extension (" << TBG_EXTENSION << " will be added automaticaly)." << std::endl;
+ std::cout << ARG_TILE_SIZE << " Size of the squared tile in pixels (From [" << MIN_TILE_SIZE << "] to [" << MAX_TILE_SIZE << "], " << DEFAULT_TILE_SIZE << " pixels by default)." << std::endl;
+ std::cout << ARG_OP_LEVEL << " Optimization level ([1] Duplicates [2] Flips (Default) [3] Rotations)." << std::endl;
+ std::cout << ARG_EXTRA_FILES << " Generates the extra files with the tileset in PNG and the map in binary format." << std::endl;
+ std::cout << std::endl;
+
+}
diff --git a/Tools/NGN_Tilemap/source/message.h b/Tools/NGN_Tilemap/source/message.h
new file mode 100644
index 0000000..2f2fe2d
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/message.h
@@ -0,0 +1,67 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Sistema de mensages -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef MESSAGE_H_INCLUDED
+#define MESSAGE_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+
+
+
+/*** Declaracion de la clase ***/
+class Message {
+
+ public:
+
+ // Constructor
+ Message(std::string pname);
+
+ // Destructor
+ ~Message();
+
+ /*** Propiedades ***/
+
+
+ /*** Metodos ***/
+ void AppHeader(); // Texto de cabecera de la aplicacion
+ void QuestionMarkForHelp(); // -? para mostrar la ayuda
+ void UseError(); // Error del uso
+ void UserManual(); // Manual del usuario
+
+
+ private:
+
+ /*** Propiedades ***/
+ std::string program_name; // Nombre del archivo ejecutable
+
+
+
+ /*** Metodos ***/
+
+};
+
+
+
+#endif // MESSAGE_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/source/tile_map.cpp b/Tools/NGN_Tilemap/source/tile_map.cpp
new file mode 100644
index 0000000..6ffb9bf
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/tile_map.cpp
@@ -0,0 +1,324 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Nucleo del programa -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+/*** Includes ***/
+
+// C++
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+// Includes del proyecto
+#include "tile_map.h"
+#include "defines.h"
+#include "message.h"
+#include "convert_to_tiles.h"
+
+
+
+
+/*** Constructor ***/
+TileMap::TileMap(int32_t argc, char* args[]) {
+
+
+ // Guarda el numero de argumentos
+ argument_count = argc;
+
+ // General al lista de argumentos
+ argument_list.clear();
+ argument_list.resize(argument_count);
+ for (int32_t i = 0; i < argument_count; i ++) argument_list[i] = args[i];
+
+ // Parametros
+ parameter.in_file = "";
+ parameter.out_file = "";
+ parameter.tile_size = 0;
+ parameter.optimization_level = 0;
+ parameter.generate_extra_files = false;
+
+ // Crea los objetos adicionales
+ msg = new Message(argument_list[0]);
+ fs = new FsManager();
+ png2tiles = new ConvertToTiles();
+
+ // Flags de argumentos
+ arg_help.state = false; arg_help.value = "";
+ arg_in_file.state = false; arg_in_file.value = "";
+ arg_out_file.state = false; arg_out_file.value = "";
+ arg_tile_size.state = false; arg_tile_size.value = "";
+ arg_op_level.state = false; arg_op_level.value = "";
+ arg_extra_files.state = false; arg_extra_files.value = "";
+
+
+}
+
+
+
+/*** Destructor ***/
+TileMap::~TileMap() {
+
+ // Elimina la lista de argumentos
+ argument_list.clear();
+
+ // Elimina los objetos adicionales
+ delete png2tiles; png2tiles = NULL;
+ delete fs; fs = NULL;
+ delete msg; msg = NULL;
+
+}
+
+
+
+/*** Programa principal ***/
+int32_t TileMap::Run() {
+
+ // Resultado de la ejecucion
+ int32_t r = ERR_CODE_OK;
+
+ // Texto de cabecera
+ msg->AppHeader();
+
+ // Analiza la lista de argumentos
+ int32_t arglist = CheckArguments();
+ //DebugArgList();
+
+ // Analisis de los posibles errores en la linea de comandos / peticion de ayuda
+ if (arglist == 0) {
+ // Si no se ha especificado ningun argumento
+ msg->QuestionMarkForHelp();
+ } else if (arglist < 0) {
+ // Uso incorrecto
+ msg->UseError();
+ msg->UserManual();
+ r = ERR_CODE_ARG_INVALID;
+ } else if (arg_help.state) {
+ // Manual en pantalla
+ msg->UserManual();
+ } else {
+ // Valida los parametros de entrada
+ if (ValidateParameters()) {
+ Report();
+ if (
+ !png2tiles->Convert(
+ parameter.in_file,
+ parameter.out_file,
+ parameter.tile_size,
+ parameter.optimization_level,
+ parameter.generate_extra_files
+ )
+ ) r = ERR_CODE_CONVERSION_FAILURE;
+ } else {
+ msg->QuestionMarkForHelp();
+ r = ERR_CODE_ARG_INVALID;
+ }
+ }
+
+ // Resultado de la ejecucion
+ return r;
+
+}
+
+
+
+/*** Analiza la lista de argumentos proporcionados ***/
+int32_t TileMap::CheckArguments() {
+
+ // Si no hay argumentos, muestra el texto de ayuda
+ if (argument_count == 1) return 0;
+
+ // Si el numero de argumentos es incorrecto
+ if ((argument_count < ARG_MIN_NUM) || (argument_count > ARG_MAX_NUM)) return -1;
+
+ // Flag de argumentos validos
+ bool arg = false;
+ bool valid = false;
+
+ // Analiza la lista de argumentos
+ for (uint32_t i = 1; i < argument_list.size(); i ++) {
+
+ valid = false;
+
+ if (argument_list[i] == ARG_HELP) { // Texto de ayuda
+
+ if (arg_help.state) return -1;
+ arg_help.state = true;
+ valid = true;
+
+ } else if (argument_list[i] == ARG_OUT_FILE) { // Archivo de salida
+
+ if (arg_out_file.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_out_file.state = true;
+ i ++;
+ arg_out_file.value = argument_list[i];
+ valid = true;
+
+ } else if (argument_list[i] == ARG_TILE_SIZE) { // Tamaño del tile
+
+ if (arg_tile_size.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_tile_size.state = true;
+ i ++;
+ arg_tile_size.value = argument_list[i];
+ valid = true;
+
+ } else if (argument_list[i] == ARG_OP_LEVEL) { // Nivel de optimizacion
+
+ if (arg_op_level.state) return -1;
+ if ((i + 1) >= argument_list.size()) return -1;
+ arg_op_level.state = true;
+ i ++;
+ arg_op_level.value = argument_list[i];
+ valid = true;
+
+ } else if (argument_list[i] == ARG_EXTRA_FILES) { // Genera archivos adicionales
+
+ if (arg_extra_files.state) return -1;
+ arg_extra_files.state = true;
+ valid = true;
+
+ } else if (i == 1) {
+
+ if (arg_in_file.state) return -1;
+ arg_in_file.state = true;
+ arg_in_file.value = argument_list[i];
+ valid = true;
+
+ }
+
+ // Si el argumento no se reconoce...
+ if (!valid) return -1;
+
+ // Argumento valido?
+ arg |= valid;
+
+ }
+
+ // Indica los argumentos se han leido correctamente
+ return (arg) ? 1:-1;
+
+}
+
+
+
+/*** Valida los parametros de entrada ***/
+bool TileMap::ValidateParameters() {
+
+ // Resultado
+ bool r = true;
+
+ // Verifica si el archivo de origen existe
+ if (!fs->CheckIfFileExist(arg_in_file.value)) {
+ std::cout << arg_in_file.value << " file not found." << std::endl;
+ r = false;
+ } else {
+ parameter.in_file = arg_in_file.value;
+ }
+
+
+ // Nombre base de los archivos de salida
+ if (arg_out_file.state) {
+ parameter.out_file = arg_out_file.value;
+ } else {
+ parameter.out_file = parameter.in_file.substr(0, (parameter.in_file.length() - 4));
+ }
+
+
+ // Tamaño del tile
+ if (arg_tile_size.state) {
+ parameter.tile_size = std::stoi(arg_tile_size.value);
+ if ((parameter.tile_size < MIN_TILE_SIZE) || (parameter.tile_size > MAX_TILE_SIZE)) {
+ std::cout << "Tile size out of range." << std::endl;
+ r = false;
+ }
+ } else {
+ parameter.tile_size = DEFAULT_TILE_SIZE;
+ }
+
+ // Nivel de optimizacion
+ if (arg_op_level.state) {
+ parameter.optimization_level = std::stoi(arg_op_level.value);
+ if ((parameter.optimization_level < 1) || (parameter.optimization_level > 3)) {
+ std::cout << "Optimization level out of range." << std::endl;
+ r = false;
+ }
+ } else {
+ parameter.optimization_level = DEFAULT_OP_LEVEL;
+ }
+
+ // Generacion de archivos adicionales
+ parameter.generate_extra_files = arg_extra_files.state;
+
+ // Parametros validados
+ return r;
+
+}
+
+
+
+/*** Resumen de los datos recopilados ***/
+void TileMap::Report() {
+
+ // Informacion de los parametros introducidos
+ std::cout << "Output filename: " << parameter.out_file << TBG_EXTENSION << std::endl;
+ std::cout << "Tile size: " << parameter.tile_size << "x" << parameter.tile_size << " pixels." << std::endl;
+ std::cout << "Optimization level: ";
+ switch (parameter.optimization_level) {
+ case 1:
+ std::cout << "Only duplicates." << std::endl;
+ break;
+ case 2:
+ std::cout << "Duplicates & flips." << std::endl;
+ break;
+ case 3:
+ std::cout << "Duplicates, flips & rotations." << std::endl;
+ break;
+ }
+ std::cout << "Generation of extra files: ";
+ if (parameter.generate_extra_files) {
+ std::cout << "enabled." << std::endl;
+ } else {
+ std::cout << "disabled." << std::endl;
+ }
+ std::cout << std::endl;
+
+}
+
+
+
+/*** DEBUG: Imprime la lista de argumentos introducidos ***/
+void TileMap::DebugArgList() {
+
+ std::cout << std::endl;
+ std::cout << "Argument list" << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << "Executable name: " << argument_list[0] << std::endl;
+ std::cout << "Input file: " << arg_in_file.state << " " << arg_in_file.value << std::endl;
+ std::cout << ARG_HELP << " " << arg_help.state << " " << arg_help.value << std::endl;
+ std::cout << ARG_OUT_FILE << " " << arg_out_file.state << " " << arg_out_file.value << std::endl;
+ std::cout << ARG_TILE_SIZE << " " << arg_tile_size.state << " " << arg_tile_size.value << std::endl;
+ std::cout << ARG_OP_LEVEL << " " << arg_op_level.state << " " << arg_op_level.value << std::endl;
+ std::cout << ARG_EXTRA_FILES << " " << arg_extra_files.state << " " << arg_extra_files.value << std::endl;
+ std::cout << "----------------------------------------" << std::endl;
+ std::cout << std::endl;
+
+}
diff --git a/Tools/NGN_Tilemap/source/tile_map.h b/Tools/NGN_Tilemap/source/tile_map.h
new file mode 100644
index 0000000..ab9f40c
--- /dev/null
+++ b/Tools/NGN_Tilemap/source/tile_map.h
@@ -0,0 +1,105 @@
+/******************************************************************************
+
+ Conversor de PNG a Fondo de Tiles (.tbg) para N'gine
+ - Nucleo del programa -
+
+ Proyecto iniciado el 11 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+******************************************************************************/
+
+
+
+#ifndef TILE_MAP_H_INCLUDED
+#define TILE_MAP_H_INCLUDED
+
+
+
+/*** Includes ***/
+// C++
+#include
+#include
+// Proyecto
+#include "defines.h"
+#include "message.h"
+#include "fs_manager.h"
+#include "convert_to_tiles.h"
+
+
+
+/*** Declaracion de la clase ***/
+class TileMap {
+
+ public:
+
+ // Constructor
+ TileMap(int32_t argc, char* args[]);
+
+ // Destructor
+ ~TileMap();
+
+ /*** Propiedades ***/
+
+
+
+ /*** Metodos ***/
+ int32_t Run(); // Programa principal
+
+
+ private:
+
+ /*** Propiedades ***/
+
+ // Flags de los argumentos
+ struct argument {
+ bool state;
+ std::string value;
+ };
+ argument arg_help; // Ayuda
+ argument arg_in_file; // Archivo de origen
+ argument arg_out_file; // Archivo de salida
+ argument arg_tile_size; // Tamaño del tile
+ argument arg_op_level; // Nivel de optimizacion
+ argument arg_extra_files; // Generacion de archivos adicionales
+
+
+ // Argumentos introducidos
+ int32_t argument_count; // Numero de argumentos en la linea de comandos
+ std::vector argument_list; // Lista con los argumentos proporcionados
+
+ // Parametros de la conversion
+ struct {
+ std::string in_file; // Archivo de entrada
+ std::string out_file; // Archivo de salida
+ int32_t tile_size; // Tamaño del tile
+ int32_t optimization_level; // Nivel de optimizacion
+ bool generate_extra_files; // Generar archivos extra?
+ } parameter;
+
+
+ /*** Objetos ***/
+ Message* msg; // Gestor de mensages
+ FsManager* fs; // Gestor de archivos del sistema
+ ConvertToTiles* png2tiles; // Conversor de PNG a tiles
+
+
+ /*** Metodos para la lectura de parametros***/
+ int32_t CheckArguments(); // Analiza la lista de argumentos proporcionados
+ bool ValidateParameters(); // Valida los parametros de entrada
+ void Report(); // Resumen de los datos
+
+
+ /*** Metodos de depuracion ***/
+ void DebugArgList(); // Imprime la lista de argumentos introducidos
+
+};
+
+
+
+#endif // TILE_MAP_H_INCLUDED
diff --git a/Tools/NGN_Tilemap/source/tilemap.h b/Tools/NGN_Tilemap/source/tilemap.h
deleted file mode 100644
index 63e2186..0000000
--- a/Tools/NGN_Tilemap/source/tilemap.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/******************************************************************************
-
- N'gine Lib for C++
- Conversor de PNG a TILES + MAP [Funciones]
-
- Proyecto iniciado el 11 de Febrero del 2016
- (cc) 2016 - 2020 by Cesar Rincon "NightFox"
- https://nightfoxandco.com
- contact@nightfoxandco.com
-
- Requiere LodePNG
- (c) 2005 - 2020 by Lode Vandevenne
- http://lodev.org/lodepng/
-
-******************************************************************************/
-
-
-
-#ifndef TILEMAP_H_INCLUDED
-#define TILEMAP_H_INCLUDED
-
-
-/*** Defines ***/
-static const int32_t VERSION = 2; // Version del archivo
-static const std::string MAGIC_STRING = "NGN TILEDBG"; // Magic String
-static const int32_t DEFAULT_TILE_SIZE = 32; // Tamaño por defecto del TILE
-
-
-
-/*** Includes ***/
-#include
-#include
-
-
-
-/*** Estructuras personalizadas ***/
-
-// Pixel RGBA
-struct rgba_pixel {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
-};
-
-// Cabecera del archivo
-struct file_header {
- uint8_t version; // Version del programa de mapeado
- char magic[32]; // Magic string
- uint32_t bg_width; // Ancho del fondo (imagen original)
- uint32_t bg_height; // Alto del fondo (imagen original)
- uint32_t tileset_width; // Ancho del Tileset en pixeles
- uint32_t tileset_height; // Ancho del Tileset en pixeles
- uint32_t map_width; // Ancho del mapa (segun los tiles) en pixeles
- uint32_t map_height; // Alto del mapa (segun los tiles) en pixeles
- uint32_t tile_size; // Tamaño del tile
- uint32_t tileset_length; // Tamaño de los datos del tileset
- uint32_t map_length; // Tamaño de los datos del mapa
- char reserve[256]; // Posible uso futuro
-};
-
-
-/*** Clase para la conversion del archivo PNG ***/
-class PngToTiles {
-
- // Segmento Publico
- public:
-
- // Conctructor
- PngToTiles();
-
- // Destructor
- ~PngToTiles();
-
-
- // Propiedades publicas
- std::string input_filename; // Fichero de entrada
- std::string output_filename; // Nombre base del archivo de salida
- uint32_t size_of_tile; // Tamaño del tile [16x16 por defecto]
- bool extra_files; // Generar archivos adicionales?
- uint32_t optimize; // Nivel de optimizacion
-
-
- // Convierte el archivo
- int32_t ConvertPng();
-
-
-
-
-
- // Segmento privado
- private:
-
- /*** Propiedades ***/
-
- // Define los vectores de memoria
- std::vector png; // Buffer para almacenar la imagen PNG
- std::vector raw; // Buffer para almacenar los pixeles de la imagen de entrada
- std::vector out; // Buffer para almacenar la imagen de salida
-
- std::vector tiles; // Buffer para almacenar los tiles del tileset
- std::vector tmap; // Buffer para almacenar el mapa
-
- std::vector img_tile; // Almacena un tile de la imagen de Origen
- std::vector map_tile; // Almacena un tile del mapa de destino
-
- std::vector buffer; // Buffer temporal de datos
-
- // Parametros de las imagenes
- uint32_t out_width, out_height; // Tamaño del archivo de salida
- uint32_t bg_width, bg_height; // Tamaño real del fondo
- uint32_t map_width, map_height; // Tamaño del mapa a generar
- uint32_t tileset_length; // Numero de tiles unicos del tileset
-
- // Cabecera del archivo de salida
- file_header header;
-
-
- /*** Metodos ***/
-
- // Lee el archivo PNG y almacena los pixeles de la imagen en el buffer
- int32_t ReadPNG(std::string filename, std::vector &data);
-
- // Graba el buffer a un archivo PNG
- int32_t WritePNG(std::string filename, std::vector &data);
-
- // Convierte la imagen en tiles + mapa
- void GenerateTileset();
-
- // Graba el archivo empaquetado
- int32_t WriteFile(std::string filename);
-
- // Lee un pixel del buffer especificado
- rgba_pixel GetPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w);
-
- // Escribe el pixel en el buffer especificado
- void PutPixel(std::vector &data, uint32_t x, uint32_t y, uint32_t w, rgba_pixel pixel);
-
- // Lee un tile del buffer especificado
- void GetTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t max_w, uint32_t max_h);
-
- // Escribe un tile en el buffer especificado
- void PutTile(std::vector &tl, std::vector &img, uint32_t x, uint32_t y, uint32_t w);
-
- // Realiza la optimizacion de tiles unicos
- uint32_t OptimizeTiles();
-
- // Compara si 2 tiles son identicos (img_tile vs map_tile)
- bool CompareNormal();
-
- // Compara si 2 tiles estan en espejo horizontal (H FLIP)
- bool CompareFlipH();
-
- // Compara si 2 tiles estan en espejo vertical (V FLIP)
- bool CompareFlipV();
-
- // Compara si 2 tiles estan en espejo completo (H & V FLIP)
- bool Compare180deg();
-
- // Compara si 2 tiles estan rotadas 90º a la derecha (90º Clock Wise)
- bool Compare90degCW();
-
- // Compara si 2 tiles estan rotadas 90º a la izquierda (90º Anti Clock Wise)
- bool Compare90degACW();
-
-};
-
-
-
-#endif // TILEMAP_H_INCLUDED
diff --git a/Tools/StaticLib/NGN.cbp b/Tools/StaticLib/NGN.cbp
index c39f4e2..c0e81e2 100644
--- a/Tools/StaticLib/NGN.cbp
+++ b/Tools/StaticLib/NGN.cbp
@@ -107,12 +107,13 @@
-
+
+
diff --git a/Tools/StaticLib/source/config_flags.h b/Tools/StaticLib/source/config_flags.h
new file mode 100644
index 0000000..238dc3e
--- /dev/null
+++ b/Tools/StaticLib/source/config_flags.h
@@ -0,0 +1,124 @@
+/******************************************************************************
+
+ N'gine Lib for C++
+ *** Version 1.11.0-stable ***
+ FLAGS de configuracion de la libreria
+ La libreria debe compilarse para que estos FLAGS sean efectivos
+
+ Proyecto iniciado el 1 de Febrero del 2016
+ (cc) 2016 - 2023 by Cesar Rincon "NightFox"
+ https://nightfoxandco.com
+ contact@nightfoxandco.com
+
+ Requiere GCC 11.3.0 MinGW64 (SEH) - 64-bits
+ https://www.mingw-w64.org/
+
+ Requiere SDL2 (2.0.22) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SDL2_TTF (2.0.15) - 64-bits
+ http://www.libsdl.org/download-2.0.php
+
+ Requiere SFML (2.5.1) - 64-bits
+ http://www.sfml-dev.org/
+
+ Requiere LodePNG (20220717)
+ (c) 2005 - 2022 by Lode Vandevenne
+ http://lodev.org/lodepng/
+
+
+ N'gine se distribuye bajo la licencia CREATIVE COMMONS
+ "Attribution-NonCommercial 4.0 International"
+ https://creativecommons.org/licenses/by-nc/4.0/
+
+ You are free to:
+
+ - Share
+ copy and redistribute the material in any medium or format.
+ - Adapt
+ remix, transform, and build upon the material.
+
+ The licensor cannot revoke these freedoms as long as you follow
+ the license terms.
+
+ Under the following terms:
+
+ - Attribution
+ You must give appropriate credit, provide a link to the license,
+ and indicate if changes were made. You may do so in any reasonable
+ manner, but not in any way that suggests the licensor endorses you
+ or your use.
+
+ - NonCommercial
+ You may not use the material for commercial purposes.
+
+ - No additional restrictions
+ You may not apply legal terms or technological measures that
+ legally restrict others from doing anything the license permits.
+
+******************************************************************************/
+
+
+
+#ifndef CONFIG_FLAGS_H_INCLUDED
+#define CONFIG_FLAGS_H_INCLUDED
+
+
+
+/******************************************************************************
+
+ Flags de seleccion del sistema operativo de destino
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the target operating system
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define OS_WINDOWS
+//#define OS_LINUX
+
+
+/******************************************************************************
+
+ Flags de seleccion del tipo de binario (debug o release)
+ Usar solo 1 a la vez y si no se esta usando el proyecto de code::blocks
+
+ Flags to select the type of the binary (debug or release)
+ Use only 1 at a time and if you are not using the code::blocks project
+
+******************************************************************************/
+
+//#define MODE_DEBUG
+//#define MODE_RELEASE
+
+
+/******************************************************************************
+
+ Flags de configuracion avanzados de N'gine
+ N'gine advanced configuration flags
+
+******************************************************************************/
+
+/*
+ Deshabilita las funciones avanzadas de sonido de SFML
+ Usar solo si se usa una version inferior a la 2.5.1.
+ Disables the advanced features of SFML audio library.
+ Use only if you're using a version under 2.5.1
+*/
+//#define DISABLE_SFML_AUDIO_ADVANCED_FEATURES
+
+/*
+ Deshabilita la funcion de backbuffer de N'gine.
+ Esto aumenta el rendimiento en mas de un 50% en GPU's de perfil bajo,
+ pero se pierde la opcion de filtrado bilineal en objetos y capas
+ por separado.
+ Disables the backbuffer feature of N'gine.
+ That speeds up to 50% in lowend GPU's, but also disables the option
+ of enable bilinear filtering in objects and layers separately.
+*/
+//#define DISABLE_BACKBUFFER
+
+
+
+#endif // CONFIG_FLAGS_H_INCLUDED
diff --git a/Tools/StaticLib/source/lodepng/lodepng.cpp b/Tools/StaticLib/source/lodepng/lodepng.cpp
index ee8cf33..1f89677 100644
--- a/Tools/StaticLib/source/lodepng/lodepng.cpp
+++ b/Tools/StaticLib/source/lodepng/lodepng.cpp
@@ -1,7 +1,7 @@
/*
-LodePNG version 20200306
+LodePNG version 20220717
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,10 +44,10 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
#endif /*_MSC_VER */
-const char* LODEPNG_VERSION_STRING = "20200306";
+const char* LODEPNG_VERSION_STRING = "20220717";
/*
-This source file is built up in the following large parts. The code sections
+This source file is divided into the following large parts. The code sections
with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way.
-Tools for C and common code for PNG and Zlib
-C Code for Zlib (huffman, deflate, ...)
@@ -267,7 +267,7 @@ typedef struct ucvector {
} ucvector;
/*returns 1 if success, 0 if failure ==> nothing done*/
-static unsigned ucvector_resize(ucvector* p, size_t size) {
+static unsigned ucvector_reserve(ucvector* p, size_t size) {
if(size > p->allocsize) {
size_t newsize = size + (p->allocsize >> 1u);
void* data = lodepng_realloc(p->data, newsize);
@@ -277,10 +277,15 @@ static unsigned ucvector_resize(ucvector* p, size_t size) {
}
else return 0; /*error: not enough memory*/
}
- p->size = size;
return 1; /*success*/
}
+/*returns 1 if success, 0 if failure ==> nothing done*/
+static unsigned ucvector_resize(ucvector* p, size_t size) {
+ p->size = size;
+ return ucvector_reserve(p, size);
+}
+
static ucvector ucvector_init(unsigned char* buffer, size_t size) {
ucvector v;
v.data = buffer;
@@ -299,6 +304,7 @@ static void string_cleanup(char** out) {
*out = NULL;
}
+/*also appends null termination character*/
static char* alloc_string_sized(const char* in, size_t insize) {
char* out = (char*)lodepng_malloc(insize + 1);
if(out) {
@@ -479,71 +485,62 @@ static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned c
ensureBits functions:
Ensures the reader can at least read nbits bits in one or more readBits calls,
safely even if not enough bits are available.
-Returns 1 if there are enough bits available, 0 if not.
+The nbits parameter is unused but is given for documentation purposes, error
+checking for amount of bits must be done beforehand.
*/
-/*See ensureBits documentation above. This one ensures exactly 1 bit */
-/*static unsigned ensureBits1(LodePNGBitReader* reader) {
- if(reader->bp >= reader->bitsize) return 0;
- reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u);
- return 1;
-}*/
-
/*See ensureBits documentation above. This one ensures up to 9 bits */
-static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits9(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 1u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
- if(start + 0u < size) reader->buffer |= reader->data[start + 0];
+ if(start + 0u < size) reader->buffer = reader->data[start + 0];
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 17 bits */
-static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits17(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 2u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 25 bits */
-static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits25(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 3u < size) {
reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) |
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u);
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/*See ensureBits documentation above. This one ensures up to 32 bits */
-static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void ensureBits32(LodePNGBitReader* reader, size_t nbits) {
size_t start = reader->bp >> 3u;
size_t size = reader->size;
if(start + 4u < size) {
@@ -551,7 +548,6 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u)));
- return 1;
} else {
reader->buffer = 0;
if(start + 0u < size) reader->buffer |= reader->data[start + 0];
@@ -559,48 +555,28 @@ static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbi
if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u);
if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u);
reader->buffer >>= (reader->bp & 7u);
- return reader->bp + nbits <= reader->bitsize;
}
+ (void)nbits;
}
/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */
-static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned peekBits(LodePNGBitReader* reader, size_t nbits) {
/* The shift allows nbits to be only up to 31. */
return reader->buffer & ((1u << nbits) - 1u);
}
/* Must have enough bits available with ensureBits */
-static void advanceBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE void advanceBits(LodePNGBitReader* reader, size_t nbits) {
reader->buffer >>= nbits;
reader->bp += nbits;
}
/* Must have enough bits available with ensureBits */
-static unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
+static LODEPNG_INLINE unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
unsigned result = peekBits(reader, nbits);
advanceBits(reader, nbits);
return result;
}
-
-/* Public for testing only. steps and result must have numsteps values. */
-unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
- size_t numsteps, const size_t* steps, unsigned* result) {
- size_t i;
- LodePNGBitReader reader;
- unsigned error = LodePNGBitReader_init(&reader, data, size);
- if(error) return 0;
- for(i = 0; i < numsteps; i++) {
- size_t step = steps[i];
- unsigned ok;
- if(step > 25) ok = ensureBits32(&reader, step);
- else if(step > 17) ok = ensureBits25(&reader, step);
- else if(step > 9) ok = ensureBits17(&reader, step);
- else ok = ensureBits9(&reader, step);
- if(!ok) return 0;
- result[i] = readBits(&reader, step);
- }
- return 1;
-}
#endif /*LODEPNG_COMPILE_DECODER*/
static unsigned reverseBits(unsigned bits, unsigned num) {
@@ -735,10 +711,11 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) {
numpresent = 0;
for(i = 0; i < tree->numcodes; ++i) {
unsigned l = tree->lengths[i];
- unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
- /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
- unsigned reverse = reverseBits(symbol, l);
+ unsigned symbol, reverse;
if(l == 0) continue;
+ symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/
+ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/
+ reverse = reverseBits(symbol, l);
numpresent++;
if(l <= FIRSTBITS) {
@@ -1102,11 +1079,10 @@ static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree*
advanceBits(reader, l);
return value;
} else {
- unsigned index2;
advanceBits(reader, FIRSTBITS);
- index2 = value + peekBits(reader, l - FIRSTBITS);
- advanceBits(reader, codetree->table_len[index2] - FIRSTBITS);
- return codetree->table_value[index2];
+ value += peekBits(reader, l - FIRSTBITS);
+ advanceBits(reader, codetree->table_len[value] - FIRSTBITS);
+ return codetree->table_value[value];
}
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -1139,7 +1115,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
unsigned* bitlen_cl = 0;
HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/
- if(!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/
+ if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the memory*/
+ ensureBits17(reader, 14);
/*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/
HLIT = readBits(reader, 5) + 257;
@@ -1260,10 +1237,14 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/
static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
- unsigned btype) {
+ unsigned btype, size_t max_output_size) {
unsigned error = 0;
HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/
HuffmanTree tree_d; /*the huffman tree for distance codes*/
+ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */
+ int done = 0;
+
+ if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
HuffmanTree_init(&tree_ll);
HuffmanTree_init(&tree_d);
@@ -1271,14 +1252,21 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d);
else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader);
- while(!error) /*decode all symbols until end reached, breaks at end code*/ {
+
+ while(!error && !done) /*decode all symbols until end reached, breaks at end code*/ {
/*code_ll is literal, length or end code*/
unsigned code_ll;
- ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */
+ /* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second literal is read at once. This
+ appears to be slightly faster, than ensuring 20 bits here for 1 huffman symbol and the potential 5 extra bits for the length symbol.*/
+ ensureBits32(reader, 30);
code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ if(code_ll <= 255) {
+ /*slightly faster code path if multiple literals in a row*/
+ out->data[out->size++] = (unsigned char)code_ll;
+ code_ll = huffmanDecodeSymbol(reader, &tree_ll);
+ }
if(code_ll <= 255) /*literal symbol*/ {
- if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/);
- out->data[out->size - 1] = (unsigned char)code_ll;
+ out->data[out->size++] = (unsigned char)code_ll;
} else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ {
unsigned code_d, distance;
unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/
@@ -1291,6 +1279,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX];
if(numextrabits_l != 0) {
/* bits already ensured above */
+ ensureBits25(reader, 5);
length += readBits(reader, numextrabits_l);
}
@@ -1318,7 +1307,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
if(distance > start) ERROR_BREAK(52); /*too long backward distance*/
backward = start - distance;
- if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/);
+ out->size += length;
if(distance < length) {
size_t forward;
lodepng_memcpy(out->data + start, out->data + backward, distance);
@@ -1330,10 +1319,13 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
lodepng_memcpy(out->data + start, out->data + backward, length);
}
} else if(code_ll == 256) {
- break; /*end code, break the loop*/
+ done = 1; /*end code, finish the loop*/
} else /*if(code_ll == INVALIDSYMBOL)*/ {
ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
}
+ if(out->allocsize - out->size < reserved_size) {
+ if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
+ }
/*check if any of the ensureBits above went out of bounds*/
if(reader->bp > reader->bitsize) {
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
@@ -1341,6 +1333,9 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
/* TODO: revise error codes 10,11,50: the above comment is no longer valid */
ERROR_BREAK(51); /*error, bit pointer jumps past memory*/
}
+ if(max_output_size && out->size > max_output_size) {
+ ERROR_BREAK(109); /*error, larger than max size*/
+ }
}
HuffmanTree_cleanup(&tree_ll);
@@ -1373,8 +1368,11 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
- lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
- bytepos += LEN;
+ /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
+ if (LEN) {
+ lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
+ bytepos += LEN;
+ }
reader->bp = bytepos << 3u;
@@ -1392,15 +1390,16 @@ static unsigned lodepng_inflatev(ucvector* out,
while(!BFINAL) {
unsigned BTYPE;
- if(!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/
+ if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/
+ ensureBits9(&reader, 3);
BFINAL = readBits(&reader, 1);
BTYPE = readBits(&reader, 2);
if(BTYPE == 3) return 20; /*error: invalid BTYPE*/
else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/
- else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/
-
- if(error) return error;
+ else error = inflateHuffmanBlock(out, &reader, BTYPE, settings->max_output_size); /*compression, BTYPE 01 or 10*/
+ if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ if(error) break;
}
return error;
@@ -1421,6 +1420,12 @@ static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize,
if(settings->custom_inflate) {
unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings);
out->allocsize = out->size;
+ if(error) {
+ /*the custom inflate is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && out->size > settings->max_output_size) error = 109;
+ }
return error;
} else {
return lodepng_inflatev(out, in, insize, settings);
@@ -2116,7 +2121,9 @@ static unsigned deflate(unsigned char** out, size_t* outsize,
const unsigned char* in, size_t insize,
const LodePNGCompressSettings* settings) {
if(settings->custom_deflate) {
- return settings->custom_deflate(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_deflate(out, outsize, in, insize, settings);
+ /*the custom deflate is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_deflate(out, outsize, in, insize, settings);
}
@@ -2213,10 +2220,16 @@ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const uns
/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
+ unsigned error;
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ error = settings->custom_zlib(out, outsize, in, insize, settings);
+ if(error) {
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
+ error = 110;
+ /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
+ if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
+ }
} else {
- unsigned error;
ucvector v = ucvector_init(*out, *outsize);
if(expected_size) {
/*reserve the memory to avoid intermediate reallocations*/
@@ -2226,8 +2239,8 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t exp
error = lodepng_zlib_decompressv(&v, in, insize, settings);
*out = v.data;
*outsize = v.size;
- return error;
}
+ return error;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2275,7 +2288,9 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in,
size_t insize, const LodePNGCompressSettings* settings) {
if(settings->custom_zlib) {
- return settings->custom_zlib(out, outsize, in, insize, settings);
+ unsigned error = settings->custom_zlib(out, outsize, in, insize, settings);
+ /*the custom zlib is allowed to have its own error codes, however, we translate it to code 111*/
+ return error ? 111 : 0;
} else {
return lodepng_zlib_compress(out, outsize, in, insize, settings);
}
@@ -2334,13 +2349,14 @@ const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT
void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) {
settings->ignore_adler32 = 0;
settings->ignore_nlen = 0;
+ settings->max_output_size = 0;
settings->custom_zlib = 0;
settings->custom_inflate = 0;
settings->custom_context = 0;
}
-const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0};
+const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0, 0};
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2357,7 +2373,7 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
/* ////////////////////////////////////////////////////////////////////////// */
-#ifndef LODEPNG_NO_COMPILE_CRC
+#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
@@ -2403,9 +2419,11 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) {
}
return r ^ 0xffffffffu;
}
-#else /* !LODEPNG_NO_COMPILE_CRC */
+#else /* LODEPNG_COMPILE_CRC */
+/*in this case, the function is only declared here, and must be defined externally
+so that it will be linked in*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
-#endif /* !LODEPNG_NO_COMPILE_CRC */
+#endif /* LODEPNG_COMPILE_CRC */
/* ////////////////////////////////////////////////////////////////////////// */
/* / Reading and writing PNG color channel bits / */
@@ -2443,7 +2461,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream,
/* ////////////////////////////////////////////////////////////////////////// */
unsigned lodepng_chunk_length(const unsigned char* chunk) {
- return lodepng_read32bitInt(&chunk[0]);
+ return lodepng_read32bitInt(chunk);
}
void lodepng_chunk_type(char type[5], const unsigned char* chunk) {
@@ -2493,34 +2511,32 @@ void lodepng_chunk_generate_crc(unsigned char* chunk) {
}
unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) {
- if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/
+ size_t available_size = (size_t)(end - chunk);
+ if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/
if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47
&& chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) {
/* Is PNG magic header at start of PNG file. Jump to first actual chunk. */
return chunk + 8;
} else {
size_t total_chunk_length;
- const unsigned char* result;
if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end;
- result = chunk + total_chunk_length;
- if(result < chunk) return end; /*pointer overflow*/
- return result;
+ if(total_chunk_length > available_size) return end; /*outside of range*/
+ return chunk + total_chunk_length;
}
}
@@ -2872,8 +2888,8 @@ static void LodePNGText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->text_keys = 0;
- dest->text_strings = 0;
+ dest->text_keys = NULL;
+ dest->text_strings = NULL;
dest->text_num = 0;
for(i = 0; i != source->text_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i]));
@@ -2932,10 +2948,10 @@ static void LodePNGIText_cleanup(LodePNGInfo* info) {
static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
size_t i = 0;
- dest->itext_keys = 0;
- dest->itext_langtags = 0;
- dest->itext_transkeys = 0;
- dest->itext_strings = 0;
+ dest->itext_keys = NULL;
+ dest->itext_langtags = NULL;
+ dest->itext_transkeys = NULL;
+ dest->itext_strings = NULL;
dest->itext_num = 0;
for(i = 0; i != source->itext_num; ++i) {
CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i],
@@ -3030,6 +3046,9 @@ void lodepng_info_init(LodePNGInfo* info) {
info->iccp_name = NULL;
info->iccp_profile = NULL;
+ info->sbit_defined = 0;
+ info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0;
+
LodePNGUnknownChunks_init(info);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
}
@@ -3924,7 +3943,7 @@ static unsigned auto_choose_color(LodePNGColorMode* mode_out,
if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize
&& mode_in->bitdepth == mode_out->bitdepth) {
/*If input should have same palette colors, keep original to preserve its order and prevent conversion*/
- lodepng_color_mode_cleanup(mode_out);
+ lodepng_color_mode_cleanup(mode_out); /*clears palette, keeps the above set colortype and bitdepth fields as-is*/
lodepng_color_mode_copy(mode_out, mode_in);
}
} else /*8-bit or 16-bit per channel*/ {
@@ -4093,10 +4112,12 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
case 0:
for(i = 0; i != length; ++i) recon[i] = scanline[i];
break;
- case 1:
+ case 1: {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth];
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + recon[j];
break;
+ }
case 2:
if(precon) {
for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i];
@@ -4106,24 +4127,56 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
break;
case 3:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u);
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u);
+ /* Unroll independent paths of this predictor. A 6x and 8x version is also possible but that adds
+ too much code. Whether this speeds up anything depends on compiler and settings. */
+ if(bytewidth >= 4) {
+ for(; i + 3 < length; i += 4, j += 4) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ recon[i + 3] = s3 + ((r3 + p3) >> 1u);
+ }
+ } else if(bytewidth >= 3) {
+ for(; i + 2 < length; i += 3, j += 3) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ recon[i + 2] = s2 + ((r2 + p2) >> 1u);
+ }
+ } else if(bytewidth >= 2) {
+ for(; i + 1 < length; i += 2, j += 2) {
+ unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
+ unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
+ unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
+ recon[i + 0] = s0 + ((r0 + p0) >> 1u);
+ recon[i + 1] = s1 + ((r1 + p1) >> 1u);
+ }
+ }
+ for(; i != length; ++i, ++j) recon[i] = scanline[i] + ((recon[j] + precon[i]) >> 1u);
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
- for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u);
+ for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + (recon[j] >> 1u);
}
break;
case 4:
if(precon) {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
- /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that
- adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */
+ /* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that
+ adds too much code. Whether this speeds up anything depends on compiler and settings. */
if(bytewidth >= 4) {
- for(; i + 3 < length; i += 4) {
- size_t j = i - bytewidth;
+ for(; i + 3 < length; i += 4, j += 4) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
@@ -4134,8 +4187,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 3] = s3 + paethPredictor(r3, p3, q3);
}
} else if(bytewidth >= 3) {
- for(; i + 2 < length; i += 3) {
- size_t j = i - bytewidth;
+ for(; i + 2 < length; i += 3, j += 3) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
@@ -4145,8 +4197,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
}
} else if(bytewidth >= 2) {
- for(; i + 1 < length; i += 2) {
- size_t j = i - bytewidth;
+ for(; i + 1 < length; i += 2, j += 2) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
@@ -4156,16 +4207,17 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
}
}
- for(; i != length; ++i) {
- recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
+ for(; i != length; ++i, ++j) {
+ recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j]));
}
} else {
+ size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = scanline[i];
}
- for(i = bytewidth; i < length; ++i) {
+ for(i = bytewidth; i != length; ++i, ++j) {
/*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
- recon[i] = (scanline[i] + recon[i - bytewidth]);
+ recon[i] = (scanline[i] + recon[j]);
}
}
break;
@@ -4447,10 +4499,13 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
}
/*compressed text chunk (zTXt)*/
-static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, string2_begin;
char *key = 0;
unsigned char* str = 0;
@@ -4473,12 +4528,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(error) break;
error = lodepng_add_text_sized(info, key, (char*)str, size);
-
break;
}
@@ -4489,11 +4546,14 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
}
/*international text chunk (iTXt)*/
-static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
+
unsigned length, begin, compressed;
char *key = 0, *langtag = 0, *transkey = 0;
@@ -4550,9 +4610,12 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(compressed) {
unsigned char* str = 0;
size_t size = 0;
+ zlibsettings.max_output_size = decoder->max_text_size;
/*will fail if zlib error, e.g. if length is too small*/
error = zlib_decompress(&str, &size, 0, &data[begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: compressed text larger than decoder->max_text_size*/
+ if(error && size > zlibsettings.max_output_size) error = 112;
if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
lodepng_free(str);
} else {
@@ -4628,11 +4691,13 @@ static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, siz
return 0; /* OK */
}
-static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
+static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
const unsigned char* data, size_t chunkLength) {
unsigned error = 0;
unsigned i;
size_t size = 0;
+ /*copy the object to change parameters in it*/
+ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;
unsigned length, string2_begin;
@@ -4655,13 +4720,57 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSetting
if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/
length = (unsigned)chunkLength - string2_begin;
+ zlibsettings.max_output_size = decoder->max_icc_size;
error = zlib_decompress(&info->iccp_profile, &size, 0,
&data[string2_begin],
- length, zlibsettings);
+ length, &zlibsettings);
+ /*error: ICC profile larger than decoder->max_icc_size*/
+ if(error && size > zlibsettings.max_output_size) error = 113;
info->iccp_profile_size = size;
if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
return error;
}
+
+/*significant bits chunk (sBIT)*/
+static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ if(info->color.colortype == LCT_GREY) {
+ /*error: this chunk must be 1 bytes for grayscale image*/
+ if(chunkLength != 1) return 114;
+ if(data[0] == 0 || data[0] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ /*error: this chunk must be 3 bytes for RGB and palette image*/
+ if(chunkLength != 3) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ /*error: this chunk must be 2 byte for grayscale with alpha image*/
+ if(chunkLength != 2) return 114;
+ if(data[0] == 0 || data[1] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/
+ info->sbit_a = data[1];
+ } else if(info->color.colortype == LCT_RGBA) {
+ /*error: this chunk must be 4 bytes for grayscale image*/
+ if(chunkLength != 4) return 114;
+ if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115;
+ if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 115;
+ info->sbit_defined = 1;
+ info->sbit_r = data[0];
+ info->sbit_g = data[1];
+ info->sbit_b = data[2];
+ info->sbit_a = data[3];
+ }
+
+ return 0; /* OK */
+}
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
@@ -4676,7 +4785,7 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
chunkLength = lodepng_chunk_length(chunk);
if(chunkLength > 2147483647) return 63;
data = lodepng_chunk_data_const(chunk);
- if(data + chunkLength + 4 > in + insize) return 30;
+ if(chunkLength + 12 > insize - pos) return 30;
if(lodepng_chunk_type_equals(chunk, "PLTE")) {
error = readChunk_PLTE(&state->info_png.color, data, chunkLength);
@@ -4688,9 +4797,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "tEXt")) {
error = readChunk_tEXt(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
- error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
- error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
error = readChunk_tIME(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "pHYs")) {
@@ -4702,7 +4811,9 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
} else if(lodepng_chunk_type_equals(chunk, "sRGB")) {
error = readChunk_sRGB(&state->info_png, data, chunkLength);
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ error = readChunk_sBIT(&state->info_png, data, chunkLength);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else {
/* unhandled chunk is ok (is not an error) */
@@ -4721,7 +4832,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
LodePNGState* state,
const unsigned char* in, size_t insize) {
unsigned char IEND = 0;
- const unsigned char* chunk;
+ const unsigned char* chunk; /*points to beginning of next chunk*/
unsigned char* idat; /*the data from idat chunks, zlib compressed*/
size_t idatsize = 0;
unsigned char* scanlines = 0;
@@ -4757,14 +4868,15 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
while(!IEND && !state->error) {
unsigned chunkLength;
const unsigned char* data; /*the data in the chunk*/
+ size_t pos = (size_t)(chunk - in);
- /*error: size of the in buffer too small to contain next chunk*/
- if((size_t)((chunk - in) + 12) > insize || chunk < in) {
+ /*error: next chunk out of bounds of the in buffer*/
+ if(chunk < in || pos + 12 > insize) {
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 30);
}
- /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
+ /*length of the data of the chunk, excluding the 12 bytes for length, chunk type and CRC*/
chunkLength = lodepng_chunk_length(chunk);
/*error: chunk length larger than the max PNG chunk size*/
if(chunkLength > 2147483647) {
@@ -4772,8 +4884,8 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
CERROR_BREAK(state->error, 63);
}
- if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) {
- CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
+ if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) {
+ CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk (or int overflow)*/
}
data = lodepng_chunk_data_const(chunk);
@@ -4820,13 +4932,13 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
} else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
/*compressed text chunk (zTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
/*international text chunk (iTXt)*/
if(state->decoder.read_text_chunks) {
- state->error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
if(state->error) break;
}
} else if(lodepng_chunk_type_equals(chunk, "tIME")) {
@@ -4845,7 +4957,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
state->error = readChunk_sRGB(&state->info_png, data, chunkLength);
if(state->error) break;
} else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
- state->error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength);
+ state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ if(state->error) break;
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ state->error = readChunk_sBIT(&state->info_png, data, chunkLength);
if(state->error) break;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} else /*it's not an implemented chunk type, so ignore it: skip over the data*/ {
@@ -4871,7 +4986,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize);
}
- if(state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
+ if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) {
state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */
}
@@ -4955,6 +5070,11 @@ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, co
lodepng_state_init(&state);
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*disable reading things that this function doesn't output*/
+ state.decoder.read_text_chunks = 0;
+ state.decoder.remember_unknown_chunks = 0;
+#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
error = lodepng_decode(out, w, h, &state, in, insize);
lodepng_state_cleanup(&state);
return error;
@@ -4997,6 +5117,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
settings->read_text_chunks = 1;
settings->remember_unknown_chunks = 0;
+ settings->max_text_size = 16777216;
+ settings->max_icc_size = 16777216; /* 16MB is much more than enough for any reasonable ICC profile */
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
settings->ignore_crc = 0;
settings->ignore_critical = 0;
@@ -5075,6 +5197,10 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) {
unsigned char* chunk;
size_t i, j = 8;
+ if(info->palettesize == 0 || info->palettesize > 256) {
+ return 68; /*invalid palette size, it is only allowed to be 1-256*/
+ }
+
CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE"));
for(i = 0; i != info->palettesize; ++i) {
@@ -5330,6 +5456,42 @@ static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCom
return error;
}
+static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ unsigned char* chunk = 0;
+ if(info->color.colortype == LCT_GREY) {
+ if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT"));
+ chunk[8] = info->sbit_r;
+ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ } else if(info->color.colortype == LCT_GREY_ALPHA) {
+ if(info->sbit_r == 0 || info->sbit_a == 0) return 115;
+ if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115;
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_a;
+ } else if(info->color.colortype == LCT_RGBA) {
+ if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 ||
+ info->sbit_r > bitdepth || info->sbit_g > bitdepth ||
+ info->sbit_b > bitdepth || info->sbit_a > bitdepth) {
+ return 115;
+ }
+ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT"));
+ chunk[8] = info->sbit_r;
+ chunk[9] = info->sbit_g;
+ chunk[10] = info->sbit_b;
+ chunk[11] = info->sbit_a;
+ }
+ if(chunk) lodepng_chunk_generate_crc(chunk);
+ return 0;
+}
+
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline,
@@ -5775,8 +5937,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
ucvector outv = ucvector_init(NULL, 0);
LodePNGInfo info;
const LodePNGInfo* info_png = &state->info_png;
+ LodePNGColorMode auto_color;
lodepng_info_init(&info);
+ lodepng_color_mode_init(&auto_color);
/*provide some proper output values if error will happen*/
*out = 0;
@@ -5786,6 +5950,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*check input values validity*/
if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
&& (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) {
+ /*this error is returned even if auto_convert is enabled and thus encoder could
+ generate the palette by itself: while allowing this could be possible in theory,
+ it may complicate the code or edge cases, and always requiring to give a palette
+ when setting this color type is a simpler contract*/
state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
goto cleanup;
}
@@ -5806,6 +5974,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
lodepng_info_copy(&info, &state->info_png);
if(state->encoder.auto_convert) {
LodePNGColorStats stats;
+ unsigned allow_convert = 1;
lodepng_color_stats_init(&stats);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined &&
@@ -5827,23 +5996,85 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*the background chunk's color must be taken into account as well*/
unsigned r = 0, g = 0, b = 0;
LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
- lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
+ lodepng_convert_rgb(&r, &g, &b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
state->error = lodepng_color_stats_add(&stats, r, g, b, 65535);
if(state->error) goto cleanup;
}
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
- state->error = auto_choose_color(&info.color, &state->info_raw, &stats);
+ state->error = auto_choose_color(&auto_color, &state->info_raw, &stats);
if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
- /*also convert the background chunk*/
- if(info_png->background_defined) {
- if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
- info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
- state->error = 104;
- goto cleanup;
+ if(info_png->sbit_defined) {
+ /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes,
+ auto_convert can't be done in many cases. However, do support a few cases here.
+ TODO: more conversions may be possible, and it may also be possible to get a more appropriate color type out of
+ auto_choose_color if knowledge about sbit is used beforehand
+ */
+ unsigned sbit_max = LODEPNG_MAX(LODEPNG_MAX(LODEPNG_MAX(info_png->sbit_r, info_png->sbit_g),
+ info_png->sbit_b), info_png->sbit_a);
+ unsigned equal = (!info_png->sbit_g || info_png->sbit_g == info_png->sbit_r)
+ && (!info_png->sbit_b || info_png->sbit_b == info_png->sbit_r)
+ && (!info_png->sbit_a || info_png->sbit_a == info_png->sbit_r);
+ allow_convert = 0;
+ if(info.color.colortype == LCT_PALETTE &&
+ auto_color.colortype == LCT_PALETTE) {
+ /* input and output are palette, and in this case it may happen that palette data is
+ expected to be copied from info_raw into the info_png */
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGB to palette (or 16-bit as long as sbit_max <= 8) is possible
+ since both are 8-bit RGB for sBIT's purposes*/
+ if(info.color.colortype == LCT_RGB &&
+ auto_color.colortype == LCT_PALETTE && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/
+ if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE &&
+ info_png->sbit_a == 8 && sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/
+ if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth == 16 &&
+ auto_color.colortype == info.color.colortype && auto_color.bitdepth == 8 &&
+ sbit_max <= 8) {
+ allow_convert = 1;
+ }
+ /*going to less channels is ok if all bit values are equal (all possible values in sbit,
+ as well as the chosen bitdepth of the result). Due to how auto_convert works,
+ we already know that auto_color.colortype has less than or equal amount of channels than
+ info.colortype. Palette is not used here. This conversion is not allowed if
+ info_png->sbit_r < auto_color.bitdepth, because specifically for alpha, non-presence of
+ an sbit value heavily implies that alpha's bit depth is equal to the PNG bit depth (rather
+ than the bit depths set in the r, g and b sbit values, by how the PNG specification describes
+ handling tRNS chunk case with sBIT), so be conservative here about ignoring user input.*/
+ if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE &&
+ equal && info_png->sbit_r == auto_color.bitdepth) {
+ allow_convert = 1;
}
}
+#endif
+ if(state->encoder.force_palette) {
+ if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
+ (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
+ /*user speficially forced a PLTE palette, so cannot convert to grayscale types because
+ the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
+ allow_convert = 0;
+ }
+ }
+ if(allow_convert) {
+ lodepng_color_mode_copy(&info.color, &auto_color);
+#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*also convert the background chunk*/
+ if(info_png->background_defined) {
+ if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
+ state->error = 104;
+ goto cleanup;
+ }
+ }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+ }
}
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
if(info_png->iccp_defined) {
@@ -5914,6 +6145,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
state->error = addChunk_cHRM(&outv, &info);
if(state->error) goto cleanup;
}
+ if(info_png->sbit_defined) {
+ state->error = addChunk_sBIT(&outv, &info);
+ if(state->error) goto cleanup;
+ }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
/*PLTE*/
if(info.color.colortype == LCT_PALETTE) {
@@ -6020,6 +6255,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
cleanup:
lodepng_info_cleanup(&info);
lodepng_free(data);
+ lodepng_color_mode_cleanup(&auto_color);
/*instead of cleaning the vector up, give it to the output*/
*out = outv.data;
@@ -6204,6 +6440,18 @@ const char* lodepng_error_text(unsigned code) {
case 106: return "PNG file must have PLTE chunk if color type is palette";
case 107: return "color convert from palette mode requested without setting the palette data in it";
case 108: return "tried to add more than 256 values to a palette";
+ /*this limit can be configured in LodePNGDecompressSettings*/
+ case 109: return "tried to decompress zlib or deflate data larger than desired max_output_size";
+ case 110: return "custom zlib or inflate decompression failed";
+ case 111: return "custom zlib or deflate compression failed";
+ /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large text sizes.*/
+ case 112: return "compressed text unreasonably large";
+ /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents
+ unreasonable memory consumption when decoding due to impossibly large ICC profile*/
+ case 113: return "ICC profile unreasonably large";
+ case 114: return "sBIT chunk has wrong size for the color type of the image";
+ case 115: return "sBIT value out of range";
}
return "unknown error code";
}
@@ -6240,7 +6488,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si
size_t buffersize = 0;
unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6259,7 +6507,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size
size_t buffersize = 0;
unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings);
if(buffer) {
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
lodepng_free(buffer);
}
return error;
@@ -6304,7 +6552,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const
state.info_raw.colortype = colortype;
state.info_raw.bitdepth = bitdepth;
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6322,7 +6570,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h,
unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize);
if(buffer && !error) {
size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw);
- out.insert(out.end(), &buffer[0], &buffer[buffersize]);
+ out.insert(out.end(), buffer, &buffer[buffersize]);
}
lodepng_free(buffer);
return error;
@@ -6354,7 +6602,7 @@ unsigned encode(std::vector