gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-support/png2asset/export.cpp
1 // This prevents windows build errors regarding the 'fopen' function
2 // Example: 'fopen': This function or variable may be unsafe.Consider using fopen_s instead.To disable deprecation, use _CRT_SECURE_NO_WARNINGS.See online help for details.
3 // More info: https://stackoverflow.com/questions/14386/fopen-deprecated-warning
4 // From bbbbbr: `Looks like some of the benefits are concurrency protection, but that probably isn't an issue for png2asset`
5 #ifdef _WIN32
6 #define _CRT_SECURE_NO_DEPRECATE
7 #endif
8
9 #include <vector>
10 #include <string>
11 #include <algorithm>
12 #include <cstring>
13 #include <set>
14 #include <stdio.h>
15 #include <fstream>
16 #include <cstdint>
17
18 #include "lodepng.h"
19 #include "mttile.h"
20
21 #include "cmp_int_color.h"
22 #include "metasprites.h"
23
24 #include "png2asset.h"
25 #include "png_image.h"
26 #include "export.h"
27 #include "image_utils.h"
28 #include "process_arguments.h"
29 #include "rgb_to_nes_lut.h"
30
31 using namespace std;
32
33
34 string extract_name(string const & name)
35 {
36 int p = name.find_last_of("/\\");
37 string res = (p > 0) ? name.substr(p + 1) : name;
38 p = name.find_first_of(".");
39 return (p > 0) ? res.substr(0, p) : res;
40 }
41
42
43 // Calculate some shared export settings (.c, .h, binary)
44 // This gets called at the start of each export output function
45 void calc_palette_and_tileset_export_size(PNG2AssetData* assetData, exportOptions_t* exportOptions) {
46
47 bool use_structs_with_source_tileset = (assetData->args->has_source_tilesets == true) && (assetData->args->use_structs == true);
48
49 // (source_tileset + use_structs) is a special combination for ZGB
50 if (use_structs_with_source_tileset) {
51 // Export all colors, including those from source tileset
52 exportOptions->color_start = 0;
53 exportOptions->color_count = (unsigned int)assetData->image.total_color_count;
54 } else {
55 // Otherwise default palette export behavior is to skip past/offset
56 // palettes that were present in the source tileset
57 exportOptions->color_start = assetData->args->source_total_color_count;
58 exportOptions->color_count = assetData->image.total_color_count - assetData->args->source_total_color_count;
59 }
60
61 // Tile export behavior is to always skip past/offset
62 // tiles that were present in the source tileset
63 exportOptions->tiles_start = assetData->args->source_tileset_size;
64 exportOptions->tiles_count = assetData->tiles.size() - assetData->args->source_tileset_size;
65
66 // When to export palette data:
67 // - Not using a source tileset : include all colors
68 // - Using a source tileset and there are extra colors : include only colors not present in source tileset
69 //
70 // AND it's not turned off via include_palettes = false
71 // exportOptions->has_palette_data_to_export = (assetData->args->include_palettes &&
72 // ((assetData->args->has_source_tilesets == false) || (exportOptions->color_count > 0)) );
73
74 exportOptions->has_palette_data_to_export = (assetData->args->include_palettes &
75 ((assetData->args->has_source_tilesets == false) || (exportOptions->color_count > 0) || (use_structs_with_source_tileset == true)));
76 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.