diff --git a/base/sources/backends/android_net.c b/base/sources/backends/android_net.c index 521d23e2..489bf6a2 100644 --- a/base/sources/backends/android_net.c +++ b/base/sources/backends/android_net.c @@ -4,6 +4,7 @@ #include #include #include +#include ANativeActivity *iron_android_get_activity(void); jclass iron_android_find_class(JNIEnv *env, const char *name); @@ -30,7 +31,19 @@ void iron_net_request(const char *url_base, const char *url_path, const char *da jsize num_bytes = (*env)->GetArrayLength(env, bytes_array); jbyte *elements = (*env)->GetByteArrayElements(env, bytes_array, NULL); if (elements != NULL) { - callback((char *)elements, callbackdata); + + if (dst_path != NULL) { + FILE *file = fopen(dst_path, "wb"); + if (file != NULL) { + fwrite((char *)elements, 1, num_bytes, file); + fclose(file); + } + callback(NULL, callbackdata); + } + else { + callback((char *)elements, callbackdata); + } + // (*env)->ReleaseByteArrayElements(env, bytes_array, elements, JNI_ABORT); } diff --git a/base/sources/backends/android_system.c b/base/sources/backends/android_system.c index fe01201b..2c8a8730 100644 --- a/base/sources/backends/android_system.c +++ b/base/sources/backends/android_system.c @@ -1,5 +1,6 @@ #include "android_system.h" +#include "android_file_dialog.h" #include #include #include @@ -47,7 +48,7 @@ static const char *videoFormats[] = {"ts", NULL}; static __kernel_time_t start_sec = 0; static void (*resizeCallback)(int x, int y, void *data) = NULL; static void *resizeCallbackData = NULL; -static char ios_title[1024]; +char android_title[1024]; #ifdef WITH_GAMEPAD static float last_x = 0.0f; static float last_y = 0.0f; @@ -1265,3 +1266,7 @@ void iron_gamepad_rumble(int gamepad, float left, float right) {} bool _save_and_quit_callback_internal() { return false; } + +volatile int iron_exec_async_done = 1; + +void iron_exec_async(const char *path, char *argv[]) {} diff --git a/paint/plugins/io_exr/io_exr.c b/paint/plugins/io_exr/io_exr.c index 8b4cc262..49550a4d 100644 --- a/paint/plugins/io_exr/io_exr.c +++ b/paint/plugins/io_exr/io_exr.c @@ -1,17 +1,17 @@ -#include -#include -#include -#include -#include #include "iron_array.h" #include "iron_gpu.h" -void *gpu_create_texture_from_bytes(void *buffer, int width, int height, int format); -void console_info(char *s); +#include +#include +#include +#include +#include +void *gpu_create_texture_from_bytes(void *buffer, int width, int height, int format); +void console_info(char *s); buffer_t *iron_inflate(buffer_t *bytes, bool raw); typedef struct { char name[256]; - int pixel_type; + int pixel_type; } channel_t; void *io_exr_parse(uint8_t *buf, size_t buf_size) { @@ -22,17 +22,17 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { pos += 4; pos += 4; // version - int width = 0; - int height = 0; - int bits = 16; - int pixel_type = 0; + int width = 0; + int height = 0; + int bits = 16; + int pixel_type = 0; channel_t channels[4]; - int num_channels = 0; - int compression = 0; + int num_channels = 0; + int compression = 0; while (1) { char name[256]; - int i = 0; + int i = 0; while (buf[pos] != 0) { name[i++] = (char)buf[pos]; pos++; @@ -71,11 +71,15 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { break; } - int32_t chpixel_type = *(int32_t *)(buf + chpos); chpos += 4; - uint8_t pLinear = buf[chpos]; chpos += 1; // 1 byte - chpos += 3; // Skip reserved (3 bytes) - int32_t xSampling = *(int32_t *)(buf + chpos); chpos += 4; - int32_t ySampling = *(int32_t *)(buf + chpos); chpos += 4; + int32_t chpixel_type = *(int32_t *)(buf + chpos); + chpos += 4; + uint8_t pLinear = buf[chpos]; + chpos += 1; // 1 byte + chpos += 3; // Skip reserved (3 bytes) + int32_t xSampling = *(int32_t *)(buf + chpos); + chpos += 4; + int32_t ySampling = *(int32_t *)(buf + chpos); + chpos += 4; strcpy(channels[num_channels].name, chname); channels[num_channels].pixel_type = chpixel_type; @@ -88,7 +92,7 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { int32_t xMax = *(int32_t *)(buf + pos + 8); int32_t yMax = *(int32_t *)(buf + pos + 12); if (strcmp(name, "dataWindow") == 0) { - width = xMax - xMin + 1; + width = xMax - xMin + 1; height = yMax - yMin + 1; } } @@ -103,11 +107,11 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { } pixel_type = channels[0].pixel_type; - bits = (pixel_type == 1) ? 16 : 32; + bits = (pixel_type == 1) ? 16 : 32; uint32_t *line_offset_table = (uint32_t *)malloc(height * sizeof(uint32_t)); for (int y = 0; y < height; y++) { - uint32_t lo = *(uint32_t *)(buf + pos); + uint32_t lo = *(uint32_t *)(buf + pos); line_offset_table[y] = lo; pos += 8; } @@ -117,44 +121,50 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { int b_idx = -1; int a_idx = -1; for (int c = 0; c < num_channels; c++) { - if (strcmp(channels[c].name, "R") == 0) r_idx = c; - else if (strcmp(channels[c].name, "G") == 0) g_idx = c; - else if (strcmp(channels[c].name, "B") == 0) b_idx = c; - else if (strcmp(channels[c].name, "A") == 0) a_idx = c; + if (strcmp(channels[c].name, "R") == 0) + r_idx = c; + else if (strcmp(channels[c].name, "G") == 0) + g_idx = c; + else if (strcmp(channels[c].name, "B") == 0) + b_idx = c; + else if (strcmp(channels[c].name, "A") == 0) + a_idx = c; } - bool is_16bit = bits == 16; - int channel_bytes = is_16bit ? 2 : 4; - size_t image_size = (size_t)width * height * 4 * channel_bytes; - uint8_t *pixels = (uint8_t *)malloc(image_size); - uint8_t *reordered = NULL; + bool is_16bit = bits == 16; + int channel_bytes = is_16bit ? 2 : 4; + size_t image_size = (size_t)width * height * 4 * channel_bytes; + uint8_t *pixels = (uint8_t *)malloc(image_size); + uint8_t *reordered = NULL; for (int y = 0; y < height; y++) { - uint32_t scan_line_pos = line_offset_table[y]; - uint32_t compressed_len = *(uint32_t *)(buf + scan_line_pos + 4); - uint32_t off = scan_line_pos + 8; - uint8_t *line_data = NULL; + uint32_t scan_line_pos = line_offset_table[y]; + uint32_t compressed_len = *(uint32_t *)(buf + scan_line_pos + 4); + uint32_t off = scan_line_pos + 8; + uint8_t *line_data = NULL; buffer_t *decomp; if (compression == 0) { // None line_data = buf + off; } + +#ifdef WITH_COMPRESS // else if (compression == 1) {} // RLE else if (compression == 2) { // ZIPS buffer_t compressed; compressed.buffer = buf + off; compressed.length = compressed.capacity = compressed_len; - decomp = iron_inflate(&compressed, false); - line_data = decomp->buffer; + decomp = iron_inflate(&compressed, false); + line_data = decomp->buffer; - uint8_t *t = line_data + 1; + uint8_t *t = line_data + 1; uint8_t *stop = line_data + decomp->length; - int p = line_data[0]; + int p = line_data[0]; while (t < stop) { - int d = *t; + int d = *t; int orig = (d - 128 + p) & 0xFF; - p = orig; - *t = (uint8_t)orig; + p = orig; + *t = (uint8_t)orig; ++t; } @@ -171,10 +181,11 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { line_data = reordered; } // else if (compression == 3) {} // ZIP +#endif if (line_data) { uint8_t *plane_starts[4]; - size_t plane_size = (size_t)width * channel_bytes; + size_t plane_size = (size_t)width * channel_bytes; for (int c = 0; c < num_channels; c++) { plane_starts[c] = line_data + (size_t)c * plane_size; } @@ -207,9 +218,9 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { float b = (b_idx >= 0 ? vals_f[b_idx] : r); float a = (a_idx >= 0 ? vals_f[a_idx] : 1.0f); - *(float *)(pixels + outi + 0) = r; - *(float *)(pixels + outi + 4) = g; - *(float *)(pixels + outi + 8) = b; + *(float *)(pixels + outi + 0) = r; + *(float *)(pixels + outi + 4) = g; + *(float *)(pixels + outi + 8) = b; *(float *)(pixels + outi + 12) = a; } } @@ -219,8 +230,8 @@ void *io_exr_parse(uint8_t *buf, size_t buf_size) { free(line_offset_table); buffer_t *b = (buffer_t *)malloc(sizeof(buffer_t)); - b->buffer = pixels; + b->buffer = pixels; b->length = b->capacity = (uint32_t)image_size; - int format = is_16bit ? GPU_TEXTURE_FORMAT_RGBA64 : GPU_TEXTURE_FORMAT_RGBA128; + int format = is_16bit ? GPU_TEXTURE_FORMAT_RGBA64 : GPU_TEXTURE_FORMAT_RGBA128; return gpu_create_texture_from_bytes(b, width, height, format); }