Commit Graph

90 Commits

Author SHA1 Message Date
Ivan Avdeev 5659fb0b6f imagelib: c90-ize ktx2 loader even more 2023-12-18 12:43:52 -05:00
Ivan Avdeev 6d79e84f5b imagelib: c90-ize ktx2 loader face cursors 2023-12-18 12:39:21 -05:00
Ivan Avdeev 356f7bdf71 imagelib: load KTX2 cubemaps directly 2023-12-18 11:37:46 -05:00
Ivan Avdeev 2776373652 imagelib: do not overwrite the correct image size when building cubemap
For some very unknown reason there's a line that fixes image size to
w*h*4, which would correspond to RGBA8 pixel format w/o alignment.

This is extremely incorrect for other pixel format, e.g. compressed
ones.

Not sure why this size-fixing was there, but removing it fixes sided
KTX2 compressed skybox corruption.
2023-12-15 09:14:23 -05:00
Ivan Avdeev b1b333f74a vk: use imagelib cubemap/skybox loader
Engine imagelib already has skybox loader. It uses rgbdata_t
IMAGE_CUBEMAP flag.
1. Support IMAGE_CUBEMAP
2. Utilize imagelib skybox loader, do not try to load individual skybox
   sides manually.

This will allow loading KTX2 cubemaps directly.

Known issues:
1. Compressed KTX2 sides are not rotated correctly. Engine/imagelib is
   unable to rotate compressed images.
2. Some KTX2 sides are corrupted. Cause unknown.
2023-12-14 13:40:34 -05:00
mittorn b949da291e engine: fix strict aliasing issues found by an old armv7hf compiler 2023-10-22 20:02:14 +03:00
Ivan Avdeev a251600c8a
engine: common: imagelib: add KTX2 support (#1455)
* engine: common: imagelib: add KTX2 support

Adds basic KTX2 support for a few compressed formats. KTX2 essentially
is a Vulkan-centric texture format that supports literally hundreds of
pixel formats.
For now only support for these is added:
- `VK_FORMAT_BC4_UNORM_BLOCK`
- `VK_FORMAT_BC4_SNORM_BLOCK`
- `VK_FORMAT_BC5_UNORM_BLOCK`
- `VK_FORMAT_BC5_SNORM_BLOCK`
- `VK_FORMAT_BC6H_UFLOAT_BLOCK`
- `VK_FORMAT_BC6H_SFLOAT_BLOCK`
- `VK_FORMAT_BC7_UNORM_BLOCK`
- `VK_FORMAT_BC7_SRGB_BLOCK`

Adding more formats is relatively straightforward:
- Copy format definition from `VkFormat` enum in `vulkan_core.h`
- Add a new definition into `pixformat_t` enum.
- Add format size calculation into `Image_ComputeSize()`

While we're at it, also adds a few new formats to DDS:
- BC4_UNORM -- PF_BC4_UNSIGNED
- BC4_SNORM -- PF_BC4_SIGNED
- BC5_UNORM -- PF_BC5_UNSIGNED
- BC5_SNORM -- PF_BC5_SIGNED
- BC7 is expanded into BC7_UNORM and BC7_SRGB

ref_gl and ref_soft code is updated where it made sense. But not tested
really. Support for these formats has been tested with ref_vk.

* address spaces-vs-parentheses formatting where noticed

* parenthesize sizeofs

* move ktx2.h to imagelib as img_ktx2.h; massage it a bit

* use SetBits() instead of |=

* remove stale TODO comments
2023-10-18 10:31:40 +03:00
Alibek Omarov 8f207362a5 public: remove Q_sprintf, and patch all code that used it to use Q_snprintf instead 2023-04-26 05:20:45 +03:00
Alibek Omarov 824a34ee1e engine: common: imgelib: fix declaration after statement in test code 2023-04-14 18:58:43 +03:00
Alibek Omarov 1caa276531 engine: common: imagelib: fix loading cubemaps
Loop break was a bug that was added after refactoring imagelib loader.

In fact, it was mindlessly copypasted from old code, where same break was
used to quickly exit from inner format bruteforcing loop, than outer cubemap
loading loop.
2023-03-25 07:02:29 +03:00
Andrey Akhmichin 9e9703e6de engine: common: imagelib: replace va function calls. 2023-03-11 17:37:16 +03:00
fgsfds 25a1cb8ce7 Nintendo Switch support (again) 2023-02-05 02:09:32 +01:00
Alibek Omarov aac0be1ab3 engine: imagelib: img_bmp: fully initialize local palette array 2023-01-31 00:50:04 +03:00
Alibek Omarov 49a65edfc3 engine: imagelib: img_quant: fix a bug in quantizer (thanks, @SNMetamorph for fix) 2023-01-05 07:24:24 +03:00
Alibek Omarov ea3bfd969c engine: imagelib: img_wad: dirty hack to fix black holes in console background images 2022-12-08 05:40:11 +03:00
Alibek Omarov 0e9106685b engine: imagelib: img_png: fix Mem_Free on null ptr 2022-12-05 06:13:04 +03:00
Alibek Omarov 9b001987e9 engine: imagelib: fix crash when chunk length is more than file size 2022-12-05 05:39:41 +03:00
Alibek Omarov 21c898d796 engine: imagelib: validate player decal image size (max 512x512) 2022-12-05 04:55:24 +03:00
Alibek Omarov e48b708fa6 engine: imagelib: img_png: validate image size through common engine function 2022-12-05 04:54:20 +03:00
Alibek Omarov ccf7619ae5 engine: imagelib: refactor image loading function 2022-12-05 03:22:07 +03:00
Andrey Akhmichin 7bb994f7bc engine: common: imagelib: img_png.c: fix wrong palette decoding. 2022-12-04 22:09:24 +03:00
Alibek Omarov c61442e960 engine: imagelib: simplify string operation 2022-12-04 05:26:22 +03:00
SNMetamorph 49fc6143ab engine: common: imagelib: fixed loading 32 bits per pixel BMP files 2022-11-25 22:30:49 +03:00
SNMetamorph 8717843333 engine: common: imagelib: fixed BMP files estimate size calculation with NPOT textures 2022-11-25 22:30:49 +03:00
SNMetamorph f6d8996968 engine: common: imagelib: added missed BMP compression type macros 2022-11-25 22:30:49 +03:00
Andrey Akhmichin d237114962 engine: common: imagelib: img_png.c: unroll loops. 2022-11-02 14:14:05 +06:00
Andrey Akhmichin fd152e82e8 engine: common: imagelib: img_png.c: add support for indexed and grayscale PNG images. 2022-09-08 12:11:02 +03:00
Alibek Omarov 5e4fc64430 filesystem: introduce new module, based on engine filesystem.
The goal is to share filesystem code between engine and
utilities and provide C++ VFileSystem interface in the future
2022-07-28 18:56:02 +03:00
Andrey Akhmichin 87ce35b32d engine: common: imagelib: img_utils.c: change formats priority. 2022-06-25 17:23:44 +03:00
Alibek Omarov 36cec298c2 Revert "engine: common: imagelib: img_tga.c: fix broken tga flip."
This reverts commit 99de598ea4.
2022-06-25 17:03:13 +03:00
Alibek Omarov 6199426e5e Revert "engine: common: imagelib: img_tga.c: fix broken tga flip again."
This reverts commit e5720cf8b9.
2022-06-25 17:03:12 +03:00
Andrey Akhmichin e5720cf8b9 engine: common: imagelib: img_tga.c: fix broken tga flip again. 2022-06-24 14:18:30 +03:00
Andrey Akhmichin 99de598ea4 engine: common: imagelib: img_tga.c: fix broken tga flip. 2022-06-24 07:38:21 +03:00
SNMetamorph cd2720ba81 engine: common: imagelib: fixed loading BMP files with v4/v5 headers 2022-03-13 01:50:30 +03:00
SNMetamorph 6473efa995 engine: added support for BC7 and BC6H compression formats of DDS textures 2022-03-07 02:03:40 +03:00
Alibek Omarov 5aa6bfee85 engine: first attempts on fuzzing the engine 2022-01-15 06:24:57 +03:00
Alibek Omarov 4f89288ccf common: cleanup port.h 2021-12-23 19:17:11 +03:00
Alibek Omarov e0efe0aa23 engine: remove emboss filter. There seems no real use for it. 2021-12-07 09:09:45 +03:00
Alibek Omarov fe0da74e75 engine: fix build with tests on 2021-09-30 15:58:32 +03:00
Alibek Omarov 91ee9bd32a engine: merge tests for imagelib 2021-06-20 20:26:22 +03:00
Alibek Omarov 9c8059ea96 engine: imagelib: add BGRA saving for PNG
Fix incorrect output, when input format has alpha but flags don't
have set IMAGE_HAS_ALPHA.
Flags are meant to control output format, but input format may be arbitrary,
as usually given by video driver(screenshots, etc)
2021-03-28 00:34:42 +03:00
Gleb Mazovetskiy 5e0a0765ce Trim all trailing whitespace
The `.editorconfig` file in this repo is configured to trim all trailing
whitespace regardless of whether the line is modified.

Trims all trailing whitespace in the repository to make the codebase easier
to work with in editors that respect `.editorconfig`.

`git blame` becomes less useful on these lines but it already isn't very useful.

Commands:

```
find . -type f -name '*.h' -exec sed --in-place 's/[[:space:]]\+$//' {} \+
find . -type f -name '*.c' -exec sed --in-place 's/[[:space:]]\+$//' {} \+
```
2021-01-04 20:55:10 +03:00
Alibek Omarov 61fe9fd1fe engine: fix some left shifts on signed integers 2021-01-02 05:01:51 +03:00
Andrey Akhmichin c53985c0bc engine: common: imagelib: img_tga.c: refactor Targa encoder. 2020-11-18 18:54:25 +05:00
Andrey Akhmichin e69956c9ea engine: common: imagelib: img_png.c: set IMAGE_HAS_ALPHA flag only for RGBA images. 2020-07-22 14:37:40 +03:00
Alibek Omarov 0db1a7743d engine: try to fix -Wmaybe-uninitialized that may be enabled with -Wuninitialized. Diagnostic is prone to false-positives, as compiler don't have enough data for this 2020-05-12 02:00:34 +03:00
Alibek Omarov a641488b98 engine: imagelib: img_bmp: add paranoid checks for estimated file size to not exceed real buffer. Needs proper testing. 2020-05-11 03:02:13 +03:00
Alibek Omarov 46b0590e4e engine: imagelib: refactor to use stdint.h definitions, use spaces for alignment instead of tabs 2020-05-11 02:28:04 +03:00
lewa_j deb7591d1e Fix SaveBMP 2020-04-25 21:19:58 +03:00
Alibek Omarov 3c8ce640c4 Merge neko/mathlib into master 2020-03-04 05:38:30 +03:00