Jackalope / jrf (public) (License: GPLv3 or later version) (since 2019-11-21) (hash sha1)
Libriary for reading and writing resource files: vertices, indices, meshes, images, models and scene data.
Supports reading from filesystem as well as from zip files.
It uses unique binary container format for those resources.
It is used in tool for converting popular formats like wavefront .obj file, TARGA image to this container and also used in resource loader as part of graphics framework.

It requires jlib libriary (see my user repositories) and libzip.
It is possible to remove libzip dependency.
List of commits:
Subject Hash Author Date (UTC)
Convert array of images to image array. 6f3666370a02ddd127ba3f6515c68cfea5f50a6c Jackalope 2020-06-03 01:47:05
Wavefront obj file converter. c24ea785073b8362a9659e3f275f0329e4799a25 Jackalope 2020-06-03 01:45:56
Forget to add config to installation! 9eb91f41049b2f0dcda1442c1750da4266e97376 Jackalope 2020-06-01 16:26:51
Better config, solving some issues with linking to jrf. 11ab2d21090cf684c08954ffabea0fe317afcc0a Jackalope 2020-06-01 16:24:51
Link jrf-shared to jlib-shared and jrf-static to jrf-static. b965856e0f894aa48555b9ccfef812bd15d2e3a6 Jackalope 2020-06-01 16:23:26
Version 0.2.2 d6aaf170a2db27ddcd429a89fd873341ea8a0082 Jackalope 2020-05-31 23:47:23
Move definitions to configuration file. a7b28738de65520eddd08cbd5d8c958fa16eedbe Jackalope 2020-05-31 21:45:28
CMake: build both shared and static with JRF_SHARED and JRF_STATIC options. When is subdirectory, select only one instead. 0dc49150959af90cd9210367a61113eca85650eb Jackalope 2020-05-31 21:38:50
CMake: version check changed. 500bcbe11c7f1e418e5d8116e89654d160c8dbd6 Jackalope 2020-05-31 21:37:47
Reduced warnings. 865f2c52ed60c37c050a1033905bb2df278032a0 Jackalope 2020-05-27 15:03:07
Make "find_package(jlib 0.2.0 REQUIRED)" optional 58bfc04890fab24adf5fc84963cb1a3bca7a8706 Jackalope 2020-05-24 16:39:14
changed notice about native compilation 0ed7e9e5e72a2d13e8add619f7999a51634f8e9c Jackalope 2020-05-24 16:37:54
Version 0.2.1 02d30aa69e9026a3f96d8549a297fccfbefbda47 Jackalope 2020-05-24 14:31:31
Why there is Doxyfile? 16cf9fe9e64353a2a717668cc4083465e2f8dff5 Jackalope 2020-05-24 14:25:20
Add license notice to CMakeLists.txt db2e7f018714cd2643c7928a8cce966d3da25059 Jackalope 2020-05-24 14:23:39
Make zip functionality optional 8e4409ba503637e5981f98c4df39ff4d649351de Jackalope 2020-05-24 14:23:18
remove LTO option 9b39746de0abc22a2ae8d2ce8c2db253dd9ad71a Jackalope 2020-05-24 13:41:20
more lost changes c52ad1ddc9fe753cb2ec6f388e4a88f9dfb0fadf Jackalope 2020-05-24 13:30:51
added lost changes 1e60b3d0d8ecda7995f3a102257d8f3c0ca4b15e Jackalope 2020-05-24 13:27:42
CMake installation target 57ba69a5bc17124a96b401c20e68f1602345c4f7 Jackalope 2020-05-24 13:22:15
Commit 6f3666370a02ddd127ba3f6515c68cfea5f50a6c - Convert array of images to image array.
Author: Jackalope
Author date (UTC): 2020-06-03 01:47
Committer name: Jackalope
Committer date (UTC): 2020-06-04 20:57
Parent(s): c24ea785073b8362a9659e3f275f0329e4799a25
Signing key:
Tree: 9598dafb42be482a4ecd918f1b7503d39836d9c1
File Lines added Lines deleted
include/jrf/convert.h 13 2
src/convert.cpp 87 1
File include/jrf/convert.h changed (mode: 100644) (index e6b5751..386cc29)
20 20 #include "image.h" #include "image.h"
21 21 #include "result.h" #include "result.h"
22 22 #include <jlib/rarray.h> #include <jlib/rarray.h>
23 #include <jlib/string.h>
23 24
24 25 namespace jrf::convert { namespace jrf::convert {
25 26 /// @return possible values: SUCCESS, FILE_UNEXPECTED_EOF, /// @return possible values: SUCCESS, FILE_UNEXPECTED_EOF,
26 27 /// COLOR_MAP_UNSUPPORTED, IMAGE_DATA_TYPE_UNSUPPORTED /// COLOR_MAP_UNSUPPORTED, IMAGE_DATA_TYPE_UNSUPPORTED
27 28 /// TGA_RLE_UNSUPPORTED, PIXEL_SIZE_UNSUPPORTED /// TGA_RLE_UNSUPPORTED, PIXEL_SIZE_UNSUPPORTED
28 29 [[nodiscard]] Result [[nodiscard]] Result
29 from_tga(const jl::byte_array_ro &data, Image* p_dst);
30 from_tga(jl::byte_array_ro data, Image* p_out_image);
30 31
32 /// @brief Convert array of images to image array.
33 /// @param src Images with equal extent and equal format.
31 34 [[nodiscard]] Result [[nodiscard]] Result
32 add_alpha_channel(const Image &src, Image *p_dst);
35 to_array(jl::rarray<const Image> src, Image *p_out_image);
36
37 [[nodiscard]] Result
38 from_tga(jl::rarray<const char*> file_paths, Image *p_out_image,
39 size_t *p_out_err_file_i);
40
41
42 [[nodiscard]] Result
43 add_alpha_channel(const Image &src, Image *p_out_image);
33 44 } }
File src/convert.cpp changed (mode: 100644) (index 1c78579..2874c2a)
17 17 * along with this library. If not, see <https://www.gnu.org/licenses/> * along with this library. If not, see <https://www.gnu.org/licenses/>
18 18 */ */
19 19 #include <jrf/convert.h> #include <jrf/convert.h>
20 #include <jlib/fs.h>
20 21
21 22 struct TGA_header { struct TGA_header {
22 23 enum DataType : uint8_t { enum DataType : uint8_t {
 
... ... static_assert (offsetof(TGA_header,width) == 8+4, "for correct bytes reading");
44 45 static_assert (sizeof(TGA_header) == 18, "for correct bytes reading"); static_assert (sizeof(TGA_header) == 18, "for correct bytes reading");
45 46
46 47 [[nodiscard]] jrf::Result jrf::convert:: [[nodiscard]] jrf::Result jrf::convert::
47 from_tga(const jl::byte_array_ro &data, Image *p_dst) {
48 from_tga(jl::byte_array_ro data, Image *p_dst) {
48 49 TGA_header header; TGA_header header;
49 50 constexpr static const uint64_t HEADER_SIZE = sizeof(header); constexpr static const uint64_t HEADER_SIZE = sizeof(header);
50 51 if (data.count() < HEADER_SIZE) if (data.count() < HEADER_SIZE)
 
... ... from_tga(const jl::byte_array_ro &data, Image *p_dst) {
100 101 } while (p_p < p_end); } while (p_p < p_end);
101 102 return Result::SUCCESS; return Result::SUCCESS;
102 103 } }
104
103 105 [[nodiscard]] jrf::Result jrf::convert:: [[nodiscard]] jrf::Result jrf::convert::
104 106 add_alpha_channel(const Image &src, Image *p_dst) { add_alpha_channel(const Image &src, Image *p_dst) {
105 107 Image::Format result_format; Image::Format result_format;
 
... ... add_alpha_channel(const Image &src, Image *p_dst) {
125 127 } }
126 128 return Result::SUCCESS; return Result::SUCCESS;
127 129 } }
130
131 [[nodiscard]] jrf::Result jrf::convert::
132 to_array(const jl::rarray<const Image> src, Image *p_dst) {
133 auto fin_extent = src[0].extent;
134 fin_extent.depth = uint16_t(src.count());
135 if (not p_dst->init(fin_extent, src[0].format))
136 return Result::ALLOCATION_FAIL;
137 auto p = reinterpret_cast<uint8_t*>(p_dst->p_pixels);
138 for(uint16_t j = 0; j < src.count(); ++j) {
139 auto &image = src[j];
140 memcpy(p, image.p_pixels, image.size);
141 p = &p[image.size];
142 }
143 return Result::SUCCESS;
144 }
145
146 [[nodiscard]] jrf::Result jrf::convert::
147 from_tga(jl::rarray<const char*> files, Image *p_dst, size_t *p_err_i) {
148 Result res;
149 *p_err_i = 0;
150
151 if (files.count() == 0)
152 return Result::MISSING_ARGUMENTS;
153 if (files.count() > jrf::Image::DEPTH_LIMIT)
154 return Result::TOO_MANY_ARGUMENTS;
155
156 Image *p_ims_tmp;
157 if (not jl::allocate(&p_ims_tmp, files.count()))
158 return Result::ALLOCATION_FAIL;
159
160 size_t i = 0;
161 for (; i < files.count(); ++i) {
162 uint8_t *p_data;
163 uint64_t size;
164 if (not jfs::read_file(files[i], &p_data, &size)) {
165 fprintf(stderr, "Error while reading file: %s", jfs::error_str());
166 res = Result::FILE_OPEN_ERROR;
167 *p_err_i = i;
168 goto CANCEL_IM;
169 }
170 res = convert::from_tga({p_data,size}, &p_ims_tmp[uint16_t(i)]);
171 jl::deallocate(&p_data);
172 if (res != Result::SUCCESS) {
173 *p_err_i = i;
174 goto CANCEL_IM;
175 }
176 }
177 for (uint32_t j = 1; j < files.count(); ++j) {
178 auto &cim = p_ims_tmp[j];
179 auto &fim = p_ims_tmp[0];
180 if (cim.extent.width != fim.extent.width
181 or
182 cim.extent.height != fim.extent.height) {
183 res = Result::IMAGE_LAYERS_EXTENT_MISMATCH;
184 *p_err_i = i;
185 goto CANCEL_IM;
186 }
187 if (cim.format != fim.format) {
188 res = Result::IMAGE_LAYERS_FORMAT_MISMATCH;
189 *p_err_i = i;
190 goto CANCEL_IM;
191 }
192 }{
193 auto fin_extent = p_ims_tmp[0].extent;
194 fin_extent.depth = uint16_t(files.count());
195 if (not p_dst->init(fin_extent, p_ims_tmp[0].format)) {
196 res = jrf::Result::ALLOCATION_FAIL;
197 goto CANCEL_IM;
198 }{
199 auto p = reinterpret_cast<uint8_t*>(p_dst->p_pixels);
200 for(uint16_t j = 0; j < files.count(); ++j) {
201 auto &src = p_ims_tmp[j];
202 memcpy(p, src.p_pixels, src.size);
203 p = &p[src.size];
204 }
205 }
206 }
207 res = jrf::Result::SUCCESS;
208 CANCEL_IM:
209 for (uint32_t j = 0; j < i; ++j)
210 p_ims_tmp[j].destroy();
211 jl::deallocate(&p_ims_tmp);
212 return res;
213 }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jrf

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jrf

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jrf

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main