diff --git a/src/base/base_core.h b/src/base/base_core.h index 87add9df..cb8904bc 100644 --- a/src/base/base_core.h +++ b/src/base/base_core.h @@ -168,6 +168,7 @@ # define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x)) # define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c)) # define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c) +# define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x),(k),(c)) # define ins_atomic_u32_eval(x,c) InterlockedAdd((volatile LONG *)(x), 0) # define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x),(c)) # define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c)) @@ -390,6 +391,19 @@ typedef enum Corner } Corner; +typedef enum Dir2 +{ + Dir2_Invalid = -1, + Dir2_Left, + Dir2_Up, + Dir2_Right, + Dir2_Down, + Dir2_COUNT +} +Dir2; +#define axis2_from_dir2(d) (((d) & 1) ? Axis2_Y : Axis2_X) +#define side_from_dir2(d) (((d) < Dir2_Right) ? Side_Min : Side_Max) + //////////////////////////////// //~ rjf: Toolchain/Environment Enums diff --git a/src/base/base_entry_point.c b/src/base/base_entry_point.c index d8f9edee..325d1f83 100644 --- a/src/base/base_entry_point.c +++ b/src/base/base_entry_point.c @@ -48,9 +48,6 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum #if defined(CTRL_CORE_H) ctrl_init(); #endif -#if defined(DASM_H) - dasmi_init(); -#endif #if defined(OS_GRAPHICAL_H) os_graphical_init(); #endif diff --git a/src/base/base_inc.c b/src/base/base_inc.c index 684cb1f6..dec3ee53 100644 --- a/src/base/base_inc.c +++ b/src/base/base_inc.c @@ -15,4 +15,5 @@ #include "base_thread_context.c" #include "base_command_line.c" #include "base_markup.c" +#include "base_log.c" #include "base_entry_point.c" diff --git a/src/base/base_inc.h b/src/base/base_inc.h index 5757b895..40927620 100644 --- a/src/base/base_inc.h +++ b/src/base/base_inc.h @@ -17,6 +17,7 @@ #include "base_thread_context.h" #include "base_command_line.h" #include "base_markup.h" +#include "base_log.h" #include "base_entry_point.h" #endif // BASE_INC_H diff --git a/src/base/base_log.c b/src/base/base_log.c new file mode 100644 index 00000000..af7b25ec --- /dev/null +++ b/src/base/base_log.c @@ -0,0 +1,97 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +//////////////////////////////// +//~ rjf: Globals/Thread-Locals + +C_LINKAGE thread_static Log *log_active; +#if !BUILD_SUPPLEMENTARY_UNIT +C_LINKAGE thread_static Log *log_active = 0; +#endif + +//////////////////////////////// +//~ rjf: Log Creation/Selection + +internal Log * +log_alloc(void) +{ + Arena *arena = arena_alloc(); + Log *log = push_array(arena, Log, 1); + log->arena = arena; + return log; +} + +internal void +log_release(Log *log) +{ + arena_release(log->arena); +} + +internal void +log_select(Log *log) +{ + log_active = log; +} + +//////////////////////////////// +//~ rjf: Log Building/Clearing + +internal void +log_msg(String8 string) +{ + if(log_active != 0 && log_active->top_scope != 0) + { + String8 string_copy = push_str8_copy(log_active->arena, string); + str8_list_push(log_active->arena, &log_active->top_scope->strings, string_copy); + } +} + +internal void +log_msgf(char *fmt, ...) +{ + if(log_active != 0) + { + Temp scratch = scratch_begin(0, 0); + va_list args; + va_start(args, fmt); + String8 string = push_str8fv(scratch.arena, fmt, args); + log_msg(string); + va_end(args); + scratch_end(scratch); + } +} + +//////////////////////////////// +//~ rjf: Log Scopes + +internal void +log_scope_begin(void) +{ + if(log_active != 0) + { + U64 pos = arena_pos(log_active->arena); + LogScope *scope = push_array(log_active->arena, LogScope, 1); + scope->pos = pos; + SLLStackPush(log_active->top_scope, scope); + } +} + +internal String8 +log_scope_end(Arena *arena) +{ + String8 result = {0}; + if(log_active != 0) + { + LogScope *scope = log_active->top_scope; + if(scope != 0) + { + SLLStackPop(log_active->top_scope); + if(arena != 0) + { + result = str8_list_join(arena, &scope->strings, 0); + } + arena_pop_to(log_active->arena, scope->pos); + } + } + return result; +} diff --git a/src/base/base_log.h b/src/base/base_log.h new file mode 100644 index 00000000..ff4ac6e4 --- /dev/null +++ b/src/base/base_log.h @@ -0,0 +1,44 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef BASE_LOG_H +#define BASE_LOG_H + +//////////////////////////////// +//~ rjf: Log Types + +typedef struct LogScope LogScope; +struct LogScope +{ + LogScope *next; + U64 pos; + String8List strings; +}; + +typedef struct Log Log; +struct Log +{ + Arena *arena; + LogScope *top_scope; +}; + +//////////////////////////////// +//~ rjf: Log Creation/Selection + +internal Log *log_alloc(void); +internal void log_release(Log *log); +internal void log_select(Log *log); + +//////////////////////////////// +//~ rjf: Log Building + +internal void log_msg(String8 string); +internal void log_msgf(char *fmt, ...); + +//////////////////////////////// +//~ rjf: Log Scopes + +internal void log_scope_begin(void); +internal String8 log_scope_end(Arena *arena); + +#endif // BASE_LOG_H diff --git a/src/base/base_markup.h b/src/base/base_markup.h index 7ca2ab36..6696ff29 100644 --- a/src/base/base_markup.h +++ b/src/base/base_markup.h @@ -4,9 +4,9 @@ #ifndef BASE_MARKUP_H #define BASE_MARKUP_H -internal void thread_namef(char *fmt, ...); internal void thread_name(String8 string); +internal void thread_namef(char *fmt, ...); #define ThreadNameF(...) (ProfThreadName(__VA_ARGS__), thread_namef(__VA_ARGS__)) -#define ThreadName(str) (ProfThreadName("%s", str8_varg(str)), thread_name(str)) +#define ThreadName(str) (ProfThreadName("%.*s", str8_varg(str)), thread_name(str)) #endif // BASE_MARKUP_H diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index f96c8ed8..daa2e619 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -851,6 +851,15 @@ ctrl_init(void) ctrl_state->c2u_ring_base = push_array_no_zero(arena, U8, ctrl_state->c2u_ring_size); ctrl_state->c2u_ring_mutex = os_mutex_alloc(); ctrl_state->c2u_ring_cv = os_condition_variable_alloc(); + { + Temp scratch = scratch_begin(0, 0); + String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData); + String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path); + os_make_directory(user_data_folder); + ctrl_state->ctrl_thread_log_path = push_str8f(ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder); + os_write_data_to_file_path(ctrl_state->ctrl_thread_log_path, str8_zero()); + scratch_end(scratch); + } ctrl_state->ctrl_thread_entity_store = ctrl_entity_store_alloc(); ctrl_state->dmn_event_arena = arena_alloc(); ctrl_state->user_entry_point_arena = arena_alloc(); @@ -865,6 +874,7 @@ ctrl_init(void) ctrl_state->u2ms_ring_base = push_array(arena, U8, ctrl_state->u2ms_ring_size); ctrl_state->u2ms_ring_mutex = os_mutex_alloc(); ctrl_state->u2ms_ring_cv = os_condition_variable_alloc(); + ctrl_state->ctrl_thread_log = log_alloc(); ctrl_state->ctrl_thread = os_launch_thread(ctrl_thread__entry_point, 0, 0); ctrl_state->ms_thread_count = Clamp(1, os_logical_core_count()-1, 4); ctrl_state->ms_threads = push_array(arena, OS_Handle, ctrl_state->ms_thread_count); @@ -1737,12 +1747,14 @@ ctrl_thread__entry_point(void *p) ThreadNameF("[ctrl] thread"); ProfBeginFunction(); DMN_CtrlCtx *ctrl_ctx = dmn_ctrl_begin(); + log_select(ctrl_state->ctrl_thread_log); //- rjf: loop Temp scratch = scratch_begin(0, 0); for(;;) { temp_end(scratch); + log_scope_begin(); //- rjf: get next messages CTRL_MsgList msgs = ctrl_u2c_pop_msgs(scratch.arena); @@ -1781,6 +1793,9 @@ ctrl_thread__entry_point(void *p) } } } + + String8 log = log_scope_end(scratch.arena); + ctrl_thread__flush_log(log); } scratch_end(scratch); @@ -1923,6 +1938,22 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // rjf: grab first event DMN_EventNode *next_event_node = ctrl_state->first_dmn_event_node; + // rjf: log event + if(next_event_node != 0) CTRL_CtrlThreadLogScope + { + DMN_Event *ev = &next_event_node->v; + log_msgf("--- event ---\n"); + log_msgf("kind: %S\n", dmn_event_kind_string_table[ev->kind]); + log_msgf("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]); + log_msgf("process: [%I64u]\n", ev->process.u64[0]); + log_msgf("thread: [%I64u]\n", ev->thread.u64[0]); + log_msgf("module: [%I64u]\n", ev->module.u64[0]); + log_msgf("arch: %S\n", string_from_architecture(ev->arch)); + log_msgf("address: 0x%I64x\n", ev->address); + log_msgf("string: \"%S\"\n", ev->string); + log_msgf("ip_vaddr: 0x%I64x\n", ev->instruction_pointer); + } + // rjf: determine if we should filter B32 should_filter_event = 0; if(next_event_node != 0) @@ -2073,7 +2104,9 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // rjf: run for new events ProfScope("run for new events") { + CTRL_CtrlThreadLogScope log_msgf("{dmn_ctrl_run ..."); DMN_EventList events = dmn_ctrl_run(scratch.arena, ctrl_ctx, run_ctrls); + CTRL_CtrlThreadLogScope log_msgf("}\n"); for(DMN_EventNode *src_n = events.first; src_n != 0; src_n = src_n->next) { DMN_EventNode *dst_n = ctrl_state->free_dmn_event_node; @@ -2260,6 +2293,23 @@ ctrl_eval_memory_read(void *u, void *out, U64 addr, U64 size) return result; } +//- rjf: log flusher + +internal void +ctrl_thread__flush_log(String8 string) +{ + os_append_data_to_file_path(ctrl_state->ctrl_thread_log_path, string); +} + +internal void +ctrl_thread__end_and_flush_log(void) +{ + Temp scratch = scratch_begin(0, 0); + String8 log = log_scope_end(scratch.arena); + ctrl_thread__flush_log(log); + scratch_end(scratch); +} + //- rjf: msg kind implementations internal void @@ -2693,7 +2743,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) B32 hard_stop = 0; CTRL_EventCause hard_stop_cause = ctrl_event_cause_from_dmn_event_kind(event->kind); B32 use_stepping_logic = 0; - switch(event->kind) + CTRL_CtrlThreadLogScope switch(event->kind) { default:{}break; case DMN_EventKind_Error: @@ -2702,17 +2752,29 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) case DMN_EventKind_Trap: { hard_stop = 1; + log_msgf(">>> stepping >>> hard stop\n"); }break; case DMN_EventKind_Exception: case DMN_EventKind_Breakpoint: { use_stepping_logic = 1; + log_msgf(">>> stepping >>> exception or breakpoint - begin stepping logic\n"); }break; case DMN_EventKind_CreateProcess: { DMN_TrapChunkList new_traps = {0}; ctrl_thread__append_resolved_process_user_bp_traps(scratch.arena, CTRL_MachineID_Local, event->process, &msg->user_bps, &new_traps); + log_msgf(">>> stepping >>> create process -> resolve new BPs\n"); + for(DMN_TrapChunkNode *n = new_traps.first; n != 0; n = n->next) + { + for(U64 idx = 0; idx < n->count; idx += 1) + { + DMN_Trap *trap = &n->v[idx]; + log_msgf(" trap: {process:%I64d, vaddr:0x%I64x}\n", trap->process.u64[0], trap->vaddr); + } + } dmn_trap_chunk_list_concat_shallow_copy(scratch.arena, &joined_traps, &new_traps); + dmn_trap_chunk_list_concat_shallow_copy(scratch.arena, &user_traps, &new_traps); }break; case DMN_EventKind_LoadModule: { @@ -2720,6 +2782,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) ctrl_thread__append_resolved_module_user_bp_traps(scratch.arena, CTRL_MachineID_Local, event->process, event->module, &msg->user_bps, &new_traps); dmn_trap_chunk_list_concat_shallow_copy(scratch.arena, &joined_traps, &new_traps); dmn_trap_chunk_list_concat_shallow_copy(scratch.arena, &user_traps, &new_traps); + log_msgf(">>> stepping >>> load module -> resolve new BPs\n"); }break; } @@ -2923,7 +2986,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) // CTRL_Entity *thread = ctrl_entity_from_machine_id_handle(ctrl_state->ctrl_thread_entity_store, CTRL_MachineID_Local, event->thread); Architecture arch = thread->arch; - U64 thread_rip_vaddr = dmn_rsp_from_thread(event->thread); + U64 thread_rip_vaddr = dmn_rip_from_thread(event->thread); DMN_Handle module = {0}; String8 module_name = {0}; U64 module_base_vaddr = 0; @@ -2991,7 +3054,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) B32 hit_trap_net_bp = 0; B32 hit_conditional_bp_but_filtered = 0; CTRL_TrapFlags hit_trap_flags = 0; - if(!hard_stop && use_stepping_logic) + if(!hard_stop && use_stepping_logic) CTRL_CtrlThreadLogScope { if(event->kind == DMN_EventKind_Breakpoint) { @@ -3093,11 +3156,13 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) { hit_user_bp = 0; hit_conditional_bp_but_filtered = 1; + log_msgf(">>> stepping >>> conditional breakpoint hit, but condition eval'd to 0, and so filtered\n"); } else { hit_user_bp = 1; hit_conditional_bp_but_filtered = 0; + log_msgf(">>> stepping >>> conditional breakpoint hit\n"); break; } } @@ -3118,6 +3183,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) } } + log_msgf(">>> stepping >>> stepping logic - BP event -> hit_user_bp: %i\n", hit_user_bp); + log_msgf(">>> stepping >>> stepping logic - BP event -> hit_entry: %i\n", hit_entry); temp_end(temp); } } @@ -3351,6 +3418,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) { stage_stop_cause = CTRL_EventCause_Finished; } + log_msgf(">>> stepping >>> stage stop cause -> %i\n", stage_stop_cause); if(stage_stop_cause != CTRL_EventCause_Null) { stop_event = event; diff --git a/src/ctrl/ctrl_core.h b/src/ctrl/ctrl_core.h index 879b404b..2c078221 100644 --- a/src/ctrl/ctrl_core.h +++ b/src/ctrl/ctrl_core.h @@ -514,7 +514,9 @@ struct CTRL_State OS_Handle c2u_ring_cv; // rjf: ctrl thread state + String8 ctrl_thread_log_path; OS_Handle ctrl_thread; + Log *ctrl_thread_log; CTRL_EntityStore *ctrl_thread_entity_store; Arena *dmn_event_arena; DMN_EventNode *first_dmn_event_node; @@ -551,6 +553,11 @@ read_only global CTRL_Entity ctrl_entity_nil = &ctrl_entity_nil, }; +//////////////////////////////// +//~ rjf: Logging Markup + +#define CTRL_CtrlThreadLogScope DeferLoop(log_scope_begin(), ctrl_thread__end_and_flush_log()) + //////////////////////////////// //~ rjf: Basic Type Functions @@ -708,6 +715,10 @@ internal DMN_Event *ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ //- rjf: eval helpers internal B32 ctrl_eval_memory_read(void *u, void *out, U64 addr, U64 size); +//- rjf: log flusher +internal void ctrl_thread__flush_log(String8 string); +internal void ctrl_thread__end_and_flush_log(void); + //- rjf: msg kind implementations internal void ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__attach(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); diff --git a/src/dasm_cache/dasm_cache.c b/src/dasm_cache/dasm_cache.c index 7bc0ec02..75b694c9 100644 --- a/src/dasm_cache/dasm_cache.c +++ b/src/dasm_cache/dasm_cache.c @@ -13,6 +13,21 @@ #include "third_party/udis86/libudis86/syn.c" #include "third_party/udis86/libudis86/udis86.c" +//////////////////////////////// +//~ rjf: Parameter Type Functions + +internal B32 +dasm_params_match(DASM_Params *a, DASM_Params *b) +{ + B32 result = (a->vaddr == b->vaddr && + a->arch == b->arch && + a->style_flags == b->style_flags && + a->syntax == b->syntax && + a->base_vaddr == b->base_vaddr && + str8_match(a->exe_path, b->exe_path, 0)); + return result; +} + //////////////////////////////// //~ rjf: Instruction Type Functions @@ -103,7 +118,7 @@ dasm_init(void) { dasm_shared->parse_threads[idx] = os_launch_thread(dasm_parse_thread__entry_point, (void *)idx, 0); } - dasm_shared->evictor_thread = os_launch_thread(dasm_evictor_thread__entry_point, 0, 0); + dasm_shared->evictor_detector_thread = os_launch_thread(dasm_evictor_detector_thread__entry_point, 0, 0); } //////////////////////////////// @@ -134,16 +149,9 @@ dasm_scope_open(void) dasm_tctx = push_array(arena, DASM_TCTX, 1); dasm_tctx->arena = arena; } - DASM_Scope *scope = dasm_tctx->free_scope; - if(scope != 0) - { - SLLStackPop(dasm_tctx->free_scope); - } - else - { - scope = push_array_no_zero(dasm_tctx->arena, DASM_Scope, 1); - } - MemoryZeroStruct(scope); + U64 base_pos = arena_pos(dasm_tctx->arena); + DASM_Scope *scope = push_array(dasm_tctx->arena, DASM_Scope, 1); + scope->base_pos = base_pos; return scope; } @@ -161,43 +169,27 @@ dasm_scope_close(DASM_Scope *scope) { for(DASM_Node *n = slot->first; n != 0; n = n->next) { - if(u128_match(t->hash, n->hash) && - t->addr == n->addr && - t->arch == n->arch && - t->style_flags == n->style_flags && - t->syntax == n->syntax) + if(u128_match(t->hash, n->hash) && dasm_params_match(&t->params, &n->params)) { ins_atomic_u64_dec_eval(&n->scope_ref_count); break; } } } - SLLStackPush(dasm_tctx->free_touch, t); } - SLLStackPush(dasm_tctx->free_scope, scope); + arena_pop_to(dasm_tctx->arena, scope->base_pos); } internal void dasm_scope_touch_node__stripe_r_guarded(DASM_Scope *scope, DASM_Node *node) { - DASM_Touch *touch = dasm_tctx->free_touch; + DASM_Touch *touch = push_array(dasm_tctx->arena, DASM_Touch, 1); ins_atomic_u64_inc_eval(&node->scope_ref_count); ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds()); ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, dasm_user_clock_idx()); - if(touch != 0) - { - SLLStackPop(dasm_tctx->free_touch); - } - else - { - touch = push_array_no_zero(dasm_tctx->arena, DASM_Touch, 1); - } - MemoryZeroStruct(touch); touch->hash = node->hash; - touch->addr = node->addr; - touch->arch = node->arch; - touch->style_flags = node->style_flags; - touch->syntax = node->syntax; + MemoryCopyStruct(&touch->params, &node->params); + touch->params.exe_path = push_str8_copy(dasm_tctx->arena, touch->params.exe_path); SLLStackPush(scope->top_touch, touch); } @@ -205,7 +197,7 @@ dasm_scope_touch_node__stripe_r_guarded(DASM_Scope *scope, DASM_Node *node) //~ rjf: Cache Lookups internal DASM_Info -dasm_info_from_hash_addr_arch_style(DASM_Scope *scope, U128 hash, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax) +dasm_info_from_hash_params(DASM_Scope *scope, U128 hash, DASM_Params *params) { DASM_Info info = {0}; if(!u128_match(hash, u128_zero())) @@ -219,11 +211,7 @@ dasm_info_from_hash_addr_arch_style(DASM_Scope *scope, U128 hash, U64 addr, Arch { for(DASM_Node *n = slot->first; n != 0; n = n->next) { - if(u128_match(hash, n->hash) && - addr == n->addr && - arch == n->arch && - style_flags == n->style_flags && - syntax == n->syntax) + if(u128_match(hash, n->hash) && dasm_params_match(params, &n->params)) { MemoryCopyStruct(&info, &n->info); found = 1; @@ -240,11 +228,7 @@ dasm_info_from_hash_addr_arch_style(DASM_Scope *scope, U128 hash, U64 addr, Arch DASM_Node *node = 0; for(DASM_Node *n = slot->first; n != 0; n = n->next) { - if(u128_match(hash, n->hash) && - addr == n->addr && - arch == n->arch && - style_flags == n->style_flags && - syntax == n->syntax) + if(u128_match(hash, n->hash) && dasm_params_match(params, &n->params)) { node = n; break; @@ -264,30 +248,29 @@ dasm_info_from_hash_addr_arch_style(DASM_Scope *scope, U128 hash, U64 addr, Arch MemoryZeroStruct(node); DLLPushBack(slot->first, slot->last, node); node->hash = hash; - node->addr = addr; - node->arch = arch; - node->style_flags = style_flags; - node->syntax = syntax; + MemoryCopyStruct(&node->params, params); + // TODO(rjf): need to make this releasable - currently all exe_paths just leak + node->params.exe_path = push_str8_copy(stripe->arena, node->params.exe_path); node_is_new = 1; } } } if(node_is_new) { - dasm_u2p_enqueue_req(hash, addr, arch, style_flags, syntax, max_U64); + dasm_u2p_enqueue_req(hash, params, max_U64); } } return info; } internal DASM_Info -dasm_info_from_key_addr_arch_style(DASM_Scope *scope, U128 key, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax, U128 *hash_out) +dasm_info_from_key_params(DASM_Scope *scope, U128 key, DASM_Params *params, U128 *hash_out) { DASM_Info result = {0}; for(U64 rewind_idx = 0; rewind_idx < 2; rewind_idx += 1) { U128 hash = hs_hash_from_key(key, rewind_idx); - result = dasm_info_from_hash_addr_arch_style(scope, hash, addr, arch, style_flags, syntax); + result = dasm_info_from_hash_params(scope, hash, params); if(result.insts.count != 0) { if(hash_out) @@ -304,21 +287,26 @@ dasm_info_from_key_addr_arch_style(DASM_Scope *scope, U128 key, U64 addr, Archit //~ rjf: Parse Threads internal B32 -dasm_u2p_enqueue_req(U128 hash, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax, U64 endt_us) +dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us) { B32 good = 0; OS_MutexScope(dasm_shared->u2p_ring_mutex) for(;;) { U64 unconsumed_size = dasm_shared->u2p_ring_write_pos - dasm_shared->u2p_ring_read_pos; U64 available_size = dasm_shared->u2p_ring_size - unconsumed_size; - if(available_size >= sizeof(hash)+sizeof(addr)+sizeof(arch)) + if(available_size >= sizeof(hash)+sizeof(U64)+sizeof(Architecture)+sizeof(DASM_StyleFlags)+sizeof(DASM_Syntax)+sizeof(U64)+sizeof(U64)+params->exe_path.size) { good = 1; dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &hash); - dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &addr); - dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &arch); - dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &style_flags); - dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &syntax); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->vaddr); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->arch); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->style_flags); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->syntax); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->base_vaddr); + dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, ¶ms->exe_path.size); + dasm_shared->u2p_ring_write_pos += ring_write(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, params->exe_path.str, params->exe_path.size); + dasm_shared->u2p_ring_write_pos += 7; + dasm_shared->u2p_ring_write_pos -= dasm_shared->u2p_ring_write_pos%8; break; } if(os_now_microseconds() >= endt_us) @@ -335,18 +323,24 @@ dasm_u2p_enqueue_req(U128 hash, U64 addr, Architecture arch, DASM_StyleFlags sty } internal void -dasm_u2p_dequeue_req(U128 *hash_out, U64 *addr_out, Architecture *arch_out, DASM_StyleFlags *style_flags_out, DASM_Syntax *syntax_out) +dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out) { OS_MutexScope(dasm_shared->u2p_ring_mutex) for(;;) { U64 unconsumed_size = dasm_shared->u2p_ring_write_pos - dasm_shared->u2p_ring_read_pos; - if(unconsumed_size >= sizeof(*hash_out)+sizeof(*addr_out)+sizeof(*arch_out)) + if(unconsumed_size >= sizeof(*hash_out)+sizeof(U64)+sizeof(Architecture)+sizeof(DASM_StyleFlags)+sizeof(DASM_Syntax)+sizeof(U64)+sizeof(U64)) { dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, hash_out); - dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, addr_out); - dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, arch_out); - dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, style_flags_out); - dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, syntax_out); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->vaddr); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->arch); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->style_flags); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->syntax); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->base_vaddr); + dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->exe_path.size); + params_out->exe_path.str = push_array(arena, U8, params_out->exe_path.size); + dasm_shared->u2p_ring_read_pos += ring_read(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, params_out->exe_path.str, params_out->exe_path.size); + dasm_shared->u2p_ring_read_pos += 7; + dasm_shared->u2p_ring_read_pos -= dasm_shared->u2p_ring_read_pos%8; break; } os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64); @@ -364,12 +358,12 @@ dasm_parse_thread__entry_point(void *p) //- rjf: get next request U128 hash = {0}; - U64 addr = 0; - Architecture arch = Architecture_Null; - DASM_StyleFlags style_flags = 0; - DASM_Syntax syntax = DASM_Syntax_Intel; - dasm_u2p_dequeue_req(&hash, &addr, &arch, &style_flags, &syntax); + DASM_Params params = {0}; + dasm_u2p_dequeue_req(scratch.arena, &hash, ¶ms); + U64 change_gen = fs_change_gen(); HS_Scope *hs_scope = hs_scope_open(); + DBGI_Scope *dbgi_scope = dbgi_scope_open(); + TXT_Scope *txt_scope = txt_scope_open(); //- rjf: unpack hash U64 slot_idx = hash.u64[1]%dasm_shared->slots_count; @@ -383,11 +377,7 @@ dasm_parse_thread__entry_point(void *p) { for(DASM_Node *n = slot->first; n != 0; n = n->next) { - if(u128_match(n->hash, hash) && - n->addr == addr && - n->arch == arch && - n->style_flags == style_flags && - n->syntax == syntax) + if(u128_match(n->hash, hash) && dasm_params_match(&n->params, ¶ms)) { got_task = !ins_atomic_u32_eval_cond_assign(&n->is_working, 1, 0); break; @@ -395,6 +385,14 @@ dasm_parse_thread__entry_point(void *p) } } + //- rjf: get dbg info + DBGI_Parse *dbgi = &dbgi_parse_nil; + if(got_task && params.exe_path.size != 0) + { + dbgi = dbgi_parse_from_exe_path(dbgi_scope, params.exe_path, max_U64); + } + RDI_Parsed *rdi = &dbgi->rdi; + //- rjf: hash -> data String8 data = {0}; if(got_task) @@ -402,12 +400,12 @@ dasm_parse_thread__entry_point(void *p) data = hs_data_from_hash(hs_scope, hash); } - //- rjf: data * arch * addr -> decode artifacts + //- rjf: data * arch * addr * dbg -> decode artifacts DASM_InstChunkList inst_list = {0}; String8List inst_strings = {0}; if(got_task) { - switch(arch) + switch(params.arch) { default:{}break; @@ -418,14 +416,15 @@ dasm_parse_thread__entry_point(void *p) // rjf: grab context struct ud udc; ud_init(&udc); - ud_set_mode(&udc, bit_size_from_arch(arch)); - ud_set_pc(&udc, addr); + ud_set_mode(&udc, bit_size_from_arch(params.arch)); + ud_set_pc(&udc, params.vaddr); ud_set_input_buffer(&udc, data.str, data.size); ud_set_vendor(&udc, UD_VENDOR_ANY); - ud_set_syntax(&udc, syntax == DASM_Syntax_Intel ? UD_SYN_INTEL : UD_SYN_ATT); + ud_set_syntax(&udc, params.syntax == DASM_Syntax_Intel ? UD_SYN_INTEL : UD_SYN_ATT); // rjf: disassemble - U64 byte_process_start_off = 0; + RDI_SourceFile *last_file = &rdi_source_file_nil; + RDI_Line *last_line = 0; for(U64 off = 0; off < data.size;) { // rjf: disassemble one instruction @@ -438,15 +437,90 @@ dasm_parse_thread__entry_point(void *p) // rjf: analyze struct ud_operand *first_op = (struct ud_operand *)ud_insn_opr(&udc, 0); U64 rel_voff = (first_op != 0 && first_op->type == UD_OP_JIMM) ? ud_syn_rel_target(&udc, first_op) : 0; + U64 jump_dst_vaddr = rel_voff; + + // rjf: push strings derived from voff -> line info + if(params.style_flags & DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines) + { + if(dbgi != &dbgi_parse_nil) + { + U64 voff = (params.vaddr+off) - params.base_vaddr; + U32 unit_idx = rdi_vmap_idx_from_voff(rdi->unit_vmap, rdi->unit_vmap_count, voff); + RDI_Unit *unit = rdi_element_from_idx(rdi, units, unit_idx); + RDI_ParsedLineInfo unit_line_info = {0}; + rdi_line_info_from_unit(rdi, unit, &unit_line_info); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff); + if(line_info_idx < unit_line_info.count) + { + RDI_Line *line = &unit_line_info.lines[line_info_idx]; + RDI_SourceFile *file = rdi_element_from_idx(rdi, source_files, line->file_idx); + String8 file_normalized_full_path = {0}; + file_normalized_full_path.str = rdi_string_from_idx(rdi, file->normal_full_path_string_idx, &file_normalized_full_path.size); + if(file != last_file) + { + if(params.style_flags & DASM_StyleFlag_SourceFilesNames && + file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0) + { + DASM_Inst inst = {0}; + dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); + str8_list_pushf(scratch.arena, &inst_strings, "> %S", file_normalized_full_path); + } + if(params.style_flags & DASM_StyleFlag_SourceFilesNames && file->normal_full_path_string_idx == 0) + { + DASM_Inst inst = {0}; + dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); + str8_list_pushf(scratch.arena, &inst_strings, ">"); + } + last_file = file; + } + if(line && line != last_line && file->normal_full_path_string_idx != 0 && + params.style_flags & DASM_StyleFlag_SourceLines && + file_normalized_full_path.size != 0) + { + FileProperties props = os_properties_from_file_path(file_normalized_full_path); + if(props.modified != 0) + { + // TODO(rjf): need redirection path - this may map to a different path on the local machine, + // need frontend to communicate path remapping info to this layer + U128 key = fs_key_from_path(file_normalized_full_path); + TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path); + U64 endt_us = max_U64; + U128 hash = {0}; + TXT_TextInfo text_info = {0}; + for(;os_now_microseconds() <= endt_us;) + { + text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + if(!u128_match(hash, u128_zero())) + { + break; + } + } + if(0 < line->line_num && line->line_num < text_info.lines_count) + { + String8 data = hs_data_from_hash(hs_scope, hash); + String8 line_text = str8_skip_chop_whitespace(str8_substr(data, text_info.lines_ranges[line->line_num-1])); + if(line_text.size != 0) + { + DASM_Inst inst = {0}; + dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); + str8_list_pushf(scratch.arena, &inst_strings, "> %S", line_text); + } + } + } + last_line = line; + } + } + } + } // rjf: push String8 addr_part = {0}; - if(style_flags & DASM_StyleFlag_Addresses) + if(params.style_flags & DASM_StyleFlag_Addresses) { - addr_part = push_str8f(scratch.arena, "%016I64X ", addr+off); + addr_part = push_str8f(scratch.arena, "%s%016I64X ", dbgi != &dbgi_parse_nil ? " " : "", params.vaddr+off); } String8 code_bytes_part = {0}; - if(style_flags & DASM_StyleFlag_CodeBytes) + if(params.style_flags & DASM_StyleFlag_CodeBytes) { String8List code_bytes_strings = {0}; str8_list_push(scratch.arena, &code_bytes_strings, str8_lit("{")); @@ -464,7 +538,24 @@ dasm_parse_thread__entry_point(void *p) str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" ")); code_bytes_part = str8_list_join(scratch.arena, &code_bytes_strings, 0); } - String8 inst_string = push_str8f(scratch.arena, "%S%S%s", addr_part, code_bytes_part, udc.asm_buf); + String8 symbol_part = {0}; + if(jump_dst_vaddr != 0 && dbgi != &dbgi_parse_nil && params.style_flags & DASM_StyleFlag_SymbolNames) + { + RDI_U32 scope_idx = rdi_vmap_idx_from_voff(rdi->scope_vmap, rdi->scope_vmap_count, jump_dst_vaddr-params.base_vaddr); + if(scope_idx != 0) + { + RDI_Scope *scope = rdi_element_from_idx(rdi, scopes, scope_idx); + RDI_U32 procedure_idx = scope->proc_idx; + RDI_Procedure *procedure = rdi_element_from_idx(rdi, procedures, procedure_idx); + String8 procedure_name = {0}; + procedure_name.str = rdi_string_from_idx(rdi, procedure->name_string_idx, &procedure_name.size); + if(procedure_name.size != 0) + { + symbol_part = push_str8f(scratch.arena, " (%S)", procedure_name); + } + } + } + String8 inst_string = push_str8f(scratch.arena, "%S%S%s%S", addr_part, code_bytes_part, udc.asm_buf, symbol_part); DASM_Inst inst = {off, rel_voff, r1u64(inst_strings.total_size + inst_strings.node_count, inst_strings.total_size + inst_strings.node_count + inst_string.size)}; dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); @@ -495,10 +586,11 @@ dasm_parse_thread__entry_point(void *p) { hash.u64[0], hash.u64[1], - addr, - (U64)arch, - (U64)style_flags, - (U64)syntax, + params.vaddr, + (U64)params.arch, + (U64)params.style_flags, + (U64)params.syntax, + (U64)dbgi, 0x4d534144, }; text_key = hs_hash_from_data(str8((U8 *)hash_data, sizeof(hash_data))); @@ -518,14 +610,18 @@ dasm_parse_thread__entry_point(void *p) { for(DASM_Node *n = slot->first; n != 0; n = n->next) { - if(u128_match(n->hash, hash) && - addr == n->addr && - arch == n->arch && - style_flags == n->style_flags && - syntax == n->syntax) + if(u128_match(n->hash, hash) && dasm_params_match(&n->params, ¶ms)) { n->info_arena = info_arena; MemoryCopyStruct(&n->info, &info); + if(dbgi != &dbgi_parse_nil && params.style_flags & (DASM_StyleFlag_SourceLines|DASM_StyleFlag_SourceFilesNames)) + { + n->change_gen = change_gen; + } + else + { + n->change_gen = 0; + } ins_atomic_u32_eval_assign(&n->is_working, 0); ins_atomic_u64_inc_eval(&n->load_count); break; @@ -533,24 +629,29 @@ dasm_parse_thread__entry_point(void *p) } } + txt_scope_close(txt_scope); + dbgi_scope_close(dbgi_scope); hs_scope_close(hs_scope); scratch_end(scratch); } } //////////////////////////////// -//~ rjf: Evictor Threads +//~ rjf: Evictor/Detector Thread internal void -dasm_evictor_thread__entry_point(void *p) +dasm_evictor_detector_thread__entry_point(void *p) { - ThreadNameF("[dasm] evictor thread"); + ThreadNameF("[dasm] evictor/detector thread"); for(;;) { + U64 change_gen = fs_change_gen(); U64 check_time_us = os_now_microseconds(); U64 check_time_user_clocks = dasm_user_clock_idx(); U64 evict_threshold_us = 10*1000000; + U64 retry_threshold_us = 1*1000000; U64 evict_threshold_user_clocks = 10; + U64 retry_threshold_user_clocks = 10; for(U64 slot_idx = 0; slot_idx < dasm_shared->slots_count; slot_idx += 1) { U64 stripe_idx = slot_idx%dasm_shared->stripes_count; @@ -570,6 +671,13 @@ dasm_evictor_thread__entry_point(void *p) slot_has_work = 1; break; } + if(n->change_gen != 0 && n->change_gen != change_gen && + n->last_time_requested_us+retry_threshold_us <= check_time_us && + n->last_user_clock_idx_requested+retry_threshold_user_clocks <= check_time_user_clocks) + { + slot_has_work = 1; + break; + } } } if(slot_has_work) OS_MutexScopeW(stripe->rw_mutex) @@ -590,10 +698,19 @@ dasm_evictor_thread__entry_point(void *p) } SLLStackPush(stripe->free_node, n); } + if(n->change_gen != 0 && n->change_gen != change_gen && + n->last_time_requested_us+retry_threshold_us <= check_time_us && + n->last_user_clock_idx_requested+retry_threshold_user_clocks <= check_time_user_clocks) + { + if(dasm_u2p_enqueue_req(n->hash, &n->params, max_U64)) + { + n->last_time_requested_us = os_now_microseconds(); + n->last_user_clock_idx_requested = check_time_user_clocks; + } + } } } - os_sleep_milliseconds(5); } - os_sleep_milliseconds(1000); + os_sleep_milliseconds(100); } } diff --git a/src/dasm_cache/dasm_cache.h b/src/dasm_cache/dasm_cache.h index 6daa60b1..3e5d4e9f 100644 --- a/src/dasm_cache/dasm_cache.h +++ b/src/dasm_cache/dasm_cache.h @@ -10,8 +10,11 @@ typedef U32 DASM_StyleFlags; enum { - DASM_StyleFlag_Addresses = (1<<0), - DASM_StyleFlag_CodeBytes = (1<<1), + DASM_StyleFlag_Addresses = (1<<0), + DASM_StyleFlag_CodeBytes = (1<<1), + DASM_StyleFlag_SourceFilesNames = (1<<2), + DASM_StyleFlag_SourceLines = (1<<3), + DASM_StyleFlag_SymbolNames = (1<<4), }; typedef enum DASM_Syntax @@ -22,6 +25,20 @@ typedef enum DASM_Syntax } DASM_Syntax; +//////////////////////////////// +//~ rjf: Disassembling Parameters Bundle + +typedef struct DASM_Params DASM_Params; +struct DASM_Params +{ + U64 vaddr; + Architecture arch; + DASM_StyleFlags style_flags; + DASM_Syntax syntax; + U64 base_vaddr; + String8 exe_path; +}; + //////////////////////////////// //~ rjf: Instruction Types @@ -80,10 +97,10 @@ struct DASM_Node // rjf: key U128 hash; - U64 addr; - Architecture arch; - DASM_StyleFlags style_flags; - DASM_Syntax syntax; + DASM_Params params; + + // rjf: generations + U64 change_gen; // rjf: value Arena *info_arena; @@ -95,6 +112,8 @@ struct DASM_Node U64 last_time_touched_us; U64 last_user_clock_idx_touched; U64 load_count; + U64 last_time_requested_us; + U64 last_user_clock_idx_requested; }; typedef struct DASM_Slot DASM_Slot; @@ -121,10 +140,7 @@ struct DASM_Touch { DASM_Touch *next; U128 hash; - U64 addr; - Architecture arch; - DASM_StyleFlags style_flags; - DASM_Syntax syntax; + DASM_Params params; }; typedef struct DASM_Scope DASM_Scope; @@ -132,6 +148,7 @@ struct DASM_Scope { DASM_Scope *next; DASM_Touch *top_touch; + U64 base_pos; }; //////////////////////////////// @@ -141,8 +158,6 @@ typedef struct DASM_TCTX DASM_TCTX; struct DASM_TCTX { Arena *arena; - DASM_Scope *free_scope; - DASM_Touch *free_touch; }; //////////////////////////////// @@ -174,8 +189,8 @@ struct DASM_Shared U64 parse_thread_count; OS_Handle *parse_threads; - // rjf: evictor thread - OS_Handle evictor_thread; + // rjf: evictor/detector thread + OS_Handle evictor_detector_thread; }; //////////////////////////////// @@ -184,6 +199,11 @@ struct DASM_Shared thread_static DASM_TCTX *dasm_tctx = 0; global DASM_Shared *dasm_shared = 0; +//////////////////////////////// +//~ rjf: Parameter Type Functions + +internal B32 dasm_params_match(DASM_Params *a, DASM_Params *b); + //////////////////////////////// //~ rjf: Instruction Type Functions @@ -213,19 +233,19 @@ internal void dasm_scope_touch_node__stripe_r_guarded(DASM_Scope *scope, DASM_No //////////////////////////////// //~ rjf: Cache Lookups -internal DASM_Info dasm_info_from_hash_addr_arch_style(DASM_Scope *scope, U128 hash, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax); -internal DASM_Info dasm_info_from_key_addr_arch_style(DASM_Scope *scope, U128 key, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax, U128 *hash_out); +internal DASM_Info dasm_info_from_hash_params(DASM_Scope *scope, U128 hash, DASM_Params *params); +internal DASM_Info dasm_info_from_key_params(DASM_Scope *scope, U128 key, DASM_Params *params, U128 *hash_out); //////////////////////////////// //~ rjf: Parse Threads -internal B32 dasm_u2p_enqueue_req(U128 hash, U64 addr, Architecture arch, DASM_StyleFlags style_flags, DASM_Syntax syntax, U64 endt_us); -internal void dasm_u2p_dequeue_req(U128 *hash_out, U64 *addr_out, Architecture *arch_out, DASM_StyleFlags *style_flags_out, DASM_Syntax *syntax_out); +internal B32 dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us); +internal void dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out); internal void dasm_parse_thread__entry_point(void *p); //////////////////////////////// -//~ rjf: Evictor Threads +//~ rjf: Evictor/Detector Thread -internal void dasm_evictor_thread__entry_point(void *p); +internal void dasm_evictor_detector_thread__entry_point(void *p); #endif // DASM_CACHE_H diff --git a/src/dbgi/dbgi.c b/src/dbgi/dbgi.c index de5d7143..1a341c20 100644 --- a/src/dbgi/dbgi.c +++ b/src/dbgi/dbgi.c @@ -859,6 +859,13 @@ dbgi_parse_thread_entry_point(void *p) os_file_close(file); } + //- rjf: heuristically choose compression settings + B32 should_compress = 0; + if(og_dbg_props.size > MB(64)) + { + should_compress = 1; + } + //- rjf: raddbg file not up-to-date? we need to generate it if(do_task) { @@ -883,6 +890,10 @@ dbgi_parse_thread_entry_point(void *p) str8_list_pushf(scratch.arena, &opts.cmd_line, "raddbg"); str8_list_pushf(scratch.arena, &opts.cmd_line, "--convert"); str8_list_pushf(scratch.arena, &opts.cmd_line, "--quiet"); + if(should_compress) + { + str8_list_pushf(scratch.arena, &opts.cmd_line, "--compress"); + } //str8_list_pushf(scratch.arena, &opts.cmd_line, "--capture"); str8_list_pushf(scratch.arena, &opts.cmd_line, "--exe:%S", exe_path); str8_list_pushf(scratch.arena, &opts.cmd_line, "--pdb:%S", og_dbg_path); @@ -1020,15 +1031,72 @@ dbgi_parse_thread_entry_point(void *p) do_task = 0; } - //- rjf: parse raddbg info - RDI_Parsed rdi_parsed = dbgi_parse_nil.rdi; - U64 arch_addr_size = 8; + //- rjf: initial parse of raddbg info + RDI_Parsed rdi_parsed_maybe_compressed = dbgi_parse_nil.rdi; if(do_task) { - RDI_ParseStatus parse_status = rdi_parse((U8 *)raddbgi_file_base, raddbgi_file_props.size, &rdi_parsed); - if(rdi_parsed.top_level_info != 0) + RDI_ParseStatus parse_status = rdi_parse((U8 *)raddbgi_file_base, raddbgi_file_props.size, &rdi_parsed_maybe_compressed); + (void)parse_status; + } + + //- rjf: decompress, if necessary + RDI_Parsed rdi_parsed = rdi_parsed_maybe_compressed; + if(do_task) + { + U64 decompressed_size = raddbgi_file_props.size; + for(U64 dsec_idx = 0; dsec_idx < rdi_parsed_maybe_compressed.dsec_count; dsec_idx += 1) { - arch_addr_size = rdi_addr_size_from_arch(rdi_parsed.top_level_info->architecture); + decompressed_size += (rdi_parsed_maybe_compressed.dsecs[dsec_idx].unpacked_size - rdi_parsed_maybe_compressed.dsecs[dsec_idx].encoded_size); + } + if(decompressed_size > raddbgi_file_props.size) + { + U8 *decompressed_data = push_array_no_zero(parse_arena, U8, decompressed_size); + + // rjf: copy header + RDI_Header *src_header = (RDI_Header *)raddbgi_file_base; + RDI_Header *dst_header = (RDI_Header *)decompressed_data; + { + MemoryCopy(dst_header, src_header, sizeof(RDI_Header)); + } + + // rjf: copy & adjust sections for decompressed version + if(rdi_parsed_maybe_compressed.dsec_count != 0) + { + RDI_DataSection *dsec_base = (RDI_DataSection *)(decompressed_data + dst_header->data_section_off); + MemoryCopy(dsec_base, (U8 *)raddbgi_file_base + src_header->data_section_off, sizeof(RDI_DataSection) * rdi_parsed_maybe_compressed.dsec_count); + U64 off = dst_header->data_section_off + sizeof(RDI_DataSection) * rdi_parsed_maybe_compressed.dsec_count; + off += 7; + off -= off%8; + for(U64 idx = 0; idx < rdi_parsed_maybe_compressed.dsec_count; idx += 1) + { + dsec_base[idx].encoding = RDI_DataSectionEncoding_Unpacked; + dsec_base[idx].off = off; + dsec_base[idx].encoded_size = dsec_base[idx].unpacked_size; + off += dsec_base[idx].unpacked_size; + off += 7; + off -= off%8; + } + } + + // rjf: decompress sections into new decompressed file buffer + if(rdi_parsed_maybe_compressed.dsec_count != 0) + { + RDI_DataSection *src_first = rdi_parsed_maybe_compressed.dsecs; + RDI_DataSection *dst_first = (RDI_DataSection *)(decompressed_data + dst_header->data_section_off); + RDI_DataSection *src_opl = src_first + rdi_parsed_maybe_compressed.dsec_count; + RDI_DataSection *dst_opl = dst_first + rdi_parsed_maybe_compressed.dsec_count; + for(RDI_DataSection *src = src_first, *dst = dst_first; + src < src_opl && dst < dst_opl; + src += 1, dst += 1) + { + rr_lzb_simple_decode((U8*)raddbgi_file_base + src->off, src->encoded_size, + decompressed_data + dst->off, dst->unpacked_size); + } + } + + // rjf: re-parse + RDI_ParseStatus parse_status = rdi_parse(decompressed_data, decompressed_size, &rdi_parsed); + (void)parse_status; } } diff --git a/src/demon/demon_core.c b/src/demon/demon_core.c index 86c1c3c6..d2f3de2d 100644 --- a/src/demon/demon_core.c +++ b/src/demon/demon_core.c @@ -1,6 +1,11 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +//////////////////////////////// +//~ rjf: Generated Code + +#include "generated/demon.meta.c" + //////////////////////////////// //~ rjf: Basic Type Functions (Helpers, Implemented Once) diff --git a/src/demon/demon_core.mdesk b/src/demon/demon_core.mdesk index 3df0d2fd..c0d05ed7 100644 --- a/src/demon/demon_core.mdesk +++ b/src/demon/demon_core.mdesk @@ -61,6 +61,11 @@ DMN_ExceptionKindTable: COUNT } +@data(String8) dmn_event_kind_string_table: +{ + @expand(DMN_EventKindTable a) `str8_lit_comp("$(a.name)")` +} + @enum DMN_ErrorKind: { @expand(DMN_ErrorKindTable a) `$(a.name)`, @@ -78,3 +83,8 @@ DMN_ExceptionKindTable: @expand(DMN_ExceptionKindTable a) `$(a.name)`, COUNT } + +@data(String8) dmn_exception_kind_string_table: +{ + @expand(DMN_ExceptionKindTable a) `str8_lit_comp("$(a.name)")` +} diff --git a/src/demon/generated/demon.meta.c b/src/demon/generated/demon.meta.c index 32e20884..7c4791ea 100644 --- a/src/demon/generated/demon.meta.c +++ b/src/demon/generated/demon.meta.c @@ -4,5 +4,35 @@ //- GENERATED CODE C_LINKAGE_BEGIN +String8 dmn_event_kind_string_table[17] = +{ +str8_lit_comp("Null"), +str8_lit_comp("Error"), +str8_lit_comp("HandshakeComplete"), +str8_lit_comp("CreateProcess"), +str8_lit_comp("ExitProcess"), +str8_lit_comp("CreateThread"), +str8_lit_comp("ExitThread"), +str8_lit_comp("LoadModule"), +str8_lit_comp("UnloadModule"), +str8_lit_comp("Breakpoint"), +str8_lit_comp("Trap"), +str8_lit_comp("SingleStep"), +str8_lit_comp("Exception"), +str8_lit_comp("Halt"), +str8_lit_comp("Memory"), +str8_lit_comp("DebugString"), +str8_lit_comp("SetThreadName"), +}; + +String8 dmn_exception_kind_string_table[5] = +{ +str8_lit_comp("Null"), +str8_lit_comp("MemoryRead"), +str8_lit_comp("MemoryWrite"), +str8_lit_comp("MemoryExecute"), +str8_lit_comp("CppThrow"), +}; + C_LINKAGE_END diff --git a/src/demon/generated/demon.meta.h b/src/demon/generated/demon.meta.h index 1db2313d..732deb06 100644 --- a/src/demon/generated/demon.meta.h +++ b/src/demon/generated/demon.meta.h @@ -58,6 +58,8 @@ DMN_ExceptionKind_COUNT, } DMN_ExceptionKind; C_LINKAGE_BEGIN +extern String8 dmn_event_kind_string_table[17]; +extern String8 dmn_exception_kind_string_table[5]; C_LINKAGE_END #endif // DEMON_META_H diff --git a/src/demon/win32/demon_core_win32.c b/src/demon/win32/demon_core_win32.c index 42035c76..578edffa 100644 --- a/src/demon/win32/demon_core_win32.c +++ b/src/demon/win32/demon_core_win32.c @@ -2114,7 +2114,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) U64 total_string_size = 0; for(;total_string_size < KB(4);) { - U8 *buffer = push_array_no_zero(scratch.arena, U8, 256); + U8 *buffer = push_array(scratch.arena, U8, 256); B32 good_read = dmn_w32_process_read(process->handle, r1u64(read_addr, read_addr+256), buffer); if(good_read) { @@ -2136,6 +2136,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) break; } } + else + { + break; + } } } e->kind = DMN_EventKind_SetThreadName; diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index f3b2890c..908b4991 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -1798,6 +1798,9 @@ df_entity_alloc(DF_StateDeltaHistory *hist, DF_Entity *parent, DF_EntityKind kin df_state->kind_alloc_gens[kind] += 1; df_entity_notify_mutation(entity); + // rjf: log + log_msgf("new entity: %S $%I64d\n", df_g_entity_kind_display_string_table[kind], entity->id); + return entity; } @@ -1841,6 +1844,7 @@ df_entity_release(DF_StateDeltaHistory *hist, DF_Entity *entity) t->e = child; SLLQueuePush(first_task, last_task, t); } + log_msgf("end entity: %S $%I64d\n", df_g_entity_kind_display_string_table[task->e->kind], task->e->id); df_state_delta_history_push_struct_delta(hist, &task->e->first); df_state_delta_history_push_struct_delta(hist, &task->e->last); df_state_delta_history_push_struct_delta(hist, &task->e->next); @@ -5025,6 +5029,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie // TG_Key eval_type_key = tg_unwrapped_from_graph_rdi_key(parse_ctx->type_graph, parse_ctx->rdi, eval.type_key); TG_Kind eval_type_kind = tg_kind_from_key(eval_type_key); + String8 eval_string = push_str8_copy(arena, string); ////////////////////////////// //- rjf: make and push block for root @@ -5033,7 +5038,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie DF_EvalVizBlock *block = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Root, parent_key, key, depth); block->eval = eval; block->cfg_table = *cfg_table; - block->string = push_str8_copy(arena, string); + block->string = eval_string; block->visual_idx_range = r1u64(key.child_num-1, key.child_num+0); block->semantic_idx_range = r1u64(key.child_num-1, key.child_num+0); if(opt_member != 0) @@ -5156,7 +5161,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie expand_view_rule_cfg != &df_g_nil_cfg_val) ProfScope("build viz blocks for lens") { - expand_view_rule_spec->info.viz_block_prod(arena, scope, ctrl_ctx, parse_ctx, macro_map, eval_view, eval, cfg_table, parent_key, key, depth+1, expand_view_rule_cfg->last, list_out); + expand_view_rule_spec->info.viz_block_prod(arena, scope, ctrl_ctx, parse_ctx, macro_map, eval_view, eval, string, cfg_table, parent_key, key, depth+1, expand_view_rule_cfg->last, list_out); } ////////////////////////////// @@ -5176,6 +5181,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie DF_EvalVizBlock *last_vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Members, key, df_expand_key_make(df_hash_from_expand_key(key), 0), depth+1); { last_vb->eval = udt_eval; + last_vb->string = eval_string; last_vb->cfg_table = *cfg_table; last_vb->visual_idx_range = last_vb->semantic_idx_range = r1u64(0, filtered_data_members.count); } @@ -5231,6 +5237,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie DF_EvalVizBlock *last_vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_EnumMembers, key, df_expand_key_make(df_hash_from_expand_key(key), 0), depth+1); { last_vb->eval = udt_eval; + last_vb->string = eval_string; last_vb->cfg_table = *cfg_table; last_vb->visual_idx_range = last_vb->semantic_idx_range = r1u64(0, type->count); } @@ -5287,6 +5294,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie DF_EvalVizBlock *last_vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Links, key, df_expand_key_make(df_hash_from_expand_key(key), 0), depth+1); { last_vb->eval = udt_eval; + last_vb->string = eval_string; last_vb->cfg_table = *cfg_table; last_vb->link_member_type_key = link_member->type_key; last_vb->link_member_off = link_member->off; @@ -5350,6 +5358,7 @@ df_append_viz_blocks_for_parent__rec(Arena *arena, DBGI_Scope *scope, DF_EvalVie DF_EvalVizBlock *last_vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Elements, key, df_expand_key_make(df_hash_from_expand_key(key), 0), depth+1); { last_vb->eval = arr_eval; + last_vb->string = eval_string; last_vb->cfg_table = *cfg_table; last_vb->visual_idx_range = last_vb->semantic_idx_range = r1u64(0, array_count); } @@ -5411,10 +5420,11 @@ df_eval_viz_block_list_from_eval_view_expr_keys(Arena *arena, DBGI_Scope *scope, { DF_Eval eval = df_eval_from_string(arena, scope, ctrl_ctx, parse_ctx, macro_map, expr); U64 expr_comma_pos = str8_find_needle(expr, 0, str8_lit(","), 0); + U64 passthrough_pos = str8_find_needle(expr, 0, str8_lit("--"), 0); String8List default_view_rules = {0}; - if(expr_comma_pos < expr.size) + if(expr_comma_pos < expr.size && expr_comma_pos < passthrough_pos) { - String8 expr_extension = str8_skip(expr, expr_comma_pos+1); + String8 expr_extension = str8_substr(expr, r1u64(expr_comma_pos+1, passthrough_pos)); expr_extension = str8_skip_chop_whitespace(expr_extension); if(str8_match(expr_extension, str8_lit("x"), StringMatchFlag_CaseInsensitive)) { @@ -5428,11 +5438,19 @@ df_eval_viz_block_list_from_eval_view_expr_keys(Arena *arena, DBGI_Scope *scope, { str8_list_pushf(arena, &default_view_rules, "oct"); } - else + else if(expr_extension.size != 0) { str8_list_pushf(arena, &default_view_rules, "array:{%S}", expr_extension); } } + if(passthrough_pos < expr.size) + { + String8 passthrough_view_rule = str8_skip_chop_whitespace(str8_skip(expr, passthrough_pos+2)); + if(passthrough_view_rule.size != 0) + { + str8_list_push(arena, &default_view_rules, passthrough_view_rule); + } + } String8 view_rule_string = df_eval_view_rule_from_key(eval_view, key); DF_CfgTable view_rule_table = {0}; for(String8Node *n = default_view_rules.first; n != 0; n = n->next) @@ -5724,7 +5742,7 @@ df_cfg_escaped_from_raw_string(Arena *arena, String8 string) for(U64 idx = 0; idx <= string.size; idx += 1) { U8 byte = (idx < string.size ? string.str[idx] : 0); - if(byte == 0 || byte == '\"') + if(byte == 0 || byte == '\"' || byte == '\\') { String8 part = str8_substr(string, r1u64(split_start_idx, idx)); str8_list_push(scratch.arena, &parts, part); @@ -5732,6 +5750,7 @@ df_cfg_escaped_from_raw_string(Arena *arena, String8 string) { default:{}break; case '\"':{str8_list_push(scratch.arena, &parts, str8_lit("\\\""));}break; + case '\\':{str8_list_push(scratch.arena, &parts, str8_lit("\\\\"));}break; } split_start_idx = idx+1; } @@ -5761,7 +5780,8 @@ df_cfg_raw_from_escaped_string(Arena *arena, String8 string) switch(string.str[idx+1]) { default:{}break; - case '"':{extra_advance = 1; str8_list_push(scratch.arena, &parts, str8_lit("\""));}break; + case '"': {extra_advance = 1; str8_list_push(scratch.arena, &parts, str8_lit("\""));}break; + case '\\':{extra_advance = 1; str8_list_push(scratch.arena, &parts, str8_lit("\\"));}break; } } split_start_idx = idx+1+extra_advance; @@ -5863,6 +5883,35 @@ df_cfg_strings_from_core(Arena *arena, String8 root_path, DF_CfgSrc source) } } + //- rjf: write auto view rules + { + B32 first = 1; + DF_EntityList avrs = df_query_cached_entity_list_with_kind(DF_EntityKind_AutoViewRule); + for(DF_EntityNode *n = avrs.first; n != 0; n = n->next) + { + DF_Entity *map = n->entity; + if(map->cfg_src == source) + { + if(first) + { + first = 0; + str8_list_push(arena, &strs, str8_lit("/// auto view rules ///////////////////////////////////////////////////////////\n")); + str8_list_push(arena, &strs, str8_lit("\n")); + } + String8 type = df_entity_child_from_kind(map, DF_EntityKind_Source)->name; + String8 view_rule = df_entity_child_from_kind(map, DF_EntityKind_Dest)->name; + type = df_cfg_escaped_from_raw_string(arena, type); + view_rule= df_cfg_escaped_from_raw_string(arena, view_rule); + str8_list_push (arena, &strs, str8_lit("auto_view_rule:\n")); + str8_list_push (arena, &strs, str8_lit("{\n")); + str8_list_pushf(arena, &strs, " type: \"%S\"\n", type); + str8_list_pushf(arena, &strs, " view_rule: \"%S\"\n", view_rule); + str8_list_push (arena, &strs, str8_lit("}\n")); + str8_list_push (arena, &strs, str8_lit("\n")); + } + } + } + //- rjf: write breakpoints { B32 first = 1; @@ -6404,6 +6453,47 @@ df_query_cached_member_map_from_binary_voff(DF_Entity *binary, U64 voff) internal void df_push_cmd__root(DF_CmdParams *params, DF_CmdSpec *spec) { + // rjf: log + { + Temp scratch = scratch_begin(0, 0); + DF_Entity *entity = df_entity_from_handle(params->entity); + log_msgf("debug frontend command pushed: \"%S\"\n", spec->info.string); +#define HandleParamPrint(mem_name) if(!df_handle_match(df_handle_zero(), params->mem_name)) { log_msgf("| %s: [0x%I64x, 0x%I64x]\n", #mem_name, params->mem_name.u64[0], params->mem_name.u64[1]); } + HandleParamPrint(window); + HandleParamPrint(panel); + HandleParamPrint(dest_panel); + HandleParamPrint(prev_view); + HandleParamPrint(view); + if(!df_entity_is_nil(entity)) + { + String8 entity_name = df_display_string_from_entity(scratch.arena, entity); + log_msgf("| entity: \"%S\"\n", entity_name); + } + U64 idx = 0; + for(DF_HandleNode *n = params->entity_list.first; n != 0; n = n->next, idx += 1) + { + DF_Entity *entity = df_entity_from_handle(n->handle); + if(!df_entity_is_nil(entity)) + { + String8 entity_name = df_display_string_from_entity(scratch.arena, entity); + log_msgf("| entity_list[%I64u]: \"%S\"\n", idx, entity_name); + } + } + if(!df_cmd_spec_is_nil(params->cmd_spec)) + { + log_msgf("| cmd_spec: \"%S\"\n", params->cmd_spec->info.string); + } + if(params->string.size != 0) { log_msgf("| string: \"%S\"\n", params->string); } + if(params->file_path.size != 0) { log_msgf("| file_path: \"%S\"\n", params->file_path); } + if(params->text_point.line != 0){ log_msgf("| text_point: [line:%I64d, col:%I64d]\n", params->text_point.line, params->text_point.column); } + if(params->vaddr != 0) { log_msgf("| vaddr: 0x%I64x\n", params->vaddr); } + if(params->voff != 0) { log_msgf("| voff: 0x%I64x\n", params->voff); } + if(params->index != 0) { log_msgf("| index: 0x%I64x\n", params->index); } + if(params->id != 0) { log_msgf("| id: 0x%I64x\n", params->id); } +#undef HandleParamPrint + log_msgf("--------------------------------\n"); + scratch_end(scratch); + } df_cmd_list_push(df_state->root_cmd_arena, &df_state->root_cmds, params, spec); } @@ -6577,6 +6667,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) df_state->time_in_seconds += dt; //- rjf: sync with ctrl thread + ProfScope("sync with ctrl thread") { Temp scratch = scratch_begin(&arena, 1); @@ -6987,6 +7078,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } //- rjf: sync with dbgi parsers + ProfScope("sync with dbgi parsers") { Temp scratch = scratch_begin(&arena, 1); DBGI_EventList events = dbgi_p2u_pop_events(scratch.arena, 0); @@ -7021,6 +7113,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } //- rjf: start/stop telemetry captures + ProfScope("start/stop telemetry captures") { if(!ProfIsCapturing() && DEV_telemetry_capture) { @@ -7051,6 +7144,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } //- rjf: process top-level commands + ProfScope("process top-level commands") { Temp scratch = scratch_begin(&arena, 1); for(DF_CmdNode *cmd_node = cmds->first; @@ -7874,6 +7968,29 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } } + //- rjf: apply auto view rules + DF_CfgVal *avrs = df_cfg_val_from_string(table, str8_lit("auto_view_rule")); + for(DF_CfgNode *map = avrs->first; + map != &df_g_nil_cfg_node; + map = map->next) + { + if(map->source == src) + { + DF_CfgNode *src_cfg = df_cfg_node_child_from_string(map, str8_lit("type"), StringMatchFlag_CaseInsensitive); + DF_CfgNode *dst_cfg = df_cfg_node_child_from_string(map, str8_lit("view_rule"), StringMatchFlag_CaseInsensitive); + String8 type = src_cfg->first->string; + String8 view_rule = dst_cfg->first->string; + type = df_cfg_raw_from_escaped_string(scratch.arena, type); + view_rule = df_cfg_raw_from_escaped_string(scratch.arena, view_rule); + DF_Entity *map_entity = df_entity_alloc(0, df_entity_root(), DF_EntityKind_AutoViewRule); + DF_Entity *src_entity = df_entity_alloc(0, map_entity, DF_EntityKind_Source); + DF_Entity *dst_entity = df_entity_alloc(0, map_entity, DF_EntityKind_Dest); + df_entity_equip_name(0, src_entity, type); + df_entity_equip_name(0, dst_entity, view_rule); + df_entity_equip_cfg_src(map_entity, src); + } + } + //- rjf: apply breakpoints DF_CfgVal *bps = df_cfg_val_from_string(table, str8_lit("breakpoint")); for(DF_CfgNode *bp = bps->first; @@ -7970,9 +8087,9 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) { df_entity_equip_color_hsva(bp_ent, hsva); } - if(cond_cfg->string.size != 0) + if(cond_cfg->first->string.size != 0) { - String8 cond_raw = df_cfg_raw_from_escaped_string(scratch.arena, cond_cfg->string); + String8 cond_raw = df_cfg_raw_from_escaped_string(scratch.arena, cond_cfg->first->string); DF_Entity *cond = df_entity_alloc(0, bp_ent, DF_EntityKind_Condition); df_entity_equip_name(0, cond, cond_raw); } @@ -8210,6 +8327,63 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } }break; + //- rjf: auto view rules + case DF_CoreCmdKind_SetAutoViewRuleType: + case DF_CoreCmdKind_SetAutoViewRuleViewRule: + { + DF_Entity *map = df_entity_from_handle(params.entity); + if(df_entity_is_nil(map)) + { + map = df_entity_alloc(df_state_delta_history(), df_entity_root(), DF_EntityKind_AutoViewRule); + df_entity_equip_cfg_src(map, DF_CfgSrc_Profile); + } + DF_Entity *src = df_entity_child_from_kind(map, DF_EntityKind_Source); + if(df_entity_is_nil(src)) + { + src = df_entity_alloc(df_state_delta_history(), map, DF_EntityKind_Source); + } + DF_Entity *dst = df_entity_child_from_kind(map, DF_EntityKind_Dest); + if(df_entity_is_nil(dst)) + { + dst = df_entity_alloc(df_state_delta_history(), map, DF_EntityKind_Dest); + } + if(map->kind == DF_EntityKind_AutoViewRule) + { + DF_Entity *edit_child = (core_cmd_kind == DF_CoreCmdKind_SetAutoViewRuleType ? src : dst); + df_entity_equip_name(df_state_delta_history(), edit_child, params.string); + } + if(src->name.size == 0 && dst->name.size == 0) + { + df_entity_mark_for_deletion(map); + } + { + DF_AutoViewRuleMapCache *cache = &df_state->auto_view_rule_cache; + if(cache->arena == 0) + { + cache->arena = arena_alloc(); + } + arena_clear(cache->arena); + cache->slots_count = 1024; + cache->slots = push_array(cache->arena, DF_AutoViewRuleSlot, cache->slots_count); + DF_EntityList maps = df_query_cached_entity_list_with_kind(DF_EntityKind_AutoViewRule); + for(DF_EntityNode *n = maps.first; n != 0; n = n->next) + { + DF_Entity *map = n->entity; + DF_Entity *src = df_entity_child_from_kind(map, DF_EntityKind_Source); + DF_Entity *dst = df_entity_child_from_kind(map, DF_EntityKind_Dest); + String8 type = src->name; + String8 view_rule = dst->name; + U64 hash = df_hash_from_string(type); + U64 slot_idx = hash%cache->slots_count; + DF_AutoViewRuleSlot *slot = &cache->slots[slot_idx]; + DF_AutoViewRuleNode *node = push_array(cache->arena, DF_AutoViewRuleNode, 1); + node->type = push_str8_copy(cache->arena, type); + node->view_rule = push_str8_copy(cache->arena, view_rule); + SLLQueuePush(slot->first, slot->last, node); + } + } + }break; + //- rjf: general entity operations case DF_CoreCmdKind_EnableEntity: case DF_CoreCmdKind_EnableBreakpoint: diff --git a/src/df/core/df_core.h b/src/df/core/df_core.h index b038b254..485cc0b9 100644 --- a/src/df/core/df_core.h +++ b/src/df/core/df_core.h @@ -268,7 +268,7 @@ struct DF_Eval #define DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_SIG(name) DF_Eval name(Arena *arena, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_Eval eval, struct DF_CfgVal *val) #define DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(name) df_core_view_rule_eval_resolution__##name #define DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(name) internal DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_SIG(DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(name)) -#define DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_SIG(name) void name(Arena *arena, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, struct DF_EvalView *eval_view, DF_Eval eval, struct DF_CfgTable *cfg_table, DF_ExpandKey parent_key, DF_ExpandKey key, S32 depth, struct DF_CfgNode *cfg, struct DF_EvalVizBlockList *out) +#define DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_SIG(name) void name(Arena *arena, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, struct DF_EvalView *eval_view, DF_Eval eval, String8 string, struct DF_CfgTable *cfg_table, DF_ExpandKey parent_key, DF_ExpandKey key, S32 depth, struct DF_CfgNode *cfg, struct DF_EvalVizBlockList *out) #define DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(name) df_core_view_rule_viz_block_prod__##name #define DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(name) internal DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_SIG(DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(name)) typedef DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_SIG(DF_CoreViewRuleEvalResolutionHookFunctionType); @@ -774,7 +774,8 @@ struct DF_EvalVizRow DF_Eval eval; // rjf: basic visualization contents - String8 expr; + String8 display_expr; + String8 edit_expr; String8 display_value; String8 edit_value; TG_KeyList inherited_type_key_chain; @@ -919,6 +920,31 @@ struct DF_EntityListCache DF_EntityList list; }; +//- rjf: auto view rules hash table cache + +typedef struct DF_AutoViewRuleNode DF_AutoViewRuleNode; +struct DF_AutoViewRuleNode +{ + DF_AutoViewRuleNode *next; + String8 type; + String8 view_rule; +}; + +typedef struct DF_AutoViewRuleSlot DF_AutoViewRuleSlot; +struct DF_AutoViewRuleSlot +{ + DF_AutoViewRuleNode *first; + DF_AutoViewRuleNode *last; +}; + +typedef struct DF_AutoViewRuleMapCache DF_AutoViewRuleMapCache; +struct DF_AutoViewRuleMapCache +{ + Arena *arena; + U64 slots_count; + DF_AutoViewRuleSlot *slots; +}; + //- rjf: per-run unwind cache typedef struct DF_RunUnwindCacheNode DF_RunUnwindCacheNode; @@ -1116,8 +1142,7 @@ struct DF_State // rjf: entity query caches U64 kind_alloc_gens[DF_EntityKind_COUNT]; DF_EntityListCache kind_caches[DF_EntityKind_COUNT]; - DF_EntityListCache dbg_info_cache; - DF_EntityListCache bin_file_cache; + DF_AutoViewRuleMapCache auto_view_rule_cache; // rjf: per-run caches U64 unwind_cache_reggen_idx; diff --git a/src/df/core/df_core.mdesk b/src/df/core/df_core.mdesk index 6963fe54..e5bc236e 100644 --- a/src/df/core/df_core.mdesk +++ b/src/df/core/df_core.mdesk @@ -28,6 +28,9 @@ DF_EntityKindTable: {OverrideFileLink override_file_link 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 "Label" FileOutline "Override File Link" } {PendingFileChange pending_file_change 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "Label" FileOutline "Pending File Change" } + //- rjf: auto view rules + {AutoViewRule auto_view_rule 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 "Label" Binoculars "Auto View Rule" } + //- rjf: diagnostics log {DiagLog diag_log 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "Label" FileOutline "Diagnostics Log" } @@ -85,12 +88,14 @@ DF_CmdParamSlotTable: {TextPoint text_point `TxtPt`} {CmdSpec cmd_spec `struct DF_CmdSpec *`} {ViewSpec view_spec `struct DF_ViewSpec *`} + {CfgNode cfg_node `struct DF_CfgNode *`} {VirtualAddr vaddr `U64`} {VirtualOff voff `U64`} {Index index `U64`} {ID id `U64`} {PreferDisassembly prefer_dasm `B32`} {ForceConfirm force_confirm `B32`} + {Dir2 dir2 `Dir2`} } @table(name lister_omit q_slot q_ent_kind q_allow_files q_allow_folders q_keep_oi q_select_oi q_is_code q_required canonical_icon string display_name desc search_tags ) @@ -172,8 +177,11 @@ DF_CoreCmdTable:// | | | //- rjf: panel splitting {ResetToDefaultPanels 0 Null Nil 0 0 0 0 0 0 Window "reset_to_default_panels" "Reset To Default Panel Layout" "Resets the window to the default panel layout." "panel" } - {NewPanelRight 0 Null Nil 0 0 0 0 0 0 XSplit "new_panel_right" "Split Panel Vertically" "Creates a new panel to the right of the active panel." "panel" } - {NewPanelDown 0 Null Nil 0 0 0 0 0 0 YSplit "new_panel_down" "Split Panel Horizontally" "Creates a new panel at the bottom of the active panel." "panel" } + {NewPanelLeft 0 Null Nil 0 0 0 0 0 0 XSplit "new_panel_left" "Split Panel Left" "Creates a new panel to the left of the active panel." "panel" } + {NewPanelUp 0 Null Nil 0 0 0 0 0 0 YSplit "new_panel_up" "Split Panel Up" "Creates a new panel at the top of the active panel." "panel" } + {NewPanelRight 0 Null Nil 0 0 0 0 0 0 XSplit "new_panel_right" "Split Panel Right" "Creates a new panel to the right of the active panel." "panel" } + {NewPanelDown 0 Null Nil 0 0 0 0 0 0 YSplit "new_panel_down" "Split Panel Down" "Creates a new panel at the bottom of the active panel." "panel" } + {SplitPanel 1 Null Nil 0 0 0 0 0 0 Null "split_panel" "Split Panel" "Creates a new panel in a given direction, and moves a tab to it, if specified." "" } //- rjf: panel rotation {RotatePanelColumns 0 Null Nil 0 0 0 0 0 0 Null "rotate_panel_columns" "Rotate Panel Columns" "Rotates all panels at the closest column level of the panel hierarchy." "" } @@ -222,6 +230,10 @@ DF_CoreCmdTable:// | | | {SetFileOverrideLinkDst 1 Null Nil 0 0 0 0 0 0 Null "set_file_override_link_dst" "Set File Override Link Destination" "Sets the destination path for an override file link." "" } {SetFileReplacementPath 1 Null Nil 0 0 0 0 0 0 Null "set_file_replacement_path" "Set File Replacement Path" "Sets the path which should be used as the replacement for the passed file." "" } + //- rjf: auto view rules + {SetAutoViewRuleType 1 Null Nil 0 0 0 0 0 0 Null "set_auto_view_rule_type" "Set Auto View Rule Type" "Sets the type for an auto view rule." "" } + {SetAutoViewRuleViewRule 1 Null Nil 0 0 0 0 0 0 Null "set_auto_view_rule_view_rule""Set Auto View Rule View Rule" "Sets the view rule string for an auto view rule." "" } + //- rjf: setting config paths {OpenUser 0 FilePath Nil 1 0 0 0 0 1 Person "open_user" "Open User" "Opens a user file path, immediately loading it, and begins autosaving to it." "load,user,profile,layout" } {OpenProfile 0 FilePath Nil 1 0 0 0 0 1 Briefcase "open_profile" "Open Profile" "Opens a profile file path, immediately loading it, and begins autosaving to it." "profile,project,session" } @@ -355,6 +367,7 @@ DF_CoreCmdTable:// | | | {Target 1 Null Nil 0 0 0 0 0 0 Target "target" "Target" "Opens the editor for a target." "" } {Targets 0 Null Nil 0 0 0 0 0 0 Target "targets" "Targets" "Opens the list of all targets." "" } {FilePathMap 0 Null Nil 0 0 0 0 0 0 FileOutline "file_path_map" "File Path Map" "Opens the file path mapping editor." "" } + {AutoViewRules 0 Null Nil 0 0 0 0 0 0 Binoculars "auto_view_rules" "Auto View Rules" "Opens the auto view rule editor." "" } {Scheduler 0 Null Nil 0 0 0 0 0 0 Scheduler "scheduler" "Scheduler" "Opens the scheduler view, for process and thread controls." "threads,processes,targets" } {CallStack 0 Null Nil 0 0 0 0 0 0 Thread "call_stack" "Call Stack" "Opens the call stack view." "callstack,thread" } {Modules 0 Null Nil 0 0 0 0 0 0 Module "modules" "Modules" "Opens the modules view." "" } @@ -454,12 +467,10 @@ DF_CoreCmdTable:// | | | // rows, this stage offers the ability to build a ui // stretching over all of the rows. // -// whole ui build, "wu" -> sometimes, more sophisticated interfaces need to be -// provided for a view rule, that stretch beyond the -// limits of what could be offered inside a watch -// window block. in such cases, the eval/view-rule -// combo will be granted its own tab for example, and -// this stage is used to fill such a ui. +// tab ui build, "tu" -> when a view rule also wants to implement ui for a +// dedicated tab, it can supply hooks for that as well +// in which case an eval/view-rule can be opened in a +// fully fledged, dedicated ui // // A few other bits are included for various ways in which a view rule may be // applied throughout the eval visualization pipeline. A list follows: @@ -498,6 +509,7 @@ DF_CoreViewRuleTable: {RGBA rgba "rgba" - x - x "Color (RGBA)" x "Displays as a color, interpreting the data as encoding R, G, B, and A values." } {Text text "text" - x - x "Text" x "Displays as text." } {Disasm disasm "disasm" - x - x "Disassembly" x "Displays as disassembled instructions, interpreting the data as raw machine code." } + {Graph graph "graph" - x - x "Graph" x "Displays as a pointer graph, visualizing nodes and edges formed by pointers directly." } {Bitmap bitmap "bitmap" - x - x "Bitmap" x "Displays as a bitmap, interpreting the data as raw pixel data." } {Geo geo "geo" - x - x "Geometry" x "Displays as geometry, interpreting the data as vertex data." } {OdinMap odin_map "odin_map" - x - x "Odin map" x "Specifies that a struct to be rendered as an Odin map type." } diff --git a/src/df/core/generated/df_core.meta.c b/src/df/core/generated/df_core.meta.c index 63da64fc..9dcba9f9 100644 --- a/src/df/core/generated/df_core.meta.c +++ b/src/df/core/generated/df_core.meta.c @@ -4,7 +4,7 @@ //- GENERATED CODE C_LINKAGE_BEGIN -Rng1U64 df_g_cmd_param_slot_range_table[19] = +Rng1U64 df_g_cmd_param_slot_range_table[21] = { {0}, {OffsetOf(DF_CmdParams, window), OffsetOf(DF_CmdParams, window) + sizeof(DF_Handle)}, @@ -19,15 +19,17 @@ Rng1U64 df_g_cmd_param_slot_range_table[19] = {OffsetOf(DF_CmdParams, text_point), OffsetOf(DF_CmdParams, text_point) + sizeof(TxtPt)}, {OffsetOf(DF_CmdParams, cmd_spec), OffsetOf(DF_CmdParams, cmd_spec) + sizeof(struct DF_CmdSpec *)}, {OffsetOf(DF_CmdParams, view_spec), OffsetOf(DF_CmdParams, view_spec) + sizeof(struct DF_ViewSpec *)}, +{OffsetOf(DF_CmdParams, cfg_node), OffsetOf(DF_CmdParams, cfg_node) + sizeof(struct DF_CfgNode *)}, {OffsetOf(DF_CmdParams, vaddr), OffsetOf(DF_CmdParams, vaddr) + sizeof(U64)}, {OffsetOf(DF_CmdParams, voff), OffsetOf(DF_CmdParams, voff) + sizeof(U64)}, {OffsetOf(DF_CmdParams, index), OffsetOf(DF_CmdParams, index) + sizeof(U64)}, {OffsetOf(DF_CmdParams, id), OffsetOf(DF_CmdParams, id) + sizeof(U64)}, {OffsetOf(DF_CmdParams, prefer_dasm), OffsetOf(DF_CmdParams, prefer_dasm) + sizeof(B32)}, {OffsetOf(DF_CmdParams, force_confirm), OffsetOf(DF_CmdParams, force_confirm) + sizeof(B32)}, +{OffsetOf(DF_CmdParams, dir2), OffsetOf(DF_CmdParams, dir2) + sizeof(Dir2)}, }; -DF_IconKind df_g_entity_kind_icon_kind_table[26] = +DF_IconKind df_g_entity_kind_icon_kind_table[27] = { DF_IconKind_Null, DF_IconKind_Null, @@ -35,6 +37,7 @@ DF_IconKind_Machine, DF_IconKind_FileOutline, DF_IconKind_FileOutline, DF_IconKind_FileOutline, +DF_IconKind_Binoculars, DF_IconKind_FileOutline, DF_IconKind_Null, DF_IconKind_Pin, @@ -57,7 +60,7 @@ DF_IconKind_Null, DF_IconKind_Null, }; -String8 df_g_entity_kind_display_string_table[26] = +String8 df_g_entity_kind_display_string_table[27] = { str8_lit_comp("Nil"), str8_lit_comp("Root"), @@ -65,6 +68,7 @@ str8_lit_comp("Machine"), str8_lit_comp("File"), str8_lit_comp("Override File Link"), str8_lit_comp("Pending File Change"), +str8_lit_comp("Auto View Rule"), str8_lit_comp("Diagnostics Log"), str8_lit_comp("Flash Marker"), str8_lit_comp("Watch Pin"), @@ -87,7 +91,7 @@ str8_lit_comp("Conversion Failure"), str8_lit_comp("EndedProcess"), }; -String8 df_g_entity_kind_name_label_table[26] = +String8 df_g_entity_kind_name_label_table[27] = { str8_lit_comp("Label"), str8_lit_comp("Label"), @@ -97,6 +101,7 @@ str8_lit_comp("Label"), str8_lit_comp("Label"), str8_lit_comp("Label"), str8_lit_comp("Label"), +str8_lit_comp("Label"), str8_lit_comp("Expression"), str8_lit_comp("Label"), str8_lit_comp("Expression"), @@ -117,7 +122,7 @@ str8_lit_comp("Label"), str8_lit_comp("Label"), }; -DF_EntityKindFlags df_g_entity_kind_flags_table[26] = +DF_EntityKindFlags df_g_entity_kind_flags_table[27] = { (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), @@ -125,6 +130,7 @@ DF_EntityKindFlags df_g_entity_kind_flags_table[26] = (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), (1*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), +(0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 1*DF_EntityKindFlag_UserDefinedLifetime), (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 1*DF_EntityKindFlag_NameIsCode | 1*DF_EntityKindFlag_UserDefinedLifetime), @@ -147,7 +153,7 @@ DF_EntityKindFlags df_g_entity_kind_flags_table[26] = (0*DF_EntityKindFlag_LeafMutationUserConfig | 0*DF_EntityKindFlag_LeafMutationProfileConfig | 0*DF_EntityKindFlag_LeafMutationSoftHalt | 0*DF_EntityKindFlag_LeafMutationDebugInfoMap | 0*DF_EntityKindFlag_TreeMutationUserConfig | 0*DF_EntityKindFlag_TreeMutationProfileConfig | 0*DF_EntityKindFlag_TreeMutationSoftHalt | 0*DF_EntityKindFlag_TreeMutationDebugInfoMap | 0*DF_EntityKindFlag_NameIsCode | 0*DF_EntityKindFlag_UserDefinedLifetime), }; -DF_EntityOpFlags df_g_entity_kind_op_flags_table[26] = +DF_EntityOpFlags df_g_entity_kind_op_flags_table[27] = { (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), @@ -157,6 +163,7 @@ DF_EntityOpFlags df_g_entity_kind_op_flags_table[26] = (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), +(0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), (1*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (1*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (1*DF_EntityOpFlag_Duplicate), (1*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (1*DF_EntityOpFlag_Rename) | (1*DF_EntityOpFlag_Enable) | (1*DF_EntityOpFlag_Condition) | (1*DF_EntityOpFlag_Duplicate), (0*DF_EntityOpFlag_Delete) | (0*DF_EntityOpFlag_Freeze) | (0*DF_EntityOpFlag_Edit) | (0*DF_EntityOpFlag_Rename) | (0*DF_EntityOpFlag_Enable) | (0*DF_EntityOpFlag_Condition) | (0*DF_EntityOpFlag_Duplicate), @@ -209,7 +216,7 @@ DF_CoreCmdKind_Null, DF_CoreCmdKind_Null, }; -DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[206] = +DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[212] = { { str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("exit"), str8_lit_comp("Exits the debugger."), str8_lit_comp("quit,close,abort"), str8_lit_comp("Exit"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_X}, @@ -263,8 +270,11 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[206] = { str8_lit_comp("confirm_accept"), str8_lit_comp("Accepts the active confirmation prompt."), str8_lit_comp(""), str8_lit_comp("Confirm Accept"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("confirm_cancel"), str8_lit_comp("Cancels the active confirmation prompt."), str8_lit_comp(""), str8_lit_comp("Confirm Cancel"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("reset_to_default_panels"), str8_lit_comp("Resets the window to the default panel layout."), str8_lit_comp("panel"), str8_lit_comp("Reset To Default Panel Layout"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Window}, -{ str8_lit_comp("new_panel_right"), str8_lit_comp("Creates a new panel to the right of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Vertically"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_XSplit}, -{ str8_lit_comp("new_panel_down"), str8_lit_comp("Creates a new panel at the bottom of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Horizontally"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_YSplit}, +{ str8_lit_comp("new_panel_left"), str8_lit_comp("Creates a new panel to the left of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Left"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_XSplit}, +{ str8_lit_comp("new_panel_up"), str8_lit_comp("Creates a new panel at the top of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Up"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_YSplit}, +{ str8_lit_comp("new_panel_right"), str8_lit_comp("Creates a new panel to the right of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Right"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_XSplit}, +{ str8_lit_comp("new_panel_down"), str8_lit_comp("Creates a new panel at the bottom of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Down"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_YSplit}, +{ str8_lit_comp("split_panel"), str8_lit_comp("Creates a new panel in a given direction, and moves a tab to it, if specified."), str8_lit_comp(""), str8_lit_comp("Split Panel"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("rotate_panel_columns"), str8_lit_comp("Rotates all panels at the closest column level of the panel hierarchy."), str8_lit_comp(""), str8_lit_comp("Rotate Panel Columns"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("next_panel"), str8_lit_comp("Cycles the active panel forward."), str8_lit_comp(""), str8_lit_comp("Focus Next Panel"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_RightArrow}, { str8_lit_comp("prev_panel"), str8_lit_comp("Cycles the active panel backwards."), str8_lit_comp(""), str8_lit_comp("Focus Previous Panel"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_LeftArrow}, @@ -296,6 +306,8 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[206] = { str8_lit_comp("set_file_override_link_src"), str8_lit_comp("Sets the source path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Source"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("set_file_override_link_dst"), str8_lit_comp("Sets the destination path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Destination"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("set_file_replacement_path"), str8_lit_comp("Sets the path which should be used as the replacement for the passed file."), str8_lit_comp(""), str8_lit_comp("Set File Replacement Path"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, +{ str8_lit_comp("set_auto_view_rule_type"), str8_lit_comp("Sets the type for an auto view rule."), str8_lit_comp(""), str8_lit_comp("Set Auto View Rule Type"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, +{ str8_lit_comp("set_auto_view_rule_view_rule"), str8_lit_comp("Sets the view rule string for an auto view rule."), str8_lit_comp(""), str8_lit_comp("Set Auto View Rule View Rule"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("open_user"), str8_lit_comp("Opens a user file path, immediately loading it, and begins autosaving to it."), str8_lit_comp("load,user,profile,layout"), str8_lit_comp("Open User"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*1)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_Person}, { str8_lit_comp("open_profile"), str8_lit_comp("Opens a profile file path, immediately loading it, and begins autosaving to it."), str8_lit_comp("profile,project,session"), str8_lit_comp("Open Profile"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*1)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_Briefcase}, { str8_lit_comp("apply_user_data"), str8_lit_comp("Applies user data from the active user file."), str8_lit_comp(""), str8_lit_comp("Apply User Data"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, @@ -392,6 +404,7 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[206] = { str8_lit_comp("target"), str8_lit_comp("Opens the editor for a target."), str8_lit_comp(""), str8_lit_comp("Target"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Target}, { str8_lit_comp("targets"), str8_lit_comp("Opens the list of all targets."), str8_lit_comp(""), str8_lit_comp("Targets"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Target}, { str8_lit_comp("file_path_map"), str8_lit_comp("Opens the file path mapping editor."), str8_lit_comp(""), str8_lit_comp("File Path Map"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline}, +{ str8_lit_comp("auto_view_rules"), str8_lit_comp("Opens the auto view rule editor."), str8_lit_comp(""), str8_lit_comp("Auto View Rules"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Binoculars}, { str8_lit_comp("scheduler"), str8_lit_comp("Opens the scheduler view, for process and thread controls."), str8_lit_comp("threads,processes,targets"), str8_lit_comp("Scheduler"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Scheduler}, { str8_lit_comp("call_stack"), str8_lit_comp("Opens the call stack view."), str8_lit_comp("callstack,thread"), str8_lit_comp("Call Stack"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Thread}, { str8_lit_comp("modules"), str8_lit_comp("Opens the modules view."), str8_lit_comp(""), str8_lit_comp("Modules"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Module}, @@ -419,11 +432,10 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[206] = { str8_lit_comp("toggle_dev_menu"), str8_lit_comp("Opens and closes the developer menu."), str8_lit_comp(""), str8_lit_comp("Toggle Developer Menu"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, }; -DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[18] = +DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[17] = { {str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, }, {str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("Specifies that a pointer points to N elements, rather than only 1."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(array) , 0, }, -{str8_lit_comp("slice"), str8_lit_comp("Slice"), str8_lit_comp("Specifies that a struct to be rendered as a slice."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(slice) , 0, }, {str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(list) , }, {str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp("Specifies that all integer primitives should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(bswap) , 0, }, {str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, }, @@ -436,9 +448,9 @@ DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[18] = {str8_lit_comp("rgba"), str8_lit_comp("Color (RGBA)"), str8_lit_comp("Displays as a color, interpreting the data as encoding R, G, B, and A values."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(rgba) , }, {str8_lit_comp("text"), str8_lit_comp("Text"), str8_lit_comp("Displays as text."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(text) , }, {str8_lit_comp("disasm"), str8_lit_comp("Disassembly"), str8_lit_comp("Displays as disassembled instructions, interpreting the data as raw machine code."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(disasm) , }, +{str8_lit_comp("graph"), str8_lit_comp("Graph"), str8_lit_comp("Displays as a pointer graph, visualizing nodes and edges formed by pointers directly."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(graph) , }, {str8_lit_comp("bitmap"), str8_lit_comp("Bitmap"), str8_lit_comp("Displays as a bitmap, interpreting the data as raw pixel data."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(bitmap) , }, {str8_lit_comp("geo"), str8_lit_comp("Geometry"), str8_lit_comp("Displays as geometry, interpreting the data as vertex data."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(geo) , }, -{str8_lit_comp("odin_map"), str8_lit_comp("Odin map"), str8_lit_comp("Specifies that a struct to be rendered as an Odin map type."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(odin_map) , }, }; String8 df_g_icon_kind_text_table[69] = diff --git a/src/df/core/generated/df_core.meta.h b/src/df/core/generated/df_core.meta.h index 8e351bfb..8f492363 100644 --- a/src/df/core/generated/df_core.meta.h +++ b/src/df/core/generated/df_core.meta.h @@ -23,6 +23,7 @@ DF_EntityKind_Machine, DF_EntityKind_File, DF_EntityKind_OverrideFileLink, DF_EntityKind_PendingFileChange, +DF_EntityKind_AutoViewRule, DF_EntityKind_DiagLog, DF_EntityKind_FlashMarker, DF_EntityKind_WatchPin, @@ -100,8 +101,11 @@ DF_CoreCmdKind_ToggleFullscreen, DF_CoreCmdKind_ConfirmAccept, DF_CoreCmdKind_ConfirmCancel, DF_CoreCmdKind_ResetToDefaultPanels, +DF_CoreCmdKind_NewPanelLeft, +DF_CoreCmdKind_NewPanelUp, DF_CoreCmdKind_NewPanelRight, DF_CoreCmdKind_NewPanelDown, +DF_CoreCmdKind_SplitPanel, DF_CoreCmdKind_RotatePanelColumns, DF_CoreCmdKind_NextPanel, DF_CoreCmdKind_PrevPanel, @@ -133,6 +137,8 @@ DF_CoreCmdKind_SwitchToPartnerFile, DF_CoreCmdKind_SetFileOverrideLinkSrc, DF_CoreCmdKind_SetFileOverrideLinkDst, DF_CoreCmdKind_SetFileReplacementPath, +DF_CoreCmdKind_SetAutoViewRuleType, +DF_CoreCmdKind_SetAutoViewRuleViewRule, DF_CoreCmdKind_OpenUser, DF_CoreCmdKind_OpenProfile, DF_CoreCmdKind_ApplyUserData, @@ -229,6 +235,7 @@ DF_CoreCmdKind_Commands, DF_CoreCmdKind_Target, DF_CoreCmdKind_Targets, DF_CoreCmdKind_FilePathMap, +DF_CoreCmdKind_AutoViewRules, DF_CoreCmdKind_Scheduler, DF_CoreCmdKind_CallStack, DF_CoreCmdKind_Modules, @@ -348,6 +355,7 @@ DF_CoreViewRuleKind_NoAddr, DF_CoreViewRuleKind_RGBA, DF_CoreViewRuleKind_Text, DF_CoreViewRuleKind_Disasm, +DF_CoreViewRuleKind_Graph, DF_CoreViewRuleKind_Bitmap, DF_CoreViewRuleKind_Geo, DF_CoreViewRuleKind_OdinMap, @@ -369,12 +377,14 @@ DF_CmdParamSlot_FilePath, DF_CmdParamSlot_TextPoint, DF_CmdParamSlot_CmdSpec, DF_CmdParamSlot_ViewSpec, +DF_CmdParamSlot_CfgNode, DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_VirtualOff, DF_CmdParamSlot_Index, DF_CmdParamSlot_ID, DF_CmdParamSlot_PreferDisassembly, DF_CmdParamSlot_ForceConfirm, +DF_CmdParamSlot_Dir2, DF_CmdParamSlot_COUNT, } DF_CmdParamSlot; @@ -394,12 +404,14 @@ String8 file_path; TxtPt text_point; struct DF_CmdSpec * cmd_spec; struct DF_ViewSpec * view_spec; +struct DF_CfgNode * cfg_node; U64 vaddr; U64 voff; U64 index; U64 id; B32 prefer_dasm; B32 force_confirm; +Dir2 dir2; }; DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(array); @@ -411,6 +423,7 @@ DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(omit); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(rgba); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(text); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(disasm); +DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(graph); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(bitmap); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(geo); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(odin_map); @@ -1511,12 +1524,12 @@ struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] = {&DEV_updating_indicator, str8_lit_comp("updating_indicator")}, }; C_LINKAGE_BEGIN -extern Rng1U64 df_g_cmd_param_slot_range_table[19]; -extern DF_IconKind df_g_entity_kind_icon_kind_table[26]; -extern String8 df_g_entity_kind_display_string_table[26]; -extern String8 df_g_entity_kind_name_label_table[26]; -extern DF_EntityKindFlags df_g_entity_kind_flags_table[26]; -extern DF_EntityOpFlags df_g_entity_kind_op_flags_table[26]; +extern Rng1U64 df_g_cmd_param_slot_range_table[21]; +extern DF_IconKind df_g_entity_kind_icon_kind_table[27]; +extern String8 df_g_entity_kind_display_string_table[27]; +extern String8 df_g_entity_kind_name_label_table[27]; +extern DF_EntityKindFlags df_g_entity_kind_flags_table[27]; +extern DF_EntityOpFlags df_g_entity_kind_op_flags_table[27]; extern String8 df_g_cfg_src_string_table[4]; extern DF_CoreCmdKind df_g_cfg_src_load_cmd_kind_table[4]; extern DF_CoreCmdKind df_g_cfg_src_write_cmd_kind_table[4]; diff --git a/src/df/df_inc.c b/src/df/df_inc.c index 21d36dcc..206b7585 100644 --- a/src/df/df_inc.c +++ b/src/df/df_inc.c @@ -4,4 +4,4 @@ #include "df/core/df_core.c" #include "df/gfx/df_gfx.c" #include "df/gfx/df_views.c" -#include "df/gfx/df_view_rule_hooks.c" +#include "df/gfx/df_view_rules.c" diff --git a/src/df/df_inc.h b/src/df/df_inc.h index 9a5ce481..b1ed72ea 100644 --- a/src/df/df_inc.h +++ b/src/df/df_inc.h @@ -7,6 +7,6 @@ #include "df/core/df_core.h" #include "df/gfx/df_gfx.h" #include "df/gfx/df_views.h" -#include "df/gfx/df_view_rule_hooks.h" +#include "df/gfx/df_view_rules.h" #endif // DEBUG_FRONTEND_INC_H diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index b3fffc7d..7a57924b 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -216,7 +216,7 @@ df_panel_rec_df(DF_Panel *panel, U64 sib_off, U64 child_off) //- rjf: panel -> rect calculations internal Rng2F32 -df_rect_from_panel_child(Rng2F32 parent_rect, DF_Panel *parent, DF_Panel *panel) +df_target_rect_from_panel_child(Rng2F32 parent_rect, DF_Panel *parent, DF_Panel *panel) { Rng2F32 rect = parent_rect; if(!df_panel_is_nil(parent)) @@ -226,26 +226,25 @@ df_rect_from_panel_child(Rng2F32 parent_rect, DF_Panel *parent, DF_Panel *panel) rect.p1.v[axis] = rect.p0.v[axis]; for(DF_Panel *child = parent->first; !df_panel_is_nil(child); child = child->next) { - rect.p1.v[axis] += parent_rect_size.v[axis] * child->size_pct_of_parent.v[axis]; - rect.p1.v[axis2_flip(axis)] = rect.p0.v[axis2_flip(axis)] + parent_rect_size.v[axis2_flip(axis)] * child->size_pct_of_parent.v[axis2_flip(axis)]; + rect.p1.v[axis] += parent_rect_size.v[axis] * child->pct_of_parent; if(child == panel) { break; } rect.p0.v[axis] = rect.p1.v[axis]; } - rect.p0.v[axis] += parent_rect_size.v[axis] * panel->off_pct_of_parent.v[axis]; - rect.p0.v[axis2_flip(axis)] += parent_rect_size.v[axis2_flip(axis)] * panel->off_pct_of_parent.v[axis2_flip(axis)]; + //rect.p0.v[axis] += parent_rect_size.v[axis] * panel->off_pct_of_parent.v[axis]; + //rect.p0.v[axis2_flip(axis)] += parent_rect_size.v[axis2_flip(axis)] * panel->off_pct_of_parent.v[axis2_flip(axis)]; } - rect.x0 = roundf(rect.x0); - rect.x1 = roundf(rect.x1); - rect.y0 = roundf(rect.y0); - rect.y1 = roundf(rect.y1); + rect.x0 = round_f32(rect.x0); + rect.x1 = round_f32(rect.x1); + rect.y0 = round_f32(rect.y0); + rect.y1 = round_f32(rect.y1); return rect; } internal Rng2F32 -df_rect_from_panel(Rng2F32 root_rect, DF_Panel *root, DF_Panel *panel) +df_target_rect_from_panel(Rng2F32 root_rect, DF_Panel *root, DF_Panel *panel) { Temp scratch = scratch_begin(0, 0); @@ -277,12 +276,12 @@ df_rect_from_panel(Rng2F32 root_rect, DF_Panel *root, DF_Panel *panel) DF_Panel *parent = ancestor->parent; if(!df_panel_is_nil(parent)) { - parent_rect = df_rect_from_panel_child(parent_rect, parent, ancestor); + parent_rect = df_target_rect_from_panel_child(parent_rect, parent, ancestor); } } // rjf: calculate final rect - Rng2F32 rect = df_rect_from_panel_child(parent_rect, panel->parent, panel); + Rng2F32 rect = df_target_rect_from_panel_child(parent_rect, panel->parent, panel); scratch_end(scratch); return rect; @@ -529,8 +528,10 @@ df_cmd_params_copy(Arena *arena, DF_CmdParams *src) dst.entity_list = df_push_handle_list_copy(arena, src->entity_list); dst.string = push_str8_copy(arena, src->string); dst.file_path = push_str8_copy(arena, src->file_path); + if(src->cfg_node != 0) {dst.cfg_node = df_cfg_tree_copy(arena, src->cfg_node);} if(dst.cmd_spec == 0) {dst.cmd_spec = &df_g_nil_cmd_spec;} if(dst.view_spec == 0) {dst.view_spec = &df_g_nil_view_spec;} + if(dst.cfg_node == 0) {dst.cfg_node = &df_g_nil_cfg_node;} return dst; } @@ -717,6 +718,17 @@ df_gfx_view_rule_spec_from_string(String8 string) return spec; } +internal DF_ViewSpec * +df_tab_view_spec_from_gfx_view_rule_spec(DF_GfxViewRuleSpec *spec) +{ + DF_ViewSpec *result = &df_g_nil_view_spec; + if(spec->info.tab_view_spec_name.size != 0) + { + result = df_view_spec_from_string(spec->info.tab_view_spec_name); + } + return result; +} + //////////////////////////////// //~ rjf: View State Functions @@ -768,7 +780,7 @@ df_view_release(DF_View *view) } internal void -df_view_equip_spec(DF_View *view, DF_ViewSpec *spec, DF_Entity *entity, String8 default_query, DF_CfgNode *cfg_root) +df_view_equip_spec(DF_Window *window, DF_View *view, DF_ViewSpec *spec, DF_Entity *entity, String8 default_query, DF_CfgNode *cfg_root) { // rjf: fill arguments buffer view->query_string_size = Min(sizeof(view->query_buffer), default_query.size); @@ -785,7 +797,7 @@ df_view_equip_spec(DF_View *view, DF_ViewSpec *spec, DF_Entity *entity, String8 view->entity = df_handle_from_entity(entity); view->is_filtering = 0; view->is_filtering_t = 0; - view_setup(view, cfg_root); + view_setup(window, view, cfg_root); } } @@ -900,6 +912,7 @@ df_panel_alloc(DF_Window *ws) panel->first = panel->last = panel->next = panel->prev = panel->parent = &df_g_nil_panel; panel->first_tab_view = panel->last_tab_view = &df_g_nil_view; panel->generation += 1; + MemoryZeroStruct(&panel->animated_rect_pct); return panel; } @@ -946,7 +959,7 @@ df_window_open(Vec2F32 size, OS_Handle preferred_monitor, DF_CfgSrc cfg_src) window->arena = arena_alloc(); { String8 title = str8_lit_comp(BUILD_TITLE_STRING_LITERAL); - window->os = os_window_open(size, title); + window->os = os_window_open(size, OS_WindowFlag_CustomBorder, title); } window->r = r_window_equip(window->os); window->ui = ui_state_alloc(); @@ -1082,7 +1095,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } // rjf: set up data for cases - Axis2 split_axis = Axis2_X; + Dir2 split_dir = Dir2_Invalid; + DF_Panel *split_panel = ws->focused_panel; U64 panel_sib_off = 0; U64 panel_child_off = 0; Vec2S32 panel_change_dir = {0}; @@ -1185,35 +1199,44 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D }break; //- rjf: panel creation - case DF_CoreCmdKind_NewPanelRight: split_axis = Axis2_X; goto split; - case DF_CoreCmdKind_NewPanelDown: split_axis = Axis2_Y; goto split; - split:; + case DF_CoreCmdKind_NewPanelLeft: {split_dir = Dir2_Left;}goto split; + case DF_CoreCmdKind_NewPanelUp: {split_dir = Dir2_Up;}goto split; + case DF_CoreCmdKind_NewPanelRight:{split_dir = Dir2_Right;}goto split; + case DF_CoreCmdKind_NewPanelDown: {split_dir = Dir2_Down;}goto split; + case DF_CoreCmdKind_SplitPanel: { - DF_Panel *panel = ws->focused_panel; + split_dir = params.dir2; + split_panel = df_panel_from_handle(params.dest_panel); + }goto split; + split:; + if(split_dir != Dir2_Invalid && !df_panel_is_nil(split_panel)) + { + DF_Panel *new_panel = &df_g_nil_panel; + Axis2 split_axis = axis2_from_dir2(split_dir); + Side split_side = side_from_dir2(split_dir); + DF_Panel *panel = split_panel; DF_Panel *parent = panel->parent; if(!df_panel_is_nil(parent) && parent->split_axis == split_axis) { DF_Panel *next = df_panel_alloc(ws); - df_panel_insert(parent, panel, next); - next->size_pct_of_parent_target.v[split_axis] = 1.f / parent->child_count; - next->size_pct_of_parent.v[axis2_flip(split_axis)] = next->size_pct_of_parent_target.v[axis2_flip(split_axis)] = 1.f; + df_panel_insert(parent, split_side == Side_Max ? panel : panel->prev, next); + next->pct_of_parent = 1.f/parent->child_count; for(DF_Panel *child = parent->first; !df_panel_is_nil(child); child = child->next) { if(child != next) { - child->size_pct_of_parent_target.v[split_axis] *= (F32)(parent->child_count-1) / (parent->child_count); + child->pct_of_parent *= (F32)(parent->child_count-1) / (parent->child_count); } } ws->focused_panel = next; + new_panel = next; } else { DF_Panel *pre_prev = panel->prev; DF_Panel *pre_parent = parent; DF_Panel *new_parent = df_panel_alloc(ws); - new_parent->size_pct_of_parent.v[split_axis] = panel->size_pct_of_parent.v[split_axis]; - new_parent->size_pct_of_parent_target.v[split_axis] = panel->size_pct_of_parent_target.v[split_axis]; - new_parent->size_pct_of_parent.v[axis2_flip(split_axis)] = new_parent->size_pct_of_parent_target.v[axis2_flip(split_axis)] = panel->size_pct_of_parent_target.v[axis2_flip(split_axis)]; + new_parent->pct_of_parent = panel->pct_of_parent; if(!df_panel_is_nil(pre_parent)) { df_panel_remove(pre_parent, panel); @@ -1225,18 +1248,44 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } DF_Panel *left = panel; DF_Panel *right = df_panel_alloc(ws); + new_panel = right; + if(split_side == Side_Min) + { + Swap(DF_Panel *, left, right); + } df_panel_insert(new_parent, &df_g_nil_panel, left); df_panel_insert(new_parent, left, right); new_parent->split_axis = split_axis; - left->size_pct_of_parent.v[split_axis] = 1.f; - left->size_pct_of_parent_target.v[split_axis] = 0.5f; - right->size_pct_of_parent.v[split_axis] = 0.f; - right->size_pct_of_parent_target.v[split_axis] = 0.5f; - left->size_pct_of_parent.v[axis2_flip(split_axis)] = 1.f; - left->size_pct_of_parent_target.v[axis2_flip(split_axis)] = 1.f; - right->size_pct_of_parent.v[axis2_flip(split_axis)] = 1.f; - right->size_pct_of_parent_target.v[axis2_flip(split_axis)] = 1.f; - ws->focused_panel = right; + left->pct_of_parent = 0.5f; + right->pct_of_parent = 0.5f; + ws->focused_panel = new_panel; + } + if(!df_panel_is_nil(new_panel->prev)) + { + Rng2F32 prev_rect_pct = new_panel->prev->animated_rect_pct; + new_panel->animated_rect_pct = prev_rect_pct; + new_panel->animated_rect_pct.p0.v[split_axis] = new_panel->animated_rect_pct.p1.v[split_axis]; + } + if(!df_panel_is_nil(new_panel->next)) + { + Rng2F32 next_rect_pct = new_panel->next->animated_rect_pct; + new_panel->animated_rect_pct = next_rect_pct; + new_panel->animated_rect_pct.p1.v[split_axis] = new_panel->animated_rect_pct.p0.v[split_axis]; + } + DF_Panel *move_tab_panel = df_panel_from_handle(params.panel); + DF_View *move_tab = df_view_from_handle(params.view); + if(!df_panel_is_nil(new_panel) && !df_view_is_nil(move_tab) && !df_panel_is_nil(move_tab_panel) && + core_cmd_kind == DF_CoreCmdKind_SplitPanel) + { + df_panel_remove_tab_view(move_tab_panel, move_tab); + df_panel_insert_tab_view(new_panel, new_panel->last_tab_view, move_tab); + new_panel->selected_tab_view = df_handle_from_view(move_tab); + if(df_view_is_nil(move_tab_panel->first_tab_view) && move_tab_panel != ws->root_panel && + move_tab_panel != new_panel->prev && move_tab_panel != new_panel->next) + { + DF_CmdParams p = df_cmd_params_from_panel(ws, move_tab_panel); + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ClosePanel)); + } } df_panel_notify_mutation(ws, panel); }break; @@ -1324,82 +1373,82 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(df_view_is_nil(watch)) { watch = df_view_alloc(); - df_view_equip_spec(watch, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Watch), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, watch, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Watch), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(locals)) { locals = df_view_alloc(); - df_view_equip_spec(locals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Locals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, locals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Locals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(regs)) { regs = df_view_alloc(); - df_view_equip_spec(regs, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Registers), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, regs, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Registers), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(globals)) { globals = df_view_alloc(); - df_view_equip_spec(globals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Globals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, globals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Globals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(tlocals)) { tlocals = df_view_alloc(); - df_view_equip_spec(tlocals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_ThreadLocals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, tlocals, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_ThreadLocals), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(types)) { types = df_view_alloc(); - df_view_equip_spec(types, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Types), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, types, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Types), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(procs)) { procs = df_view_alloc(); - df_view_equip_spec(procs, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Procedures), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, procs, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Procedures), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(callstack)) { callstack = df_view_alloc(); - df_view_equip_spec(callstack, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_CallStack), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, callstack, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_CallStack), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(breakpoints)) { breakpoints = df_view_alloc(); - df_view_equip_spec(breakpoints, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Breakpoints), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, breakpoints, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Breakpoints), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(watch_pins)) { watch_pins = df_view_alloc(); - df_view_equip_spec(watch_pins, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_WatchPins), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, watch_pins, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_WatchPins), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(output)) { output = df_view_alloc(); - df_view_equip_spec(output, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Output), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, output, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Output), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(targets)) { targets = df_view_alloc(); - df_view_equip_spec(targets, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Targets), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, targets, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Targets), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(scheduler)) { scheduler = df_view_alloc(); - df_view_equip_spec(scheduler, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Scheduler), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, scheduler, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Scheduler), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(modules)) { modules = df_view_alloc(); - df_view_equip_spec(modules, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Modules), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, modules, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Modules), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(disasm)) { disasm = df_view_alloc(); - df_view_equip_spec(disasm, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Disassembly), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, disasm, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Disassembly), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } if(df_view_is_nil(memory)) { memory = df_view_alloc(); - df_view_equip_spec(memory, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Memory), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, memory, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Memory), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); } // rjf: root split @@ -1408,8 +1457,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_1 = df_panel_alloc(ws); df_panel_insert(ws->root_panel, ws->root_panel->last, root_0); df_panel_insert(ws->root_panel, ws->root_panel->last, root_1); - root_0->size_pct_of_parent = root_0->size_pct_of_parent_target = v2f32(0.85f, 1.f); - root_1->size_pct_of_parent = root_1->size_pct_of_parent_target = v2f32(0.15f, 1.f); + root_0->pct_of_parent = 0.85f; + root_1->pct_of_parent = 0.15f; // rjf: root_0 split root_0->split_axis = Axis2_Y; @@ -1417,8 +1466,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_0_1 = df_panel_alloc(ws); df_panel_insert(root_0, root_0->last, root_0_0); df_panel_insert(root_0, root_0->last, root_0_1); - root_0_0->size_pct_of_parent = root_0_0->size_pct_of_parent_target = v2f32(1.f, 0.80f); - root_0_1->size_pct_of_parent = root_0_1->size_pct_of_parent_target = v2f32(1.f, 0.20f); + root_0_0->pct_of_parent = 0.80f; + root_0_1->pct_of_parent = 0.20f; // rjf: root_1 split root_1->split_axis = Axis2_Y; @@ -1426,8 +1475,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_1_1 = df_panel_alloc(ws); df_panel_insert(root_1, root_1->last, root_1_0); df_panel_insert(root_1, root_1->last, root_1_1); - root_1_0->size_pct_of_parent = root_1_0->size_pct_of_parent_target = v2f32(1.f, 0.50f); - root_1_1->size_pct_of_parent = root_1_1->size_pct_of_parent_target = v2f32(1.f, 0.50f); + root_1_0->pct_of_parent = 0.50f; + root_1_1->pct_of_parent = 0.50f; df_panel_insert_tab_view(root_1_0, root_1_0->last_tab_view, targets); df_panel_insert_tab_view(root_1_1, root_1_1->last_tab_view, scheduler); root_1_0->selected_tab_view = df_handle_from_view(targets); @@ -1440,8 +1489,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_0_0_1 = df_panel_alloc(ws); df_panel_insert(root_0_0, root_0_0->last, root_0_0_0); df_panel_insert(root_0_0, root_0_0->last, root_0_0_1); - root_0_0_0->size_pct_of_parent = root_0_0_0->size_pct_of_parent_target = v2f32(0.25f, 1.f); - root_0_0_1->size_pct_of_parent = root_0_0_1->size_pct_of_parent_target = v2f32(0.75f, 1.f); + root_0_0_0->pct_of_parent = 0.25f; + root_0_0_1->pct_of_parent = 0.75f; // rjf: root_0_0_0 split root_0_0_0->split_axis = Axis2_Y; @@ -1449,8 +1498,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_0_0_0_1 = df_panel_alloc(ws); df_panel_insert(root_0_0_0, root_0_0_0->last, root_0_0_0_0); df_panel_insert(root_0_0_0, root_0_0_0->last, root_0_0_0_1); - root_0_0_0_0->size_pct_of_parent = root_0_0_0_0->size_pct_of_parent_target = v2f32(1.f, 0.5f); - root_0_0_0_1->size_pct_of_parent = root_0_0_0_1->size_pct_of_parent_target = v2f32(1.f, 0.5f); + root_0_0_0_0->pct_of_parent = 0.5f; + root_0_0_0_1->pct_of_parent = 0.5f; df_panel_insert_tab_view(root_0_0_0_0, root_0_0_0_0->last_tab_view, disasm); root_0_0_0_0->selected_tab_view = df_handle_from_view(disasm); df_panel_insert_tab_view(root_0_0_0_1, root_0_0_0_1->last_tab_view, breakpoints); @@ -1465,8 +1514,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *root_0_1_1 = df_panel_alloc(ws); df_panel_insert(root_0_1, root_0_1->last, root_0_1_0); df_panel_insert(root_0_1, root_0_1->last, root_0_1_1); - root_0_1_0->size_pct_of_parent = root_0_1_0->size_pct_of_parent_target = v2f32(0.60f, 1.f); - root_0_1_1->size_pct_of_parent = root_0_1_1->size_pct_of_parent_target = v2f32(0.40f, 1.f); + root_0_1_0->pct_of_parent = 0.60f; + root_0_1_1->pct_of_parent = 0.40f; df_panel_insert_tab_view(root_0_1_0, root_0_1_0->last_tab_view, watch); df_panel_insert_tab_view(root_0_1_0, root_0_1_0->last_tab_view, locals); df_panel_insert_tab_view(root_0_1_0, root_0_1_0->last_tab_view, regs); @@ -1573,7 +1622,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D focus_panel_dir:; { DF_Panel *src_panel = ws->focused_panel; - Rng2F32 src_panel_rect = df_rect_from_panel(r2f32(v2f32(0, 0), v2f32(1000, 1000)), ws->root_panel, src_panel); + Rng2F32 src_panel_rect = df_target_rect_from_panel(r2f32(v2f32(0, 0), v2f32(1000, 1000)), ws->root_panel, src_panel); Vec2F32 src_panel_center = center_2f32(src_panel_rect); Vec2F32 src_panel_half_dim = scale_2f32(dim_2f32(src_panel_rect), 0.5f); Vec2F32 travel_dim = add_2f32(src_panel_half_dim, v2f32(10.f, 10.f)); @@ -1585,7 +1634,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { continue; } - Rng2F32 p_rect = df_rect_from_panel(r2f32(v2f32(0, 0), v2f32(1000, 1000)), ws->root_panel, p); + Rng2F32 p_rect = df_target_rect_from_panel(r2f32(v2f32(0, 0), v2f32(1000, 1000)), ws->root_panel, p); if(contains_2f32(p_rect, travel_dst)) { dst_root = p; @@ -1637,7 +1686,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *keep_child = panel == parent->first ? parent->last : parent->first; DF_Panel *grandparent = parent->parent; DF_Panel *parent_prev = parent->prev; - Vec2F32 size_pct_of_parent = parent->size_pct_of_parent_target; + F32 pct_of_parent = parent->pct_of_parent; // rjf: unhook kept child df_panel_remove(parent, keep_child); @@ -1663,9 +1712,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { df_panel_insert(grandparent, parent_prev, keep_child); } - keep_child->size_pct_of_parent_target = size_pct_of_parent; - keep_child->size_pct_of_parent.v[split_axis] *= size_pct_of_parent.v[split_axis]; - keep_child->size_pct_of_parent.v[axis2_flip(split_axis)] *= size_pct_of_parent.v[axis2_flip(split_axis)]; + keep_child->pct_of_parent = pct_of_parent; // rjf: reset focus, if needed if(ws->focused_panel == discard_child) @@ -1688,8 +1735,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D df_panel_remove(keep_child, child); df_panel_insert(grandparent, prev, child); prev = child; - child->size_pct_of_parent_target.v[keep_child->split_axis] *= keep_child->size_pct_of_parent_target.v[grandparent->split_axis]; - child->size_pct_of_parent.v[keep_child->split_axis] *= keep_child->size_pct_of_parent_target.v[grandparent->split_axis]; + child->pct_of_parent *= keep_child->pct_of_parent; } df_panel_release(ws, keep_child); } @@ -1698,7 +1744,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D else { DF_Panel *next = &df_g_nil_panel; - F32 removed_size_pct = panel->size_pct_of_parent_target.v[parent->split_axis]; + F32 removed_size_pct = panel->pct_of_parent; if(df_panel_is_nil(next)) { next = panel->prev; } if(df_panel_is_nil(next)) { next = panel->next; } df_panel_remove(parent, panel); @@ -1709,7 +1755,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } for(DF_Panel *child = parent->first; !df_panel_is_nil(child); child = child->next) { - child->size_pct_of_parent_target.v[parent->split_axis] /= 1.f-removed_size_pct; + child->pct_of_parent /= 1.f-removed_size_pct; } } } @@ -1766,7 +1812,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(!df_panel_is_nil(panel) && spec != &df_g_nil_view_spec) { DF_View *view = df_view_alloc(); - df_view_equip_spec(view, spec, entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, spec, entity, params.string, params.cfg_node); df_panel_insert_tab_view(panel, panel->last_tab_view, view); df_panel_notify_mutation(ws, panel); } @@ -1795,6 +1841,11 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D df_panel_remove_tab_view(src_panel, view); df_panel_insert_tab_view(dst_panel, prev_view, view); ws->focused_panel = dst_panel; + if(df_view_is_nil(src_panel->first_tab_view) && src_panel != ws->root_panel) + { + DF_CmdParams p = df_cmd_params_from_panel(ws, src_panel); + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ClosePanel)); + } df_panel_notify_mutation(ws, dst_panel); } }break; @@ -2637,7 +2688,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { continue; } - Rng2F32 panel_rect = df_rect_from_panel(root_rect, ws->root_panel, panel); + Rng2F32 panel_rect = df_target_rect_from_panel(root_rect, ws->root_panel, panel); Vec2F32 panel_rect_dim = dim_2f32(panel_rect); F32 area = panel_rect_dim.x * panel_rect_dim.y; if((best_panel_area == 0 || area > best_panel_area)) @@ -2659,7 +2710,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { continue; } - Rng2F32 panel_rect = df_rect_from_panel(root_rect, ws->root_panel, panel); + Rng2F32 panel_rect = df_target_rect_from_panel(root_rect, ws->root_panel, panel); Vec2F32 panel_rect_dim = dim_2f32(panel_rect); F32 area = panel_rect_dim.x * panel_rect_dim.y; if(df_view_is_nil(panel->first_tab_view) && (best_panel_area == 0 || area > best_panel_area)) @@ -2689,7 +2740,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(!df_panel_is_nil(dst_panel) && df_view_is_nil(view_w_this_src_code)) { DF_View *view = df_view_alloc(); - df_view_equip_spec(view, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Code), src_code, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Code), src_code, str8_lit(""), &df_g_nil_cfg_node); df_panel_insert_tab_view(dst_panel, dst_panel->last_tab_view, view); dst_view = view; } @@ -2737,7 +2788,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(!df_panel_is_nil(dst_panel) && df_view_is_nil(view_w_disasm)) { DF_View *view = df_view_alloc(); - df_view_equip_spec(view, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Disassembly), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, df_view_spec_from_gfx_view_kind(DF_GfxViewKind_Disassembly), &df_g_nil_entity, str8_lit(""), &df_g_nil_cfg_node); df_panel_insert_tab_view(dst_panel, dst_panel->last_tab_view, view); dst_view = view; } @@ -2939,6 +2990,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D Rng2F32 top_bar_rect = r2f32p(window_rect.x0, window_rect.y0, window_rect.x0+window_rect_dim.x, window_rect.y0+ui_top_pref_height().value); Rng2F32 bottom_bar_rect = r2f32p(window_rect.x0, window_rect_dim.y - ui_top_pref_height().value, window_rect.x0+window_rect_dim.x, window_rect.y0+window_rect_dim.y); Rng2F32 content_rect = r2f32p(window_rect.x0, top_bar_rect.y1, window_rect.x0+window_rect_dim.x, bottom_bar_rect.y0); + F32 window_edge_px = os_dpi_from_window(ws->os)*0.035f; + content_rect = pad_2f32(content_rect, -window_edge_px); //////////////////////////// //- rjf: truncated string hover @@ -2964,26 +3017,50 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Panel *panel = df_panel_from_handle(payload->panel); DF_Entity *entity = df_entity_from_handle(payload->entity); DF_View *view = df_view_from_handle(payload->view); - UI_Tooltip { - UI_Box *tooltip = ui_top_parent(); + //- rjf: tab dragging if(!df_view_is_nil(view)) { - ui_set_next_pref_width(ui_children_sum(1)); - UI_Row UI_HeightFill + UI_Size main_width = ui_top_pref_width(); + UI_Size main_height = ui_top_pref_height(); + UI_TextAlign main_text_align = ui_top_text_alignment(); + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_TabActive)); + UI_Tooltip UI_PrefWidth(main_width) UI_PrefHeight(main_height) UI_TextAlignment(main_text_align) { - DF_CtrlCtx ctrl_ctx = df_ctrl_ctx_from_view(ws, view); - String8 display_name = df_display_string_from_view(scratch.arena, ctrl_ctx, view); - DF_IconKind icon_kind = df_icon_kind_from_view(view); - UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) - UI_Font(df_font_from_slot(DF_FontSlot_Icons)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) - ui_label(df_g_icon_kind_text_table[icon_kind]); - ui_label(display_name); - tooltip->background_color = df_rgba_from_theme_color(DF_ThemeColor_TabActive); + ui_set_next_pref_width(ui_em(60.f, 1.f)); + ui_set_next_pref_height(ui_em(40.f, 1.f)); + ui_set_next_child_layout_axis(Axis2_Y); + UI_Box *container = ui_build_box_from_key(0, ui_key_zero()); + UI_Parent(container) + { + UI_Row + { + DF_CtrlCtx ctrl_ctx = df_ctrl_ctx_from_view(ws, view); + String8 display_name = df_display_string_from_view(scratch.arena, ctrl_ctx, view); + DF_IconKind icon_kind = df_icon_kind_from_view(view); + UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) + UI_Font(df_font_from_slot(DF_FontSlot_Icons)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) + UI_PrefWidth(ui_em(2.5f, 1.f)) + ui_label(df_g_icon_kind_text_table[icon_kind]); + ui_label(display_name); + } + ui_set_next_pref_width(ui_pct(1, 0)); + ui_set_next_pref_height(ui_pct(1, 0)); + ui_set_next_child_layout_axis(Axis2_Y); + UI_Box *view_preview_container = ui_build_box_from_stringf(UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clip, "###view_preview_container"); + UI_Parent(view_preview_container) UI_Focus(UI_FocusKind_Off) UI_WidthFill + { + DF_ViewSpec *view_spec = view->spec; + DF_ViewUIFunctionType *build_view_ui_function = view_spec->info.ui_hook; + build_view_ui_function(ws, &df_g_nil_panel, view, view_preview_container->rect); + } + } } } - if(!df_entity_is_nil(entity)) + + //- rjf: entity dragging + else if(!df_entity_is_nil(entity)) UI_Tooltip { ui_set_next_pref_width(ui_children_sum(1)); UI_Row UI_HeightFill @@ -2995,7 +3072,6 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) ui_label(df_g_icon_kind_text_table[icon_kind]); ui_label(display_name); - tooltip->background_color = df_rgba_from_theme_color(DF_ThemeColor_EntityBackground); } } } @@ -3801,11 +3877,11 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D //- rjf: confirmation popup // { - if(df_gfx_state->confirm_t > 0.005f) UI_TextAlignment(UI_TextAlign_Center) + if(df_gfx_state->confirm_t > 0.005f) UI_TextAlignment(UI_TextAlign_Center) UI_Focus(df_gfx_state->confirm_active ? UI_FocusKind_Root : UI_FocusKind_Off) { Vec2F32 window_dim = dim_2f32(window_rect); UI_Box *bg_box = &ui_g_nil_box; - UI_Rect(window_rect) UI_ChildLayoutAxis(Axis2_X) + UI_Rect(window_rect) UI_ChildLayoutAxis(Axis2_X) UI_Focus(UI_FocusKind_On) { Vec4F32 bg_color = ui_top_background_color(); bg_color.w *= df_gfx_state->confirm_t; @@ -3828,7 +3904,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_ActionBackground)) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_ActionText)) UI_BorderColor(df_rgba_from_theme_color(DF_ThemeColor_ActionBorder)) - if(ui_clicked(ui_buttonf("OK")) || os_key_press(ui_events(), ui_window(), 0, OS_Key_Return)) + if(ui_clicked(ui_buttonf("OK")) || (ui_key_match(bg_box->default_nav_focus_hot_key, ui_key_zero()) && os_key_press(ui_events(), ui_window(), 0, OS_Key_Return))) { DF_CmdParams p = df_cmd_params_zero(); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ConfirmAccept)); @@ -4039,6 +4115,9 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D // ProfScope("build top bar") { + os_window_clear_custom_border_data(ws->os); + os_window_push_custom_edges(ws->os, window_edge_px); + os_window_push_custom_title_bar(ws->os, dim_2f32(top_bar_rect).y); ui_set_next_flags(UI_BoxFlag_DefaultFocusNav); UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_AltBackground)) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_AltText)) @@ -4050,577 +4129,767 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { MemoryZeroArray(ui_top_parent()->parent->corner_radii); - // rjf: menu items - UI_PrefWidth(ui_text_dim(20, 1)) + //- rjf: left column + ui_set_next_flags(UI_BoxFlag_Clip|UI_BoxFlag_ViewScrollX|UI_BoxFlag_ViewClamp); + UI_WidthFill UI_NamedRow(str8_lit("###menu_bar")) { - // rjf: file menu - UI_Key file_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_file_menu_key_")); - UI_CtxMenu(file_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + //- rjf: icon + UI_Padding(ui_em(0.5f, 1.f)) UI_PrefWidth(ui_px(dim_2f32(top_bar_rect).y, 1.f)) { - DF_CoreCmdKind cmds[] = - { - DF_CoreCmdKind_Open, - DF_CoreCmdKind_OpenUser, - DF_CoreCmdKind_OpenProfile, - DF_CoreCmdKind_Exit, - }; - U32 codepoints[] = - { - 'o', - 'u', - 'p', - 'x', - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + R_Handle texture = df_gfx_state->icon_texture; + Vec2S32 texture_dim = r_size_from_tex2d(texture); + ui_image(texture, R_Tex2DSampleKind_Linear, r2f32p(0, 0, texture_dim.x, texture_dim.y), v4f32(1, 1, 1, 1), 0, str8_lit("")); } - // rjf: window menu - UI_Key window_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_window_menu_key_")); - UI_CtxMenu(window_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + //- rjf: menu items + ui_set_next_flags(UI_BoxFlag_DrawBackground); + UI_PrefWidth(ui_children_sum(1)) UI_Row UI_PrefWidth(ui_text_dim(20, 1)) { - DF_CoreCmdKind cmds[] = + // rjf: file menu + UI_Key file_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_file_menu_key_")); + UI_CtxMenu(file_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) { - DF_CoreCmdKind_OpenWindow, - DF_CoreCmdKind_CloseWindow, - DF_CoreCmdKind_ToggleFullscreen, - }; - U32 codepoints[] = + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_Open, + DF_CoreCmdKind_OpenUser, + DF_CoreCmdKind_OpenProfile, + DF_CoreCmdKind_Exit, + }; + U32 codepoints[] = + { + 'o', + 'u', + 'p', + 'x', + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + } + + // rjf: window menu + UI_Key window_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_window_menu_key_")); + UI_CtxMenu(window_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) { - 'w', - 'c', - 'f', - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_OpenWindow, + DF_CoreCmdKind_CloseWindow, + DF_CoreCmdKind_ToggleFullscreen, + }; + U32 codepoints[] = + { + 'w', + 'c', + 'f', + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + } + + // rjf: panel menu + UI_Key panel_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_panel_menu_key_")); + UI_CtxMenu(panel_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + { + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_NewPanelRight, + DF_CoreCmdKind_NewPanelDown, + DF_CoreCmdKind_ClosePanel, + DF_CoreCmdKind_RotatePanelColumns, + DF_CoreCmdKind_NextPanel, + DF_CoreCmdKind_PrevPanel, + DF_CoreCmdKind_CloseTab, + DF_CoreCmdKind_NextTab, + DF_CoreCmdKind_PrevTab, + DF_CoreCmdKind_TabBarTop, + DF_CoreCmdKind_TabBarBottom, + DF_CoreCmdKind_ResetToDefaultPanels, + }; + U32 codepoints[] = + { + 'r', + 'd', + 'x', + 'c', + 'n', + 'p', + 't', + 'b', + 'v', + 0, + 0, + 0, + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + } + + // rjf: view menu + UI_Key view_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_view_menu_key_")); + UI_CtxMenu(view_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + { + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_Targets, + DF_CoreCmdKind_Scheduler, + DF_CoreCmdKind_CallStack, + DF_CoreCmdKind_Modules, + DF_CoreCmdKind_Output, + DF_CoreCmdKind_Memory, + DF_CoreCmdKind_Disassembly, + DF_CoreCmdKind_Watch, + DF_CoreCmdKind_Locals, + DF_CoreCmdKind_Registers, + DF_CoreCmdKind_Globals, + DF_CoreCmdKind_ThreadLocals, + DF_CoreCmdKind_Types, + DF_CoreCmdKind_Procedures, + DF_CoreCmdKind_Breakpoints, + DF_CoreCmdKind_WatchPins, + DF_CoreCmdKind_FilePathMap, + DF_CoreCmdKind_Theme, + DF_CoreCmdKind_ExceptionFilters, + }; + U32 codepoints[] = + { + 't', + 's', + 'k', + 'd', + 'o', + 'm', + 'y', + 'w', + 'l', + 'r', + 0, + 0, + 0, + 0, + 'b', + 'h', + 'p', + 'e', + 'g', + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + } + + // rjf: targets menu + UI_Key targets_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_targets_menu_key_")); + UI_CtxMenu(targets_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + { + Temp scratch = scratch_begin(&arena, 1); + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_AddTarget, + DF_CoreCmdKind_EditTarget, + DF_CoreCmdKind_RemoveTarget, + }; + U32 codepoints[] = + { + 'a', + 'e', + 'r', + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + DF_EntityList targets_list = df_query_cached_entity_list_with_kind(DF_EntityKind_Target); + for(DF_EntityNode *n = targets_list.first; n != 0; n = n->next) + { + DF_Entity *target = n->entity; + Vec4F32 color = ui_top_text_color(); + if(target->flags & DF_EntityFlag_HasColor) + { + color = df_rgba_from_entity(target); + } + String8 target_name = df_display_string_from_entity(scratch.arena, target); + UI_Signal sig = {0}; + UI_TextColor(color) + sig = df_icon_buttonf(DF_IconKind_Target, 0, "%S##%p", target_name, target); + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + params.entity = df_handle_from_entity(target); + df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_Entity); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_EditTarget)); + ui_ctx_menu_close(); + ws->menu_bar_focused = 0; + } + } + scratch_end(scratch); + } + + // rjf: ctrl menu + UI_Key ctrl_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_ctrl_menu_key_")); + UI_CtxMenu(ctrl_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + { + DF_CoreCmdKind cmds[] = + { + DF_CoreCmdKind_Run, + DF_CoreCmdKind_KillAll, + DF_CoreCmdKind_Restart, + DF_CoreCmdKind_Halt, + DF_CoreCmdKind_SoftHaltRefresh, + DF_CoreCmdKind_StepInto, + DF_CoreCmdKind_StepOver, + DF_CoreCmdKind_StepOut, + DF_CoreCmdKind_Attach, + }; + U32 codepoints[] = + { + 'r', + 'k', + 's', + 'h', + 'f', + 'i', + 'o', + 't', + 'a', + }; + Assert(ArrayCount(codepoints) == ArrayCount(cmds)); + df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); + } + + // rjf: help menu + UI_Key help_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_help_menu_key_")); + UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(60.f, 1.f)) + { + UI_Row UI_TextAlignment(UI_TextAlign_Center) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) + ui_label(str8_lit(BUILD_TITLE_STRING_LITERAL)); + UI_PrefHeight(ui_children_sum(1)) UI_Row UI_Padding(ui_pct(1, 0)) + { + R_Handle texture = df_gfx_state->icon_texture; + Vec2S32 texture_dim = r_size_from_tex2d(texture); + UI_PrefWidth(ui_px(ui_top_font_size()*10.f, 1.f)) + UI_PrefHeight(ui_px(ui_top_font_size()*10.f, 1.f)) + ui_image(texture, R_Tex2DSampleKind_Linear, r2f32p(0, 0, texture_dim.x, texture_dim.y), v4f32(1, 1, 1, 1), 0, str8_lit("")); + } + ui_spacer(ui_em(0.25f, 1.f)); + UI_Row + UI_PrefWidth(ui_text_dim(10, 1)) + UI_TextAlignment(UI_TextAlign_Center) + UI_Padding(ui_pct(1, 0)) + { + ui_labelf("Search for commands by pressing "); + DF_CmdSpec *spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand); + UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_PlainText)) + UI_Flags(UI_BoxFlag_DrawBorder) + UI_TextAlignment(UI_TextAlign_Center) + df_cmd_binding_button(spec); + } + ui_spacer(ui_em(0.25f, 1.f)); + UI_Row UI_TextAlignment(UI_TextAlign_Center) ui_label(str8_lit("Submit issues to the GitHub at:")); + UI_TextAlignment(UI_TextAlign_Center) + { + UI_Signal url_sig = ui_buttonf("github.com/EpicGames/raddebugger"); + if(ui_hovering(url_sig)) UI_Tooltip + { + ui_labelf("Copy To Clipboard"); + } + if(ui_clicked(url_sig)) + { + os_set_clipboard_text(str8_lit("https://github.com/EpicGames/raddebugger")); + } + } + } + + // rjf: buttons + UI_TextAlignment(UI_TextAlign_Center) UI_HeightFill + { + // rjf: set up table + struct + { + String8 name; + U32 codepoint; + OS_Key key; + UI_Key menu_key; + } + items[] = + { + {str8_lit("File"), 'f', OS_Key_F, file_menu_key}, + {str8_lit("Window"), 'w', OS_Key_W, window_menu_key}, + {str8_lit("Panel"), 'p', OS_Key_P, panel_menu_key}, + {str8_lit("View"), 'v', OS_Key_V, view_menu_key}, + {str8_lit("Targets"), 't', OS_Key_T, targets_menu_key}, + {str8_lit("Control"), 'c', OS_Key_C, ctrl_menu_key}, + {str8_lit("Help"), 'h', OS_Key_H, help_menu_key}, + }; + + // rjf: determine if one of the menus is already open + B32 menu_open = 0; + U64 open_menu_idx = 0; + for(U64 idx = 0; idx < ArrayCount(items); idx += 1) + { + if(ui_ctx_menu_is_open(items[idx].menu_key)) + { + menu_open = 1; + open_menu_idx = idx; + break; + } + } + + // rjf: navigate between menus + U64 open_menu_idx_prime = open_menu_idx; + if(menu_open && ws->menu_bar_focused && window_is_focused) + { + UI_NavActionList *nav_actions = ui_nav_actions(); + for(UI_NavActionNode *n = nav_actions->first, *next = 0; + n != 0; + n = next) + { + next = n->next; + UI_NavAction *action = &n->v; + B32 taken = 0; + if(action->delta.x > 0) + { + taken = 1; + open_menu_idx_prime += 1; + open_menu_idx_prime = open_menu_idx_prime%ArrayCount(items); + } + if(action->delta.x < 0) + { + taken = 1; + open_menu_idx_prime = open_menu_idx_prime > 0 ? open_menu_idx_prime-1 : (ArrayCount(items)-1); + } + if(taken) + { + ui_nav_eat_action_node(nav_actions, n); + } + } + } + + // rjf: make ui + for(U64 idx = 0; idx < ArrayCount(items); idx += 1) + { + ui_set_next_fastpath_codepoint(items[idx].codepoint); + B32 alt_fastpath_key = 0; + if(os_key_press(ui_events(), ui_window(), OS_EventFlag_Alt, items[idx].key)) + { + alt_fastpath_key = 1; + } + if((ws->menu_bar_key_held || ws->menu_bar_focused) && !ui_any_ctx_menu_is_open()) + { + ui_set_next_flags(UI_BoxFlag_DrawTextFastpathCodepoint); + } + UI_Signal sig = df_menu_bar_button(items[idx].name); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(menu_open) + { + if((ui_hovering(sig) && !ui_ctx_menu_is_open(items[idx].menu_key)) || (open_menu_idx_prime == idx && open_menu_idx_prime != open_menu_idx)) + { + ui_ctx_menu_open(items[idx].menu_key, sig.box->key, v2f32(0, sig.box->rect.y1-sig.box->rect.y0)); + } + } + else if(ui_pressed(sig) || alt_fastpath_key) + { + if(ui_ctx_menu_is_open(items[idx].menu_key)) + { + ui_ctx_menu_close(); + } + else + { + ui_ctx_menu_open(items[idx].menu_key, sig.box->key, v2f32(0, sig.box->rect.y1-sig.box->rect.y0)); + } + } + } + } } - // rjf: panel menu - UI_Key panel_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_panel_menu_key_")); - UI_CtxMenu(panel_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) - { - DF_CoreCmdKind cmds[] = - { - DF_CoreCmdKind_NewPanelRight, - DF_CoreCmdKind_NewPanelDown, - DF_CoreCmdKind_ClosePanel, - DF_CoreCmdKind_RotatePanelColumns, - DF_CoreCmdKind_NextPanel, - DF_CoreCmdKind_PrevPanel, - DF_CoreCmdKind_CloseTab, - DF_CoreCmdKind_NextTab, - DF_CoreCmdKind_PrevTab, - DF_CoreCmdKind_TabBarTop, - DF_CoreCmdKind_TabBarBottom, - DF_CoreCmdKind_ResetToDefaultPanels, - }; - U32 codepoints[] = - { - 'r', - 'd', - 'x', - 'c', - 'n', - 'p', - 't', - 'b', - 'v', - 0, - 0, - 0, - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); - } + ui_spacer(ui_em(0.75f, 1)); - // rjf: view menu - UI_Key view_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_view_menu_key_")); - UI_CtxMenu(view_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) - { - DF_CoreCmdKind cmds[] = - { - DF_CoreCmdKind_Targets, - DF_CoreCmdKind_Scheduler, - DF_CoreCmdKind_CallStack, - DF_CoreCmdKind_Modules, - DF_CoreCmdKind_Output, - DF_CoreCmdKind_Memory, - DF_CoreCmdKind_Disassembly, - DF_CoreCmdKind_Watch, - DF_CoreCmdKind_Locals, - DF_CoreCmdKind_Registers, - DF_CoreCmdKind_Globals, - DF_CoreCmdKind_ThreadLocals, - DF_CoreCmdKind_Types, - DF_CoreCmdKind_Procedures, - DF_CoreCmdKind_Breakpoints, - DF_CoreCmdKind_WatchPins, - DF_CoreCmdKind_FilePathMap, - DF_CoreCmdKind_Theme, - DF_CoreCmdKind_ExceptionFilters, - }; - U32 codepoints[] = - { - 't', - 's', - 'k', - 'd', - 'o', - 'm', - 'y', - 'w', - 'l', - 'r', - 0, - 0, - 0, - 0, - 'b', - 'h', - 'p', - 'e', - 'g', - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); - } - - // rjf: targets menu - UI_Key targets_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_targets_menu_key_")); - UI_CtxMenu(targets_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + // rjf: conversion task visualization + UI_PrefWidth(ui_text_dim(10, 1)) UI_HeightFill UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_Highlight1)) { Temp scratch = scratch_begin(&arena, 1); - DF_CoreCmdKind cmds[] = + DF_EntityList tasks = df_query_cached_entity_list_with_kind(DF_EntityKind_ConversionTask); + for(DF_EntityNode *n = tasks.first; n != 0; n = n->next) { - DF_CoreCmdKind_AddTarget, - DF_CoreCmdKind_EditTarget, - DF_CoreCmdKind_RemoveTarget, - }; - U32 codepoints[] = - { - 'a', - 'e', - 'r', - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); - DF_EntityList targets_list = df_query_cached_entity_list_with_kind(DF_EntityKind_Target); - for(DF_EntityNode *n = targets_list.first; n != 0; n = n->next) - { - DF_Entity *target = n->entity; - Vec4F32 color = ui_top_text_color(); - if(target->flags & DF_EntityFlag_HasColor) + DF_Entity *task = n->entity; + if(task->alloc_time_us + 500000 < os_now_microseconds()) { - color = df_rgba_from_entity(target); - } - String8 target_name = df_display_string_from_entity(scratch.arena, target); - UI_Signal sig = {0}; - UI_TextColor(color) - sig = df_icon_buttonf(DF_IconKind_Target, 0, "%S##%p", target_name, target); - if(ui_clicked(sig)) - { - DF_CmdParams params = df_cmd_params_from_window(ws); - params.entity = df_handle_from_entity(target); - df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_Entity); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_EditTarget)); - ui_ctx_menu_close(); - ws->menu_bar_focused = 0; + String8 rdi_path = task->name; + String8 rdi_name = str8_skip_last_slash(rdi_path); + String8 task_text = push_str8f(scratch.arena, "Creating %S...", rdi_name); + UI_Key key = ui_key_from_stringf(ui_key_zero(), "task_%p", task); + UI_Box *box = ui_build_box_from_key(UI_BoxFlag_DrawHotEffects|UI_BoxFlag_DrawText|UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clickable, key); + os_window_push_custom_title_bar_client_area(ws->os, box->rect); + UI_Signal sig = ui_signal_from_box(box); + if(ui_hovering(sig)) UI_Tooltip + { + ui_label(rdi_path); + } + ui_box_equip_display_string(box, task_text); } } scratch_end(scratch); } - - // rjf: ctrl menu - UI_Key ctrl_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_ctrl_menu_key_")); - UI_CtxMenu(ctrl_menu_key) UI_PrefWidth(ui_em(30.f, 1.f)) + } + + //- rjf: center column + UI_PrefWidth(ui_children_sum(1.f)) UI_Row + { + // rjf: fast-paths + UI_PrefWidth(ui_em(2.25f, 1)) + UI_Font(df_font_from_slot(DF_FontSlot_Icons)) + UI_FontSize(ui_top_font_size()*0.85f) { - DF_CoreCmdKind cmds[] = - { - DF_CoreCmdKind_Run, - DF_CoreCmdKind_KillAll, - DF_CoreCmdKind_Restart, - DF_CoreCmdKind_Halt, - DF_CoreCmdKind_SoftHaltRefresh, - DF_CoreCmdKind_StepInto, - DF_CoreCmdKind_StepOver, - DF_CoreCmdKind_StepOut, - DF_CoreCmdKind_Attach, - }; - U32 codepoints[] = - { - 'r', - 'k', - 's', - 'h', - 'f', - 'i', - 'o', - 't', - 'a', - }; - Assert(ArrayCount(codepoints) == ArrayCount(cmds)); - df_cmd_list_menu_buttons(ws, ArrayCount(cmds), cmds, codepoints); - } - - // rjf: help menu - UI_Key help_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_help_menu_key_")); - UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(40.f, 1.f)) - { - UI_Row UI_TextAlignment(UI_TextAlign_Center) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) - ui_label(str8_lit(BUILD_TITLE_STRING_LITERAL)); - ui_spacer(ui_em(0.25f, 1.f)); - UI_Row - UI_PrefWidth(ui_text_dim(10, 1)) - UI_TextAlignment(UI_TextAlign_Center) - UI_Padding(ui_pct(1, 0)) - { - ui_labelf("Search for commands by pressing "); - DF_CmdSpec *spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand); - UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_PlainText)) - UI_Flags(UI_BoxFlag_DrawBorder) - UI_TextAlignment(UI_TextAlign_Center) - df_cmd_binding_button(spec); - } - ui_spacer(ui_em(0.25f, 1.f)); - UI_Row UI_TextAlignment(UI_TextAlign_Center) ui_label(str8_lit("Submit issues to the GitHub at:")); - UI_TextAlignment(UI_TextAlign_Center) - { - UI_Signal url_sig = ui_buttonf("github.com/EpicGames/raddebugger"); - if(ui_hovering(url_sig)) UI_Tooltip - { - ui_labelf("Copy To Clipboard"); - } - if(ui_clicked(url_sig)) - { - os_set_clipboard_text(str8_lit("https://github.com/EpicGames/raddebugger")); - } - } - } - - // rjf: buttons - UI_TextAlignment(UI_TextAlign_Center) UI_HeightFill - { - // rjf: set up table - struct - { - String8 name; - U32 codepoint; - OS_Key key; - UI_Key menu_key; - } - items[] = - { - {str8_lit("File"), 'f', OS_Key_F, file_menu_key}, - {str8_lit("Window"), 'w', OS_Key_W, window_menu_key}, - {str8_lit("Panel"), 'p', OS_Key_P, panel_menu_key}, - {str8_lit("View"), 'v', OS_Key_V, view_menu_key}, - {str8_lit("Targets"), 't', OS_Key_T, targets_menu_key}, - {str8_lit("Control"), 'c', OS_Key_C, ctrl_menu_key}, - {str8_lit("Help"), 'h', OS_Key_H, help_menu_key}, - }; + Temp scratch = scratch_begin(&arena, 1); + DF_EntityList targets = df_push_active_target_list(scratch.arena); + DF_EntityList processes = df_query_cached_entity_list_with_kind(DF_EntityKind_Process); + B32 have_targets = targets.count != 0; + B32 can_send_signal = !df_ctrl_targets_running(); + B32 can_play = (have_targets && (can_send_signal || df_ctrl_last_run_frame_idx()+4 > df_frame_index())); + B32 can_pause = (!can_send_signal); + B32 can_stop = (processes.count != 0); + B32 can_step = (processes.count != 0 && can_send_signal); - // rjf: determine if one of the menus is already open - B32 menu_open = 0; - U64 open_menu_idx = 0; - for(U64 idx = 0; idx < ArrayCount(items); idx += 1) + if(can_play || !have_targets || + processes.count == 0) UI_TextAlignment(UI_TextAlign_Center) UI_Flags((can_play ? 0 : UI_BoxFlag_Disabled)) { - if(ui_ctx_menu_is_open(items[idx].menu_key)) + ui_set_next_text_color(v4f32(0.3f, 0.8f, 0.2f, 1.f)); + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Play]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig) && !can_play) { - menu_open = 1; - open_menu_idx = idx; - break; + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: %s", have_targets ? "Targets are currently running" : "No active targets exist"); } - } - - // rjf: navigate between menus - U64 open_menu_idx_prime = open_menu_idx; - if(menu_open && ws->menu_bar_focused && window_is_focused) - { - UI_NavActionList *nav_actions = ui_nav_actions(); - for(UI_NavActionNode *n = nav_actions->first, *next = 0; - n != 0; - n = next) + if(ui_hovering(sig) && can_play) { - next = n->next; - UI_NavAction *action = &n->v; - B32 taken = 0; - if(action->delta.x > 0) + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) { - taken = 1; - open_menu_idx_prime += 1; - open_menu_idx_prime = open_menu_idx_prime%ArrayCount(items); - } - if(action->delta.x < 0) - { - taken = 1; - open_menu_idx_prime = open_menu_idx_prime > 0 ? open_menu_idx_prime-1 : (ArrayCount(items)-1); - } - if(taken) - { - ui_nav_eat_action_node(nav_actions, n); - } - } - } - - // rjf: make ui - for(U64 idx = 0; idx < ArrayCount(items); idx += 1) - { - ui_set_next_fastpath_codepoint(items[idx].codepoint); - B32 alt_fastpath_key = 0; - if(os_key_press(ui_events(), ui_window(), OS_EventFlag_Alt, items[idx].key)) - { - alt_fastpath_key = 1; - } - if((ws->menu_bar_key_held || ws->menu_bar_focused) && !ui_any_ctx_menu_is_open()) - { - ui_set_next_flags(UI_BoxFlag_DrawTextFastpathCodepoint); - } - UI_Signal sig = df_menu_bar_button(items[idx].name); - if(menu_open) - { - if((ui_hovering(sig) && !ui_ctx_menu_is_open(items[idx].menu_key)) || (open_menu_idx_prime == idx && open_menu_idx_prime != open_menu_idx)) - { - ui_ctx_menu_open(items[idx].menu_key, sig.box->key, v2f32(0, sig.box->rect.y1-sig.box->rect.y0)); - } - } - else if(ui_pressed(sig) || alt_fastpath_key) - { - if(ui_ctx_menu_is_open(items[idx].menu_key)) - { - ui_ctx_menu_close(); - } - else - { - ui_ctx_menu_open(items[idx].menu_key, sig.box->key, v2f32(0, sig.box->rect.y1-sig.box->rect.y0)); - } - } - } - } - } - - ui_spacer(ui_em(0.75f, 1)); - - // rjf: conversion task visualization - UI_PrefWidth(ui_text_dim(10, 1)) UI_HeightFill UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_Highlight1)) - { - Temp scratch = scratch_begin(&arena, 1); - DF_EntityList tasks = df_query_cached_entity_list_with_kind(DF_EntityKind_ConversionTask); - for(DF_EntityNode *n = tasks.first; n != 0; n = n->next) - { - DF_Entity *task = n->entity; - if(task->alloc_time_us + 500000 < os_now_microseconds()) - { - String8 rdi_path = task->name; - String8 rdi_name = str8_skip_last_slash(rdi_path); - String8 task_text = push_str8f(scratch.arena, "Creating %S...", rdi_name); - UI_Key key = ui_key_from_stringf(ui_key_zero(), "task_%p", task); - UI_Box *box = ui_build_box_from_key(UI_BoxFlag_DrawHotEffects|UI_BoxFlag_DrawText|UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clickable, key); - UI_Signal sig = ui_signal_from_box(box); - if(ui_hovering(sig)) UI_Tooltip - { - ui_label(rdi_path); - } - ui_box_equip_display_string(box, task_text); - } - } - scratch_end(scratch); - } - - ui_spacer(ui_pct(1, 0)); - - // rjf: loaded user viz - { - ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight1)); - ui_set_next_pref_width(ui_children_sum(1)); - ui_set_next_child_layout_axis(Axis2_X); - ui_set_next_hover_cursor(OS_Cursor_HandPoint); - UI_Box *user_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable| - UI_BoxFlag_DrawBorder| - UI_BoxFlag_DrawBackground| - UI_BoxFlag_DrawHotEffects| - UI_BoxFlag_DrawActiveEffects, - "###loaded_user_button"); - UI_Parent(user_box) UI_PrefWidth(ui_text_dim(10, 1)) UI_TextAlignment(UI_TextAlign_Center) - { - String8 user_path = df_cfg_path_from_src(DF_CfgSrc_User); - UI_Font(ui_icon_font()) ui_label(df_g_icon_kind_text_table[DF_IconKind_Person]); - ui_label(str8_skip_last_slash(user_path)); - } - UI_Signal user_sig = ui_signal_from_box(user_box); - if(ui_clicked(user_sig)) - { - DF_CmdParams p = df_cmd_params_from_window(ws); - p.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OpenUser); - df_cmd_params_mark_slot(&p, DF_CmdParamSlot_CmdSpec); - df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand)); - } - } - - ui_spacer(ui_em(0.75f, 1)); - - // rjf: loaded profile viz - { - ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight0)); - ui_set_next_pref_width(ui_children_sum(1)); - ui_set_next_child_layout_axis(Axis2_X); - ui_set_next_hover_cursor(OS_Cursor_HandPoint); - UI_Box *prof_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable| - UI_BoxFlag_DrawBorder| - UI_BoxFlag_DrawBackground| - UI_BoxFlag_DrawHotEffects| - UI_BoxFlag_DrawActiveEffects, - "###loaded_profile_button"); - UI_Parent(prof_box) UI_PrefWidth(ui_text_dim(10, 1)) UI_TextAlignment(UI_TextAlign_Center) - { - String8 prof_path = df_cfg_path_from_src(DF_CfgSrc_Profile); - UI_Font(ui_icon_font()) ui_label(df_g_icon_kind_text_table[DF_IconKind_Briefcase]); - ui_label(str8_skip_last_slash(prof_path)); - } - UI_Signal prof_sig = ui_signal_from_box(prof_box); - if(ui_clicked(prof_sig)) - { - DF_CmdParams p = df_cmd_params_from_window(ws); - p.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OpenProfile); - df_cmd_params_mark_slot(&p, DF_CmdParamSlot_CmdSpec); - df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand)); - } - } - - ui_spacer(ui_em(0.75f, 1)); - - // rjf: fast-paths - UI_PrefWidth(ui_em(2.25f, 1)) - UI_Font(df_font_from_slot(DF_FontSlot_Icons)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) - { - Temp scratch = scratch_begin(&arena, 1); - DF_EntityList targets = df_push_active_target_list(scratch.arena); - DF_EntityList processes = df_query_cached_entity_list_with_kind(DF_EntityKind_Process); - B32 have_targets = targets.count != 0; - B32 can_send_signal = !df_ctrl_targets_running(); - B32 can_play = (have_targets && can_send_signal); - B32 can_pause = (!can_send_signal); - B32 can_stop = (processes.count != 0); - - if(can_play || !have_targets) UI_TextAlignment(UI_TextAlign_Center) UI_Flags((can_play ? 0 : UI_BoxFlag_Disabled)) - { - UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Play]); - if(ui_hovering(sig) && !can_play) - { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - ui_labelf("Disabled: %s", have_targets ? "Targets are currently running" : "No active targets exist"); - } - if(ui_hovering(sig) && can_play) - { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - { - if(can_stop) - { - ui_labelf("Resume all processes"); - } - else - { - ui_labelf("Launch all active targets:"); - for(DF_EntityNode *n = targets.first; n != 0; n = n->next) + if(can_stop) { - ui_label(n->entity->name); + ui_labelf("Resume all processes"); } - } - } - } - if(ui_clicked(sig)) - { - DF_CmdParams params = df_cmd_params_from_window(ws); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Run)); - } - } - - if(!can_play && have_targets && !can_send_signal) UI_TextAlignment(UI_TextAlign_Center) - { - UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Redo]); - if(ui_hovering(sig)) - { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - { - ui_labelf("Restart all running targets:"); - { - DF_EntityList processes = df_query_cached_entity_list_with_kind(DF_EntityKind_Process); - for(DF_EntityNode *n = processes.first; n != 0; n = n->next) + else { - DF_Entity *process = n->entity; - DF_Entity *target = df_entity_from_handle(process->entity_handle); - if(!df_entity_is_nil(target)) + ui_labelf("Launch all active targets:"); + for(DF_EntityNode *n = targets.first; n != 0; n = n->next) { - ui_label(target->name); + String8 target_display_name = df_display_string_from_entity(scratch.arena, n->entity); + ui_label(target_display_name); } } } } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Run)); + } } - if(ui_clicked(sig)) + + if(!can_play && processes.count != 0) UI_TextAlignment(UI_TextAlign_Center) { - DF_CmdParams params = df_cmd_params_from_window(ws); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Restart)); + ui_set_next_text_color(v4f32(0.3f, 0.8f, 0.2f, 1.f)); + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Redo]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig)) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + { + ui_labelf("Restart all running targets:"); + { + DF_EntityList processes = df_query_cached_entity_list_with_kind(DF_EntityKind_Process); + for(DF_EntityNode *n = processes.first; n != 0; n = n->next) + { + DF_Entity *process = n->entity; + DF_Entity *target = df_entity_from_handle(process->entity_handle); + if(!df_entity_is_nil(target)) + { + String8 target_display_name = df_display_string_from_entity(scratch.arena, target); + ui_label(target_display_name); + } + } + } + } + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Restart)); + } + } + + UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_pause ? 0 : UI_BoxFlag_Disabled) + { + ui_set_next_text_color(v4f32(0.3f, 0.5f, 0.8f, 1.f)); + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Pause]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig) && !can_pause) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: Already halted"); + } + if(ui_hovering(sig) && can_pause) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Halt all target processes"); + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Halt)); + } + } + + UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_stop ? 0 : UI_BoxFlag_Disabled) + { + UI_Signal sig = {0}; + { + ui_set_next_text_color(v4f32(0.8f, 0.4f, 0.2f, 1.f)); + sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Stop]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + } + if(ui_hovering(sig) && !can_stop) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: No processes are running"); + } + if(ui_hovering(sig) && can_stop) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Kill all target processes"); + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Kill)); + } + } + + UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_step ? 0 : UI_BoxFlag_Disabled) + { + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_StepOver]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig) && !can_step && can_pause) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: Running"); + } + if(ui_hovering(sig) && !can_step && !can_stop) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: No processes are running"); + } + if(ui_hovering(sig) && can_step) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Step Over"); + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_StepOver)); + } + } + + UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_step ? 0 : UI_BoxFlag_Disabled) + { + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_StepInto]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig) && !can_step && can_pause) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: Running"); + } + if(ui_hovering(sig) && !can_step && !can_stop) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: No processes are running"); + } + if(ui_hovering(sig) && can_step) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Step Into"); + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_StepInto)); + } + } + + UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_step ? 0 : UI_BoxFlag_Disabled) + { + UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_StepOut]); + os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + if(ui_hovering(sig) && !can_step && can_pause) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: Running"); + } + if(ui_hovering(sig) && !can_step && !can_stop) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Disabled: No processes are running"); + } + if(ui_hovering(sig) && can_step) + { + UI_Tooltip + UI_Font(df_font_from_slot(DF_FontSlot_Main)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) + ui_labelf("Step Out"); + } + if(ui_clicked(sig)) + { + DF_CmdParams params = df_cmd_params_from_window(ws); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_StepOut)); + } + } + + scratch_end(scratch); + } + } + + //- rjf: right column + UI_WidthFill UI_Row + { + B32 do_user_prof = (dim_2f32(top_bar_rect).x > ui_top_font_size()*80); + + ui_spacer(ui_pct(1, 0)); + + // rjf: loaded user viz + if(do_user_prof) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight1)); + ui_set_next_pref_width(ui_children_sum(1)); + ui_set_next_child_layout_axis(Axis2_X); + ui_set_next_hover_cursor(OS_Cursor_HandPoint); + UI_Box *user_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable| + UI_BoxFlag_DrawBorder| + UI_BoxFlag_DrawBackground| + UI_BoxFlag_DrawHotEffects| + UI_BoxFlag_DrawActiveEffects, + "###loaded_user_button"); + os_window_push_custom_title_bar_client_area(ws->os, user_box->rect); + UI_Parent(user_box) UI_PrefWidth(ui_text_dim(10, 0)) UI_TextAlignment(UI_TextAlign_Center) + { + String8 user_path = df_cfg_path_from_src(DF_CfgSrc_User); + user_path = str8_chop_last_dot(user_path); + UI_Font(ui_icon_font()) ui_label(df_g_icon_kind_text_table[DF_IconKind_Person]); + ui_label(str8_skip_last_slash(user_path)); + } + UI_Signal user_sig = ui_signal_from_box(user_box); + if(ui_clicked(user_sig)) + { + DF_CmdParams p = df_cmd_params_from_window(ws); + p.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OpenUser); + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_CmdSpec); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand)); } } - UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_pause ? 0 : UI_BoxFlag_Disabled) + if(do_user_prof) { - UI_Signal sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Pause]); - if(ui_hovering(sig) && !can_pause) + ui_spacer(ui_em(0.75f, 0)); + } + + // rjf: loaded profile viz + if(do_user_prof) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight0)); + ui_set_next_pref_width(ui_children_sum(1)); + ui_set_next_child_layout_axis(Axis2_X); + ui_set_next_hover_cursor(OS_Cursor_HandPoint); + UI_Box *prof_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable| + UI_BoxFlag_DrawBorder| + UI_BoxFlag_DrawBackground| + UI_BoxFlag_DrawHotEffects| + UI_BoxFlag_DrawActiveEffects, + "###loaded_profile_button"); + os_window_push_custom_title_bar_client_area(ws->os, prof_box->rect); + UI_Parent(prof_box) UI_PrefWidth(ui_text_dim(10, 0)) UI_TextAlignment(UI_TextAlign_Center) { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - ui_labelf("Disabled: Already halted"); + String8 prof_path = df_cfg_path_from_src(DF_CfgSrc_Profile); + prof_path = str8_chop_last_dot(prof_path); + UI_Font(ui_icon_font()) ui_label(df_g_icon_kind_text_table[DF_IconKind_Briefcase]); + ui_label(str8_skip_last_slash(prof_path)); } - if(ui_hovering(sig) && can_pause) + UI_Signal prof_sig = ui_signal_from_box(prof_box); + if(ui_clicked(prof_sig)) { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - ui_labelf("Halt all target processes"); - } - if(ui_clicked(sig)) - { - DF_CmdParams params = df_cmd_params_from_window(ws); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Halt)); + DF_CmdParams p = df_cmd_params_from_window(ws); + p.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OpenProfile); + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_CmdSpec); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand)); } } - UI_TextAlignment(UI_TextAlign_Center) UI_Flags(can_stop ? 0 : UI_BoxFlag_Disabled) + if(do_user_prof) { - UI_Signal sig = {0}; - { - sig = ui_button(df_g_icon_kind_text_table[DF_IconKind_Stop]); - } - if(ui_hovering(sig) && !can_stop) - { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - ui_labelf("Disabled: No processes are running"); - } - if(ui_hovering(sig) && can_stop) - { - UI_Tooltip - UI_Font(df_font_from_slot(DF_FontSlot_Main)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Main)) - ui_labelf("Kill all target processes"); - } - if(ui_clicked(sig)) - { - DF_CmdParams params = df_cmd_params_from_window(ws); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Kill)); - } + ui_spacer(ui_em(0.75f, 0)); + } + + // rjf: min/max/close buttons + { + UI_Signal min_sig = {0}; + UI_Signal max_sig = {0}; + UI_Signal cls_sig = {0}; + Vec2F32 bar_dim = dim_2f32(top_bar_rect); + F32 button_dim = bar_dim.y; + UI_PrefWidth(ui_px(button_dim, 1.f)) + { + min_sig = df_icon_buttonf(DF_IconKind_Minus, 0, "##minimize"); + max_sig = df_icon_buttonf(DF_IconKind_Window, 0, "##maximize"); + } + UI_PrefWidth(ui_px(button_dim*2, 1.f)) + UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_FailureBackground)) + { + cls_sig = df_icon_buttonf(DF_IconKind_X, 0, "##close"); + } + if(ui_clicked(min_sig)) + { + os_window_minimize(ws->os); + } + if(ui_clicked(max_sig)) + { + os_window_set_maximized(ws->os, !os_window_is_maximized(ws->os)); + } + if(ui_clicked(cls_sig)) + { + DF_CmdParams p = df_cmd_params_from_window(ws); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseWindow)); + } + os_window_push_custom_title_bar_client_area(ws->os, min_sig.box->rect); + os_window_push_custom_title_bar_client_area(ws->os, max_sig.box->rect); + os_window_push_custom_title_bar_client_area(ws->os, cls_sig.box->rect); } - scratch_end(scratch); } } } @@ -4784,7 +5053,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D // rjf: construct & push new view DF_View *view = df_view_alloc(); - df_view_equip_spec(view, view_spec, &df_g_nil_entity, default_query, &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, view_spec, &df_g_nil_entity, default_query, &df_g_nil_cfg_node); if(cmd_spec->info.query.flags & DF_CmdQueryFlag_SelectOldInput) { view->query_mark = txt_pt(1, 1); @@ -4991,7 +5260,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D panel = df_panel_rec_df_pre(panel).next) { if(!df_panel_is_nil(panel->first)) { continue; } - Rng2F32 panel_rect = df_rect_from_panel(content_rect, ws->root_panel, panel); + Rng2F32 panel_rect = df_target_rect_from_panel(content_rect, ws->root_panel, panel); DF_View *view = df_view_from_handle(panel->selected_tab_view); if(!df_view_is_nil(view) && contains_2f32(panel_rect, ui_mouse()) && @@ -5127,7 +5396,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D //- rjf: calculate width of exp row if(row == viz_rows.first) { - expr_column_width_px = f_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), row->expr).x + ui_top_font_size()*0.5f; + expr_column_width_px = f_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), row->display_expr).x + ui_top_font_size()*0.5f; expr_column_width_px = Max(expr_column_width_px, ui_top_font_size()*10.f); } @@ -5176,7 +5445,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } UI_WidthFill { - UI_PrefWidth(ui_px(expr_column_width_px, 1.f)) df_code_label(1.f, 1, df_rgba_from_theme_color(DF_ThemeColor_CodeDefault), row->expr); + UI_PrefWidth(ui_px(expr_column_width_px, 1.f)) df_code_label(1.f, 1, df_rgba_from_theme_color(DF_ThemeColor_CodeDefault), row->display_expr); ui_spacer(ui_em(1.5f, 1.f)); if(row->flags & DF_EvalVizRowFlag_CanEditValue) { @@ -5298,7 +5567,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } //////////////////////////// - //- rjf: panel non-leaf UI (drag boundaries) + //- rjf: panel non-leaf UI (drag boundaries, drag/drop sites) // B32 is_changing_panel_boundaries = 0; ProfScope("non-leaf panel UI") @@ -5306,23 +5575,224 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D !df_panel_is_nil(panel); panel = df_panel_rec_df_pre(panel).next) { + ////////////////////////// //- rjf: continue on leaf panels + // if(df_panel_is_nil(panel->first)) { continue; } + ////////////////////////// //- rjf: grab info + // Axis2 split_axis = panel->split_axis; - Rng2F32 panel_rect = df_rect_from_panel(content_rect, ws->root_panel, panel); + Rng2F32 panel_rect = df_target_rect_from_panel(content_rect, ws->root_panel, panel); - //- rjf: do UI for boundaries between all children + ////////////////////////// + //- rjf: boundary tab-drag/drop sites + // + { + DF_View *drag_view = df_view_from_handle(df_g_drag_drop_payload.view); + if(df_drag_is_active() && !df_view_is_nil(drag_view)) + { + //- rjf: params + F32 drop_site_major_dim_px = ceil_f32(ui_top_font_size()*7.f); + F32 drop_site_minor_dim_px = ceil_f32(ui_top_font_size()*5.f); + F32 corner_radius = ui_top_font_size()*0.5f; + F32 padding = ceil_f32(ui_top_font_size()*0.5f); + + //- rjf: special case - build Y boundary drop sites on root panel + // + // (this does not naturally follow from the below algorithm, since the + // root level panel only splits on X) + if(panel == ws->root_panel) UI_CornerRadius(corner_radius) + { + Vec2F32 panel_rect_center = center_2f32(panel_rect); + Axis2 axis = axis2_flip(ws->root_panel->split_axis); + for(EachEnumVal(Side, side)) + { + UI_Key key = ui_key_from_stringf(ui_key_zero(), "root_extra_split_%i", side); + Rng2F32 site_rect = panel_rect; + site_rect.p0.v[axis2_flip(axis)] = panel_rect_center.v[axis2_flip(axis)] - drop_site_major_dim_px/2; + site_rect.p1.v[axis2_flip(axis)] = panel_rect_center.v[axis2_flip(axis)] + drop_site_major_dim_px/2; + site_rect.p0.v[axis] = panel_rect.v[side].v[axis] - drop_site_minor_dim_px/2; + site_rect.p1.v[axis] = panel_rect.v[side].v[axis] + drop_site_minor_dim_px/2; + + // rjf: build + UI_Box *site_box = &ui_g_nil_box; + { + UI_Rect(site_rect) + { + site_box = ui_build_box_from_key(UI_BoxFlag_DropSite, key); + ui_signal_from_box(site_box); + } + UI_Box *site_box_viz = &ui_g_nil_box; + UI_Parent(site_box) UI_WidthFill UI_HeightFill + UI_Padding(ui_px(padding, 1.f)) + UI_Column + UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(axis2_flip(axis)); + if(ui_key_match(key, ui_drop_hot_key())) + { + ui_set_next_border_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight0)); + } + site_box_viz = ui_build_box_from_key(UI_BoxFlag_DrawBackground| + UI_BoxFlag_DrawBorder| + UI_BoxFlag_DrawDropShadow| + UI_BoxFlag_DrawBackgroundBlur, ui_key_zero()); + } + UI_Parent(site_box_viz) UI_WidthFill UI_HeightFill UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(axis); + UI_Box *row_or_column = ui_build_box_from_key(0, ui_key_zero()); UI_Parent(row_or_column) UI_Padding(ui_px(padding, 1.f)) + { + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + ui_spacer(ui_px(padding, 1.f)); + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + } + } + } + + // rjf: viz + if(ui_key_match(site_box->key, ui_drop_hot_key())) + { + Rng2F32 future_split_rect = site_rect; + future_split_rect.p0.v[axis] -= drop_site_major_dim_px; + future_split_rect.p1.v[axis] += drop_site_major_dim_px; + future_split_rect.p0.v[axis2_flip(axis)] = panel_rect.p0.v[axis2_flip(axis)]; + future_split_rect.p1.v[axis2_flip(axis)] = panel_rect.p1.v[axis2_flip(axis)]; + UI_Rect(future_split_rect) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); + ui_build_box_from_key(UI_BoxFlag_DrawBackground, ui_key_zero()); + } + } + + // rjf: drop + DF_DragDropPayload payload = {0}; + if(ui_key_match(site_box->key, ui_drop_hot_key()) && df_drag_drop(&payload)) + { + Dir2 dir = (axis == Axis2_Y ? (side == Side_Min ? Dir2_Up : Dir2_Down) : + axis == Axis2_X ? (side == Side_Min ? Dir2_Left : Dir2_Right) : + Dir2_Invalid); + if(dir != Dir2_Invalid) + { + DF_Panel *split_panel = panel; + DF_CmdParams p = df_cmd_params_from_window(ws); + p.dest_panel = df_handle_from_panel(split_panel); + p.panel = payload.panel; + p.view = payload.view; + p.dir2 = dir; + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_SplitPanel)); + } + } + } + } + + //- rjf: iterate all children, build boundary drop sites + Axis2 split_axis = panel->split_axis; + UI_CornerRadius(corner_radius) for(DF_Panel *child = panel->first;; child = child->next) + { + // rjf: form rect + Rng2F32 child_rect = df_target_rect_from_panel_child(panel_rect, panel, child); + Vec2F32 child_rect_center = center_2f32(child_rect); + UI_Key key = ui_key_from_stringf(ui_key_zero(), "drop_boundary_%p_%p", panel, child); + Rng2F32 site_rect = r2f32(child_rect_center, child_rect_center); + site_rect.p0.v[split_axis] = child_rect.p0.v[split_axis] - drop_site_minor_dim_px/2; + site_rect.p1.v[split_axis] = child_rect.p0.v[split_axis] + drop_site_minor_dim_px/2; + site_rect.p0.v[axis2_flip(split_axis)] -= drop_site_major_dim_px/2; + site_rect.p1.v[axis2_flip(split_axis)] += drop_site_major_dim_px/2; + + // rjf: build + UI_Box *site_box = &ui_g_nil_box; + { + UI_Rect(site_rect) + { + site_box = ui_build_box_from_key(UI_BoxFlag_DropSite, key); + ui_signal_from_box(site_box); + } + UI_Box *site_box_viz = &ui_g_nil_box; + UI_Parent(site_box) UI_WidthFill UI_HeightFill + UI_Padding(ui_px(padding, 1.f)) + UI_Column + UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(axis2_flip(split_axis)); + if(ui_key_match(key, ui_drop_hot_key())) + { + ui_set_next_border_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight0)); + } + site_box_viz = ui_build_box_from_key(UI_BoxFlag_DrawBackground| + UI_BoxFlag_DrawBorder| + UI_BoxFlag_DrawDropShadow| + UI_BoxFlag_DrawBackgroundBlur, ui_key_zero()); + } + UI_Parent(site_box_viz) UI_WidthFill UI_HeightFill UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(split_axis); + UI_Box *row_or_column = ui_build_box_from_key(0, ui_key_zero()); UI_Parent(row_or_column) UI_Padding(ui_px(padding, 1.f)) + { + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + ui_spacer(ui_px(padding, 1.f)); + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + } + } + } + + // rjf: viz + if(ui_key_match(site_box->key, ui_drop_hot_key())) + { + Rng2F32 future_split_rect = site_rect; + future_split_rect.p0.v[split_axis] -= drop_site_major_dim_px; + future_split_rect.p1.v[split_axis] += drop_site_major_dim_px; + future_split_rect.p0.v[axis2_flip(split_axis)] = child_rect.p0.v[axis2_flip(split_axis)]; + future_split_rect.p1.v[axis2_flip(split_axis)] = child_rect.p1.v[axis2_flip(split_axis)]; + UI_Rect(future_split_rect) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); + ui_build_box_from_key(UI_BoxFlag_DrawBackground, ui_key_zero()); + } + } + + // rjf: drop + DF_DragDropPayload payload = {0}; + if(ui_key_match(site_box->key, ui_drop_hot_key()) && df_drag_drop(&payload)) + { + Dir2 dir = (panel->split_axis == Axis2_X ? Dir2_Left : Dir2_Up); + DF_Panel *split_panel = child; + if(df_panel_is_nil(split_panel)) + { + split_panel = panel->last; + dir = (panel->split_axis == Axis2_X ? Dir2_Right : Dir2_Down); + } + DF_CmdParams p = df_cmd_params_from_window(ws); + p.dest_panel = df_handle_from_panel(split_panel); + p.panel = payload.panel; + p.view = payload.view; + p.dir2 = dir; + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_SplitPanel)); + } + + // rjf: exit on opl child + if(df_panel_is_nil(child)) + { + break; + } + } + } + } + + ////////////////////////// + //- rjf: do UI for drag boundaries between all children + // for(DF_Panel *child = panel->first; !df_panel_is_nil(child) && !df_panel_is_nil(child->next); child = child->next) { DF_Panel *min_child = child; DF_Panel *max_child = min_child->next; - Rng2F32 min_child_rect = df_rect_from_panel_child(panel_rect, panel, min_child); - Rng2F32 max_child_rect = df_rect_from_panel_child(panel_rect, panel, max_child); + Rng2F32 min_child_rect = df_target_rect_from_panel_child(panel_rect, panel, min_child); + Rng2F32 max_child_rect = df_target_rect_from_panel_child(panel_rect, panel, max_child); Rng2F32 boundary_rect = {0}; { boundary_rect.p0.v[split_axis] = min_child_rect.p1.v[split_axis] - ui_top_font_size()/3; @@ -5339,13 +5809,13 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(ui_double_clicked(sig)) { ui_kill_action(); - F32 sum_pct = min_child->size_pct_of_parent_target.v[split_axis] + max_child->size_pct_of_parent_target.v[split_axis]; - min_child->size_pct_of_parent_target.v[split_axis] = 0.5f * sum_pct; - max_child->size_pct_of_parent_target.v[split_axis] = 0.5f * sum_pct; + F32 sum_pct = min_child->pct_of_parent + max_child->pct_of_parent; + min_child->pct_of_parent = 0.5f * sum_pct; + max_child->pct_of_parent = 0.5f * sum_pct; } else if(ui_pressed(sig)) { - Vec2F32 v = {min_child->size_pct_of_parent_target.v[split_axis], max_child->size_pct_of_parent_target.v[split_axis]}; + Vec2F32 v = {min_child->pct_of_parent, max_child->pct_of_parent}; ui_store_drag_struct(&v); } else if(ui_dragging(sig)) @@ -5372,8 +5842,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D pct_delta = -(max_pct__after - max_pct__before); min_pct__after = min_pct__before + pct_delta; } - min_child->size_pct_of_parent.v[split_axis] = min_child->size_pct_of_parent_target.v[split_axis] = min_pct__after; - max_child->size_pct_of_parent.v[split_axis] = max_child->size_pct_of_parent_target.v[split_axis] = max_pct__after; + min_child->pct_of_parent = min_pct__after; + max_child->pct_of_parent = max_pct__after; is_changing_panel_boundaries = 1; } if(ui_released(sig) || ui_double_clicked(sig)) @@ -5384,6 +5854,37 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } } + //////////////////////////// + //- rjf: animate panels + // + { + F32 rate = 1 - pow_f32(2, (-50.f * df_dt())); + Vec2F32 content_rect_dim = dim_2f32(content_rect); + for(DF_Panel *panel = ws->root_panel; !df_panel_is_nil(panel); panel = df_panel_rec_df_pre(panel).next) + { + Rng2F32 target_rect_px = df_target_rect_from_panel(content_rect, ws->root_panel, panel); + Rng2F32 target_rect_pct = r2f32p(target_rect_px.x0/content_rect_dim.x, + target_rect_px.y0/content_rect_dim.y, + target_rect_px.x1/content_rect_dim.x, + target_rect_px.y1/content_rect_dim.y); + if(abs_f32(target_rect_pct.x0 - panel->animated_rect_pct.x0) > 0.005f || + abs_f32(target_rect_pct.y0 - panel->animated_rect_pct.y0) > 0.005f || + abs_f32(target_rect_pct.x1 - panel->animated_rect_pct.x1) > 0.005f || + abs_f32(target_rect_pct.y1 - panel->animated_rect_pct.y1) > 0.005f) + { + df_gfx_request_frame(); + } + panel->animated_rect_pct.x0 += rate * (target_rect_pct.x0 - panel->animated_rect_pct.x0); + panel->animated_rect_pct.y0 += rate * (target_rect_pct.y0 - panel->animated_rect_pct.y0); + panel->animated_rect_pct.x1 += rate * (target_rect_pct.x1 - panel->animated_rect_pct.x1); + panel->animated_rect_pct.y1 += rate * (target_rect_pct.y1 - panel->animated_rect_pct.y1); + if(ws->frames_alive < 5 || is_changing_panel_boundaries) + { + panel->animated_rect_pct = target_rect_pct; + } + } + } + //////////////////////////// //- rjf: panel leaf UI // @@ -5404,7 +5905,12 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ////////////////////////// //- rjf: calculate UI rectangles // - Rng2F32 panel_rect = df_rect_from_panel(content_rect, ws->root_panel, panel); + Vec2F32 content_rect_dim = dim_2f32(content_rect); + Rng2F32 panel_rect_pct = panel->animated_rect_pct; + Rng2F32 panel_rect = r2f32p(panel_rect_pct.x0*content_rect_dim.x, + panel_rect_pct.y0*content_rect_dim.y, + panel_rect_pct.x1*content_rect_dim.x, + panel_rect_pct.y1*content_rect_dim.y); panel_rect = pad_2f32(panel_rect, -1.f); F32 tab_bar_rheight = ui_top_font_size()*3.f; F32 tab_bar_vheight = ui_top_font_size()*2.6f; @@ -5433,6 +5939,190 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } } + ////////////////////////// + //- rjf: build combined split+movetab drag/drop sites + // + { + DF_View *view = df_view_from_handle(df_g_drag_drop_payload.view); + if(df_drag_is_active() && !df_view_is_nil(view) && contains_2f32(panel_rect, ui_mouse())) + { + F32 drop_site_dim_px = ceil_f32(ui_top_font_size()*7.f); + Vec2F32 drop_site_half_dim = v2f32(drop_site_dim_px/2, drop_site_dim_px/2); + Vec2F32 panel_center = center_2f32(panel_rect); + F32 corner_radius = ui_top_font_size()*0.5f; + F32 padding = ceil_f32(ui_top_font_size()*0.5f); + struct + { + UI_Key key; + Dir2 split_dir; + Rng2F32 rect; + } + sites[] = + { + { + ui_key_from_stringf(ui_key_zero(), "drop_split_center_%p", panel), + Dir2_Invalid, + r2f32(sub_2f32(panel_center, drop_site_half_dim), + add_2f32(panel_center, drop_site_half_dim)) + }, + { + ui_key_from_stringf(ui_key_zero(), "drop_split_up_%p", panel), + Dir2_Up, + r2f32p(panel_center.x-drop_site_half_dim.x, + panel_center.y-drop_site_half_dim.y - drop_site_half_dim.y*2, + panel_center.x+drop_site_half_dim.x, + panel_center.y+drop_site_half_dim.y - drop_site_half_dim.y*2), + }, + { + ui_key_from_stringf(ui_key_zero(), "drop_split_down_%p", panel), + Dir2_Down, + r2f32p(panel_center.x-drop_site_half_dim.x, + panel_center.y-drop_site_half_dim.y + drop_site_half_dim.y*2, + panel_center.x+drop_site_half_dim.x, + panel_center.y+drop_site_half_dim.y + drop_site_half_dim.y*2), + }, + { + ui_key_from_stringf(ui_key_zero(), "drop_split_left_%p", panel), + Dir2_Left, + r2f32p(panel_center.x-drop_site_half_dim.x - drop_site_half_dim.x*2, + panel_center.y-drop_site_half_dim.y, + panel_center.x+drop_site_half_dim.x - drop_site_half_dim.x*2, + panel_center.y+drop_site_half_dim.y), + }, + { + ui_key_from_stringf(ui_key_zero(), "drop_split_right_%p", panel), + Dir2_Right, + r2f32p(panel_center.x-drop_site_half_dim.x + drop_site_half_dim.x*2, + panel_center.y-drop_site_half_dim.y, + panel_center.x+drop_site_half_dim.x + drop_site_half_dim.x*2, + panel_center.y+drop_site_half_dim.y), + }, + }; + UI_CornerRadius(corner_radius) + for(U64 idx = 0; idx < ArrayCount(sites); idx += 1) + { + UI_Key key = sites[idx].key; + Dir2 dir = sites[idx].split_dir; + Rng2F32 rect = sites[idx].rect; + Axis2 split_axis = axis2_from_dir2(dir); + Side split_side = side_from_dir2(dir); + if(dir != Dir2_Invalid && split_axis == panel->parent->split_axis) + { + continue; + } + UI_Box *site_box = &ui_g_nil_box; + { + UI_Rect(rect) + { + site_box = ui_build_box_from_key(UI_BoxFlag_DropSite, key); + ui_signal_from_box(site_box); + } + UI_Box *site_box_viz = &ui_g_nil_box; + UI_Parent(site_box) UI_WidthFill UI_HeightFill + UI_Padding(ui_px(padding, 1.f)) + UI_Column + UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(axis2_flip(split_axis)); + if(ui_key_match(key, ui_drop_hot_key())) + { + ui_set_next_border_color(df_rgba_from_theme_color(DF_ThemeColor_Highlight0)); + } + site_box_viz = ui_build_box_from_key(UI_BoxFlag_DrawBackground| + UI_BoxFlag_DrawBorder| + UI_BoxFlag_DrawDropShadow| + UI_BoxFlag_DrawBackgroundBlur, ui_key_zero()); + } + if(dir != Dir2_Invalid) + { + UI_Parent(site_box_viz) UI_WidthFill UI_HeightFill UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(split_axis); + UI_Box *row_or_column = ui_build_box_from_key(0, ui_key_zero()); UI_Parent(row_or_column) UI_Padding(ui_px(padding, 1.f)) + { + if(split_side == Side_Min) { ui_set_next_flags(UI_BoxFlag_DrawBackground); ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); } + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + ui_spacer(ui_px(padding, 1.f)); + if(split_side == Side_Max) { ui_set_next_flags(UI_BoxFlag_DrawBackground); ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); } + ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); + } + } + } + else + { + UI_Parent(site_box_viz) UI_WidthFill UI_HeightFill UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_child_layout_axis(split_axis); + UI_Box *row_or_column = ui_build_box_from_key(0, ui_key_zero()); + UI_Parent(row_or_column) UI_Padding(ui_px(padding, 1.f)) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); + ui_build_box_from_key(UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground, ui_key_zero()); + } + } + } + } + DF_DragDropPayload payload = {0}; + if(ui_key_match(site_box->key, ui_drop_hot_key()) && df_drag_drop(&payload)) + { + if(dir != Dir2_Invalid) + { + DF_CmdParams p = df_cmd_params_from_window(ws); + p.dest_panel = df_handle_from_panel(panel); + p.panel = payload.panel; + p.view = payload.view; + p.dir2 = dir; + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_SplitPanel)); + } + else + { + DF_CmdParams p = df_cmd_params_from_window(ws); + p.dest_panel = df_handle_from_panel(panel); + p.panel = payload.panel; + p.view = payload.view; + p.prev_view = df_handle_from_view(panel->last_tab_view); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_MoveTab)); + } + } + } + for(U64 idx = 0; idx < ArrayCount(sites); idx += 1) + { + B32 is_drop_hot = ui_key_match(ui_drop_hot_key(), sites[idx].key); + if(is_drop_hot) + { + Axis2 split_axis = axis2_from_dir2(sites[idx].split_dir); + Side split_side = side_from_dir2(sites[idx].split_dir); + Rng2F32 future_split_rect = panel_rect; + if(sites[idx].split_dir != Dir2_Invalid) + { + Vec2F32 panel_center = center_2f32(panel_rect); + future_split_rect.v[side_flip(split_side)].v[split_axis] = panel_center.v[split_axis]; + } + UI_Rect(future_split_rect) + { + ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)); + ui_build_box_from_key(UI_BoxFlag_DrawBackground, ui_key_zero()); + } + } + } + } + } + + ////////////////////////// + //- rjf: build catch-all panel drop-site + // + B32 catchall_drop_site_hovered = 0; + if(df_drag_is_active() && ui_key_match(ui_key_zero(), ui_drop_hot_key())) + { + UI_Rect(panel_rect) + { + UI_Key key = ui_key_from_stringf(ui_key_zero(), "catchall_drop_site_%p", panel); + UI_Box *catchall_drop_site = ui_build_box_from_key(UI_BoxFlag_DropSite, key); + ui_signal_from_box(catchall_drop_site); + catchall_drop_site_hovered = ui_key_match(key, ui_drop_hot_key()); + } + } + ////////////////////////// //- rjf: build filtering box // @@ -5800,10 +6490,40 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D UI_CornerRadius01(panel->tab_side == Side_Min ? 0 : corner_radius) UI_CornerRadius10(panel->tab_side == Side_Min ? corner_radius : 0) UI_CornerRadius11(panel->tab_side == Side_Min ? 0 : corner_radius) - for(DF_View *view = panel->first_tab_view; !df_view_is_nil(view); view = view->next, view_idx += 1) + for(DF_View *view = panel->first_tab_view;; view = view->next, view_idx += 1) { temp_end(scratch); + // rjf: if before this tab is the prev-view of the current tab drag, + // draw empty space + if(df_drag_is_active() && catchall_drop_site_hovered) + { + DF_Panel *dst_panel = df_panel_from_handle(df_g_last_drag_drop_panel); + DF_View *drag_view = df_view_from_handle(df_g_drag_drop_payload.view); + DF_View *dst_prev_view = df_view_from_handle(df_g_last_drag_drop_prev_tab); + if(dst_panel == panel && + ((!df_view_is_nil(view) && dst_prev_view == view->prev && drag_view != view && drag_view != view->prev) || + (df_view_is_nil(view) && dst_prev_view == panel->last_tab_view && drag_view != panel->last_tab_view))) + { + UI_PrefWidth(ui_em(9.f, 0.2f)) UI_Column + { + ui_spacer(ui_em(0.2f, 1.f)); + UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay)) + UI_CornerRadius00(corner_radius) + UI_CornerRadius10(corner_radius) + { + ui_build_box_from_key(UI_BoxFlag_DrawBackground|UI_BoxFlag_DrawBorder, ui_key_zero()); + } + } + } + } + + // rjf: end on nil view + if(df_view_is_nil(view)) + { + break; + } + // rjf: gather info for this tab B32 view_is_selected = (view == df_view_from_handle(panel->selected_tab_view)); DF_IconKind icon_kind = df_icon_kind_from_view(view); @@ -5845,18 +6565,65 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D // rjf: build tab contents UI_Parent(tab_box) { - if(icon_kind != DF_IconKind_Null) + UI_WidthFill UI_Row { - UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) - UI_Font(df_font_from_slot(DF_FontSlot_Icons)) - UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) - UI_TextAlignment(UI_TextAlign_Center) - UI_PrefWidth(ui_em(2.25f, 1.f)) - ui_label(df_g_icon_kind_text_table[icon_kind]); + if(icon_kind != DF_IconKind_Null) + { + UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) + UI_Font(df_font_from_slot(DF_FontSlot_Icons)) + UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)) + UI_TextAlignment(UI_TextAlign_Center) + UI_PrefWidth(ui_em(2.25f, 1.f)) + ui_label(df_g_icon_kind_text_table[icon_kind]); + } + if(view->query_string_size != 0) + { + UI_PrefWidth(ui_text_dim(10, 0)) + { + Temp scratch = scratch_begin(0, 0); + D_FancyStringList fstrs = {0}; + { + D_FancyString view_title = + { + df_font_from_slot(DF_FontSlot_Main), + label, + df_rgba_from_theme_color(view_is_selected ? DF_ThemeColor_PlainText : DF_ThemeColor_WeakText), + ui_top_font_size(), + }; + d_fancy_string_list_push(scratch.arena, &fstrs, &view_title); + } + { + D_FancyString space = + { + df_font_from_slot(DF_FontSlot_Code), + str8_lit(" "), + v4f32(0, 0, 0, 0), + ui_top_font_size(), + }; + d_fancy_string_list_push(scratch.arena, &fstrs, &space); + } + { + D_FancyString query = + { + df_font_from_slot(DF_FontSlot_Code), + str8(view->query_buffer, view->query_string_size), + df_rgba_from_theme_color(DF_ThemeColor_WeakText), + ui_top_font_size(), + }; + d_fancy_string_list_push(scratch.arena, &fstrs, &query); + } + UI_Box *box = ui_build_box_from_key(UI_BoxFlag_DrawText, ui_key_zero()); + ui_box_equip_display_fancy_strings(box, &fstrs); + scratch_end(scratch); + } + } + else + { + UI_TextColor(df_rgba_from_theme_color(view_is_selected ? DF_ThemeColor_PlainText : DF_ThemeColor_WeakText)) + UI_PrefWidth(ui_text_dim(10, 0)) + ui_label(label); + } } - UI_TextColor(df_rgba_from_theme_color(view_is_selected ? DF_ThemeColor_PlainText : DF_ThemeColor_WeakText)) - UI_WidthFill - ui_label(label); UI_PrefWidth(ui_em(2.35f, 1.f)) UI_TextAlignment(UI_TextAlign_Center) UI_Font(df_font_from_slot(DF_FontSlot_Icons)) UI_FontSize(df_font_size_from_slot(ws, DF_FontSlot_Icons)*0.75f) @@ -5942,44 +6709,42 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D // rjf: mouse => hovered drop site F32 min_distance = 0; DropSite *active_drop_site = 0; - for(U64 drop_site_idx = 0; drop_site_idx < drop_site_count; drop_site_idx += 1) + if(catchall_drop_site_hovered) { - F32 distance = abs_f32(drop_sites[drop_site_idx].p - mouse.x); - if(drop_site_idx == 0 || distance < min_distance) + for(U64 drop_site_idx = 0; drop_site_idx < drop_site_count; drop_site_idx += 1) { - active_drop_site = &drop_sites[drop_site_idx]; - min_distance = distance; + F32 distance = abs_f32(drop_sites[drop_site_idx].p - mouse.x); + if(drop_site_idx == 0 || distance < min_distance) + { + active_drop_site = &drop_sites[drop_site_idx]; + min_distance = distance; + } } } + // rjf: store closest prev-view + if(active_drop_site != 0) + { + df_g_last_drag_drop_prev_tab = df_handle_from_view(active_drop_site->prev_view); + } + else + { + df_g_last_drag_drop_prev_tab = df_handle_zero(); + } + // rjf: vis DF_Panel *drag_panel = df_panel_from_handle(df_g_drag_drop_payload.panel); if(!df_view_is_nil(view) && active_drop_site != 0 && - (panel != drag_panel)) + (panel != drag_panel || 1)) { tab_bar_box->flags |= UI_BoxFlag_DrawOverlay; tab_bar_box->overlay_color = df_rgba_from_theme_color(DF_ThemeColor_DropSiteOverlay); - - if(panel->tab_view_count != 0) - { - D_Bucket *bucket = d_bucket_make(); - D_BucketScope(bucket) - { - d_rect(r2f32p(active_drop_site->p - tab_spacing/2, - tab_bar_box->rect.y0, - active_drop_site->p + tab_spacing/2, - tab_bar_box->rect.y1), - v4f32(1, 1, 1, 1), - 2.f, 0, 1.f); - } - ui_box_equip_draw_bucket(tab_bar_box, bucket); - } } // rjf: drop DF_DragDropPayload payload = df_g_drag_drop_payload; - if((active_drop_site != 0 && df_drag_drop(&payload)) || df_panel_from_handle(payload.panel) == panel) + if(catchall_drop_site_hovered && (active_drop_site != 0 && df_drag_drop(&payload)) || (df_panel_from_handle(payload.panel) == panel && 0)) { DF_View *view = df_view_from_handle(payload.view); DF_Panel *src_panel = df_panel_from_handle(payload.panel); @@ -6011,8 +6776,10 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ////////////////////////// //- rjf: less granular panel for tabs & entities drop-site // - if(df_drag_is_active() && window_is_focused && contains_2f32(panel_rect, ui_mouse())) + if(catchall_drop_site_hovered) { + df_g_last_drag_drop_panel = df_handle_from_panel(panel); + DF_DragDropPayload *payload = &df_g_drag_drop_payload; DF_View *dragged_view = df_view_from_handle(payload->view); B32 view_is_in_panel = 0; @@ -6080,27 +6847,6 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } } - //////////////////////////// - //- rjf: animate panel pcts - // - { - F32 rate = 1 - pow_f32(2, (-50.f * df_dt())); - for(DF_Panel *panel = ws->root_panel; !df_panel_is_nil(panel); panel = df_panel_rec_df_pre(panel).next) - { - if(abs_f32(panel->off_pct_of_parent.x) > 0.005f || - abs_f32(panel->off_pct_of_parent.y) > 0.005f || - abs_f32(panel->size_pct_of_parent_target.x - panel->size_pct_of_parent.x) > 0.005f || - abs_f32(panel->size_pct_of_parent_target.y - panel->size_pct_of_parent.y) > 0.005f) - { - df_gfx_request_frame(); - } - panel->off_pct_of_parent.x += (-panel->off_pct_of_parent.x) * rate; - panel->off_pct_of_parent.y += (-panel->off_pct_of_parent.y) * rate; - panel->size_pct_of_parent.x += (panel->size_pct_of_parent_target.x - panel->size_pct_of_parent.x) * rate; - panel->size_pct_of_parent.y += (panel->size_pct_of_parent_target.y - panel->size_pct_of_parent.y) * rate; - } - } - //////////////////////////// //- rjf: animate views // @@ -6285,6 +7031,12 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D d_rect(os_client_rect_from_window(ws->os), bg_color, 0, 0, 0); } + //- rjf: draw window border + { + Vec4F32 color = df_rgba_from_theme_color(DF_ThemeColor_PlainBorder); + d_rect(os_client_rect_from_window(ws->os), color, 0, 1.f, 0.5f); + } + //- rjf: recurse & draw U64 total_heatmap_sum_count = 0; for(UI_Box *box = ui_root_from_state(ws->ui); !ui_box_is_nil(box);) @@ -6320,6 +7072,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D Mat3x3F32 origin2box_xform = make_translate_3x3f32(v2f32(box->rect.x0 + box_dim.x/8, box->rect.y0)); Mat3x3F32 xform = mul_3x3f32(origin2box_xform, mul_3x3f32(scale_xform, box2origin_xform)); d_push_xform2d(xform); + d_push_tex2d_sample_kind(R_Tex2DSampleKind_Linear); } // rjf: draw drop shadow @@ -6549,6 +7302,13 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } } + // rjf: debug border rendering + if(0) + { + R_Rect2DInst *inst = d_rect(pad_2f32(b->rect, 1), v4f32(1, 0, 1, 0.25f), 0, 1.f, 1.f); + MemoryCopyArray(inst->corner_radii, b->corner_radii); + } + // rjf: draw sides { Rng2F32 r = b->rect; @@ -6648,6 +7408,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D if(b->squish != 0) { d_pop_xform2d(); + d_pop_tex2d_sample_kind(); } // rjf: pop transparency @@ -7226,7 +7987,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop String8List display_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, DF_EvalVizStringFlag_ReadOnlyDisplayRules, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, block->eval, block->member, &block->cfg_table); String8List edit_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, 0, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, block->eval, block->member, &block->cfg_table); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, block->key, block->eval); - row->expr = block->string; + row->display_expr = block->string; + row->edit_expr = block->string; row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7286,7 +8048,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop { row->flags |= DF_EvalVizRowFlag_ExprIsSpecial; } - row->expr = push_str8_copy(arena, member->name); + row->display_expr = push_str8_copy(arena, member->name); + row->edit_expr = push_str8f(arena, "%S.%S", block->string, member->name); row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7336,7 +8099,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop String8List display_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, DF_EvalVizStringFlag_ReadOnlyDisplayRules, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, eval, 0, &view_rule_table); String8List edit_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, 0, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, eval, 0, &view_rule_table); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, key, eval); - row->expr = push_str8_copy(arena, enum_val->name); + row->display_expr = push_str8_copy(arena, enum_val->name); + row->edit_expr = row->display_expr; row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7383,7 +8147,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop String8List display_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, DF_EvalVizStringFlag_ReadOnlyDisplayRules, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, elem_eval, 0, &view_rule_table); String8List edit_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, 0, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, elem_eval, 0, &view_rule_table); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, key, elem_eval); - row->expr = push_str8f(arena, "[%I64u]", idx); + row->display_expr = push_str8f(arena, "[%I64u]", idx); + row->edit_expr = push_str8f(arena, "%S[%I64u]", block->string, idx); row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7404,6 +8169,7 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop { DF_EvalLinkBaseChunkList link_base_chunks = df_eval_link_base_chunk_list_from_eval(scratch.arena, parse_ctx->type_graph, parse_ctx->rdi, block->link_member_type_key, block->link_member_off, ctrl_ctx, block->eval, 512); DF_EvalLinkBaseArray link_bases = df_eval_link_base_array_from_chunk_list(scratch.arena, &link_base_chunks); + String8 node_type_string = tg_string_from_key(arena, parse_ctx->type_graph, parse_ctx->rdi, block->eval.type_key); for(U64 idx = visible_idx_range.min; idx < visible_idx_range.max; idx += 1) { // rjf: get key for this row @@ -7434,7 +8200,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop String8List display_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, DF_EvalVizStringFlag_ReadOnlyDisplayRules, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, link_eval, 0, &view_rule_table); String8List edit_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, 0, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, link_eval, 0, &view_rule_table); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, key, link_eval); - row->expr = push_str8f(arena, "[%I64u]", idx); + row->display_expr = push_str8f(arena, "[%I64u]", idx); + row->edit_expr = push_str8f(arena, "(%S *)0xI64x", node_type_string, link_eval.offset); row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7457,6 +8224,7 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop DF_ExpandKey key = df_expand_key_make(df_hash_from_expand_key(block->parent_key), 1); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, key, block->eval); row->flags = DF_EvalVizRowFlag_Canvas; + row->edit_expr = block->string; row->size_in_rows = dim_1u64(intersect_1u64(visible_idx_range, r1u64(0, dim_1u64(block->visual_idx_range)))); row->skipped_size_in_rows= (visible_idx_range.min > block->visual_idx_range.min) ? visible_idx_range.min - block->visual_idx_range.min : 0; row->chopped_size_in_rows= (visible_idx_range.max < block->visual_idx_range.max) ? block->visual_idx_range.max - visible_idx_range.max : 0; @@ -7496,7 +8264,8 @@ df_eval_viz_windowed_row_list_from_viz_block_list(Arena *arena, DBGI_Scope *scop String8List display_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, DF_EvalVizStringFlag_ReadOnlyDisplayRules, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, eval, 0, &view_rule_table); String8List edit_strings = df_single_line_eval_value_strings_from_eval(scratch.arena, 0, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, default_radix, font, font_size, 500, 0, eval, 0, &view_rule_table); DF_EvalVizRow *row = df_eval_viz_row_list_push_new(arena, parse_ctx, &list, block, key, eval); - row->expr = name; + row->display_expr = name; + row->edit_expr = name; row->display_value = str8_list_join(arena, &display_strings, 0); row->edit_value = str8_list_join(arena, &edit_strings, 0); row->value_ui_rule_node = value_ui_rule_node; @@ -7899,7 +8668,7 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, DF_CfgSrc source) // rjf: non-root needs pct node if(p != root_panel) { - str8_list_pushf(arena, &strs, "%.*s%g:\n", indentation*2, indent_str.str, p->size_pct_of_parent_target.v[p->parent->split_axis]); + str8_list_pushf(arena, &strs, "%.*s%g:\n", indentation*2, indent_str.str, p->pct_of_parent); str8_list_pushf(arena, &strs, "%.*s{\n", indentation*2, indent_str.str); indentation += 1; } @@ -7951,6 +8720,14 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, DF_CfgSrc source) { str8_list_push(arena, &strs, str8_lit("selected ")); } + if(view->query_string_size != 0 && view->spec->info.flags & DF_ViewSpecFlag_CanSerializeQuery) + { + Temp scratch = scratch_begin(&arena, 1); + String8 query_raw = str8(view->query_buffer, view->query_string_size); + String8 query_sanitized = df_cfg_escaped_from_raw_string(scratch.arena, query_raw); + str8_list_pushf(arena, &strs, "query:{\"%S\"} ", query_sanitized); + scratch_end(scratch); + } if(view->spec->info.flags & DF_ViewSpecFlag_CanSerializeEntityPath) { if(view_entity->kind == DF_EntityKind_File) @@ -11270,6 +12047,13 @@ df_gfx_request_frame(void) //////////////////////////////// //~ rjf: Main Layer Top-Level Calls +#if !defined(STBI_INCLUDE_STB_IMAGE_H) +# define STB_IMAGE_IMPLEMENTATION +# define STBI_ONLY_PNG +# define STBI_ONLY_BMP +# include "third_party/stb/stb_image.h" +#endif + internal void df_gfx_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, DF_StateDeltaHistory *hist) { @@ -11303,6 +12087,8 @@ df_gfx_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, DF_StateDe { DF_GfxViewRuleSpecInfoArray array = {df_g_gfx_view_rule_spec_info_table, ArrayCount(df_g_gfx_view_rule_spec_info_table)}; df_register_gfx_view_rule_specs(array); + DF_ViewSpecInfoArray tab_view_specs_array = {df_g_gfx_view_rule_tab_view_spec_info_table, ArrayCount(df_g_gfx_view_rule_tab_view_spec_info_table)}; + df_register_view_specs(tab_view_specs_array); } // rjf: register cmd param slot -> view specs @@ -11322,6 +12108,72 @@ df_gfx_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, DF_StateDe } } + // rjf: unpack icon image data + { + Temp scratch = scratch_begin(0, 0); + String8 data = df_g_icon_file_bytes; + U8 *ptr = data.str; + U8 *opl = ptr+data.size; + + // rjf: read header + ICO_Header hdr = {0}; + if(ptr+sizeof(hdr) < opl) + { + MemoryCopy(&hdr, ptr, sizeof(hdr)); + ptr += sizeof(hdr); + } + + // rjf: read image entries + U64 entries_count = hdr.num_images; + ICO_Entry *entries = push_array(scratch.arena, ICO_Entry, hdr.num_images); + { + U64 bytes_to_read = sizeof(ICO_Entry)*entries_count; + bytes_to_read = Min(bytes_to_read, opl-ptr); + MemoryCopy(entries, ptr, bytes_to_read); + ptr += bytes_to_read; + } + + // rjf: find largest image + ICO_Entry *best_entry = 0; + U64 best_entry_area = 0; + for(U64 idx = 0; idx < entries_count; idx += 1) + { + ICO_Entry *entry = &entries[idx]; + U64 width = entry->image_width_px; + if(width == 0) { width = 256; } + U64 height = entry->image_height_px; + if(height == 0) { height = 256; } + U64 entry_area = width*height; + if(entry_area > best_entry_area) + { + best_entry = entry; + best_entry_area = entry_area; + } + } + + // rjf: deserialize raw image data from best entry's offset + U8 *image_data = 0; + Vec2S32 image_dim = {0}; + if(best_entry != 0) + { + U8 *file_data_ptr = data.str + best_entry->image_data_off; + U64 file_data_size = best_entry->image_data_size; + int width = 0; + int height = 0; + int components = 0; + image_data = stbi_load_from_memory(file_data_ptr, file_data_size, &width, &height, &components, 4); + image_dim.x = width; + image_dim.y = height; + } + + // rjf: upload to gpu texture + df_gfx_state->icon_texture = r_tex2d_alloc(R_Tex2DKind_Static, image_dim, R_Tex2DFormat_RGBA8, image_data); + + // rjf: release + stbi_image_free(image_data); + scratch_end(scratch); + } + ProfEnd(); } @@ -11343,7 +12195,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) } //- rjf: capture is active? -> keep rendering - if(ProfIsCapturing()) + if(ProfIsCapturing() || DEV_telemetry_capture) { df_gfx_request_frame(); } @@ -11723,8 +12575,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) if(n == cfg_panels) { panel = ws->root_panel; - panel->size_pct_of_parent.v[panel_parent->split_axis] = panel->size_pct_of_parent_target.v[panel_parent->split_axis] = 1.f; - panel->size_pct_of_parent.v[axis2_flip(panel_parent->split_axis)] = panel->size_pct_of_parent_target.v[axis2_flip(panel_parent->split_axis)] = 1.f; + panel->pct_of_parent = 1.f; } // rjf: allocate & insert non-root panels - these will have a numeric string, determining @@ -11734,8 +12585,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) panel = df_panel_alloc(ws); df_panel_insert(panel_parent, panel_parent->last, panel); panel->split_axis = axis2_flip(panel_parent->split_axis); - panel->size_pct_of_parent.v[panel_parent->split_axis] = panel->size_pct_of_parent_target.v[panel_parent->split_axis] = (F32)f64_from_str8(n->string); - panel->size_pct_of_parent.v[axis2_flip(panel_parent->split_axis)] = panel->size_pct_of_parent_target.v[axis2_flip(panel_parent->split_axis)] = 1.f; + panel->pct_of_parent = (F32)f64_from_str8(n->string); } // rjf: do general per-panel work @@ -11783,6 +12633,14 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) // rjf: check if this view is selected view_is_selected = df_cfg_node_child_from_string(op, str8_lit("selected"), StringMatchFlag_CaseInsensitive) != &df_g_nil_cfg_node; + // rjf: read view query string + String8 view_query = str8_lit(""); + if(view_spec_flags & DF_ViewSpecFlag_CanSerializeQuery) + { + String8 escaped_query = df_cfg_node_child_from_string(op, str8_lit("query"), StringMatchFlag_CaseInsensitive)->first->string; + view_query = df_cfg_raw_from_escaped_string(scratch.arena, escaped_query); + } + // rjf: read entity path DF_Entity *entity = &df_g_nil_entity; if(view_spec_flags & DF_ViewSpecFlag_CanSerializeEntityPath) @@ -11793,7 +12651,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) } // rjf: set up view - df_view_equip_spec(view, view_spec, entity, str8_lit(""), op); + df_view_equip_spec(ws, view, view_spec, entity, view_query, op); } // rjf: insert @@ -11853,7 +12711,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) { if(df_panel_is_nil(panel->first)) { - Rng2F32 rect = df_rect_from_panel(root_rect, ws->root_panel, panel); + Rng2F32 rect = df_target_rect_from_panel(root_rect, ws->root_panel, panel); Vec2F32 dim = dim_2f32(rect); F32 area = dim.x*dim.y; if(best_leaf_panel_area == 0 || area > best_leaf_panel_area) diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index 0809b846..425ea56b 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -73,7 +73,7 @@ struct DF_View; struct DF_Panel; struct DF_Window; -#define DF_VIEW_SETUP_FUNCTION_SIG(name) void name(struct DF_View *view, DF_CfgNode *cfg_root) +#define DF_VIEW_SETUP_FUNCTION_SIG(name) void name(DF_Window *ws, struct DF_View *view, DF_CfgNode *cfg_root) #define DF_VIEW_SETUP_FUNCTION_NAME(name) df_view_setup_##name #define DF_VIEW_SETUP_FUNCTION_DEF(name) internal DF_VIEW_SETUP_FUNCTION_SIG(DF_VIEW_SETUP_FUNCTION_NAME(name)) typedef DF_VIEW_SETUP_FUNCTION_SIG(DF_ViewSetupFunctionType); @@ -102,9 +102,10 @@ enum DF_ViewSpecFlag_ParameterizedByEntity = (1<<0), DF_ViewSpecFlag_CanSerialize = (1<<1), DF_ViewSpecFlag_CanSerializeEntityPath = (1<<2), - DF_ViewSpecFlag_CanFilter = (1<<3), - DF_ViewSpecFlag_FilterIsCode = (1<<4), - DF_ViewSpecFlag_TypingAutomaticallyFilters = (1<<5), + DF_ViewSpecFlag_CanSerializeQuery = (1<<3), + DF_ViewSpecFlag_CanFilter = (1<<4), + DF_ViewSpecFlag_FilterIsCode = (1<<5), + DF_ViewSpecFlag_TypingAutomaticallyFilters = (1<<6), }; typedef struct DF_ViewSpecInfo DF_ViewSpecInfo; @@ -226,10 +227,10 @@ struct DF_Panel // rjf: split data Axis2 split_axis; - Vec2F32 off_pct_of_parent; - Vec2F32 off_pct_of_parent_target; - Vec2F32 size_pct_of_parent; - Vec2F32 size_pct_of_parent_target; + F32 pct_of_parent; + + // rjf: animated rectangle data + Rng2F32 animated_rect_pct; // rjf: tab params Side tab_side; @@ -281,7 +282,6 @@ enum DF_GfxViewRuleSpecInfoFlag_LineStringize = (1<<1), DF_GfxViewRuleSpecInfoFlag_RowUI = (1<<2), DF_GfxViewRuleSpecInfoFlag_BlockUI = (1<<3), - DF_GfxViewRuleSpecInfoFlag_WholeUI = (1<<4), }; #define DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_SIG(name) void name(void) @@ -296,19 +296,14 @@ enum #define DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(name) df_gfx_view_rule_row_ui__##name #define DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(name) DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_SIG(DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(name)) -#define DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_SIG(name) void name(struct DF_Window *ws, DF_ExpandKey key, DF_Eval eval, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, struct DF_CfgNode *cfg, Vec2F32 dim) +#define DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_SIG(name) void name(struct DF_Window *ws, DF_ExpandKey key, DF_Eval eval, String8 string, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, struct DF_CfgNode *cfg, Vec2F32 dim) #define DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(name) df_gfx_view_rule_block_ui__##name #define DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(name) DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_SIG(DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(name)) -#define DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_SIG(name) void name(struct DF_Window *ws, struct DF_Panel *panel, struct DF_View *view, Rng2F32 rect, DBGI_Scope *dbgi_scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, struct DF_CfgNode *cfg) -#define DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_NAME(name) df_gfx_view_rule_whole_ui__##name -#define DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_DEF(name) DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_SIG(DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_NAME(name)) - typedef DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_SIG(DF_GfxViewRuleVizRowProdHookFunctionType); typedef DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_SIG(DF_GfxViewRuleLineStringizeHookFunctionType); typedef DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_SIG(DF_GfxViewRuleRowUIFunctionType); typedef DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_SIG(DF_GfxViewRuleBlockUIFunctionType); -typedef DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_SIG(DF_GfxViewRuleWholeUIFunctionType); typedef struct DF_GfxViewRuleSpecInfo DF_GfxViewRuleSpecInfo; struct DF_GfxViewRuleSpecInfo @@ -319,7 +314,7 @@ struct DF_GfxViewRuleSpecInfo DF_GfxViewRuleLineStringizeHookFunctionType *line_stringize; DF_GfxViewRuleRowUIFunctionType *row_ui; DF_GfxViewRuleBlockUIFunctionType *block_ui; - DF_GfxViewRuleWholeUIFunctionType *whole_ui; + String8 tab_view_spec_name; }; typedef struct DF_GfxViewRuleSpecInfoArray DF_GfxViewRuleSpecInfoArray; @@ -707,6 +702,9 @@ struct DF_GfxState String8 cfg_main_font_path; String8 cfg_code_font_path; F_Tag cfg_font_tags[DF_FontSlot_COUNT]; + + // rjf: icon texture + R_Handle icon_texture; }; //////////////////////////////// @@ -765,6 +763,8 @@ read_only global DF_Panel df_g_nil_panel = global DF_GfxState *df_gfx_state = 0; global DF_DragDropPayload df_g_drag_drop_payload = {0}; +global DF_Handle df_g_last_drag_drop_panel = {0}; +global DF_Handle df_g_last_drag_drop_prev_tab = {0}; //////////////////////////////// //~ rjf: Basic Helpers @@ -805,8 +805,8 @@ internal DF_PanelRec df_panel_rec_df(DF_Panel *panel, U64 sib_off, U64 child_off #define df_panel_rec_df_post(panel) df_panel_rec_df(panel, OffsetOf(DF_Panel, prev), OffsetOf(DF_Panel, last)) //- rjf: panel -> rect calculations -internal Rng2F32 df_rect_from_panel_child(Rng2F32 parent_rect, DF_Panel *parent, DF_Panel *panel); -internal Rng2F32 df_rect_from_panel(Rng2F32 root_rect, DF_Panel *root, DF_Panel *panel); +internal Rng2F32 df_target_rect_from_panel_child(Rng2F32 parent_rect, DF_Panel *parent, DF_Panel *panel); +internal Rng2F32 df_target_rect_from_panel(Rng2F32 root_rect, DF_Panel *root, DF_Panel *panel); //- rjf: view ownership insertion/removal internal void df_panel_insert_tab_view(DF_Panel *panel, DF_View *prev_view, DF_View *view); @@ -864,13 +864,14 @@ internal DF_ViewSpec *df_view_spec_from_cmd_param_slot_spec(DF_CmdParamSlot slot internal void df_register_gfx_view_rule_specs(DF_GfxViewRuleSpecInfoArray specs); internal DF_GfxViewRuleSpec *df_gfx_view_rule_spec_from_string(String8 string); +internal DF_ViewSpec *df_tab_view_spec_from_gfx_view_rule_spec(DF_GfxViewRuleSpec *spec); //////////////////////////////// //~ rjf: View State Functions internal DF_View *df_view_alloc(void); internal void df_view_release(DF_View *view); -internal void df_view_equip_spec(DF_View *view, DF_ViewSpec *spec, DF_Entity *entity, String8 default_query, DF_CfgNode *cfg_root); +internal void df_view_equip_spec(DF_Window *window, DF_View *view, DF_ViewSpec *spec, DF_Entity *entity, String8 default_query, DF_CfgNode *cfg_root); internal void df_view_equip_loading_info(DF_View *view, B32 is_loading, U64 progress_v, U64 progress_target); internal void df_view_clear_user_state(DF_View *view); internal void *df_view_get_or_push_user_state(DF_View *view, U64 size); diff --git a/src/df/gfx/df_gfx.mdesk b/src/df/gfx/df_gfx.mdesk index e764b418..13508c04 100644 --- a/src/df/gfx/df_gfx.mdesk +++ b/src/df/gfx/df_gfx.mdesk @@ -8,6 +8,7 @@ @embed_file df_g_default_main_font_bytes: "../data/Roboto-Regular.ttf" @embed_file df_g_default_code_font_bytes: "../data/liberation-mono.ttf" //@embed_file df_g_default_code_font_bytes: "../data/Inconsolata-Regular.ttf" +@embed_file df_g_icon_file_bytes: "../data/logo.ico" //////////////////////////////// //~ rjf: Default Bindings @@ -182,7 +183,6 @@ DF_NameKindTable: { {Null} {EntityName} - {EntityKindName} } @table(name, name_lower, display_string, name_kind, icon, parameterized_by_entity, can_serialize, can_serialize_entity_path, can_filter, filter_is_code, typing_automatically_filters, inc_in_docs, docs_desc) @@ -193,18 +193,18 @@ DF_GfxViewTable: { Commands "commands" "Commands" Null List 0 0 0 0 0 0 0 "" } { FileSystem "file_system" "File System" Null FileOutline 0 0 0 0 0 0 0 "" } { SystemProcesses "system_processes" "System Processes" Null Null 0 0 0 0 0 0 0 "" } - { EntityLister "entity_lister" "Entity List" EntityKindName Null 0 0 0 0 0 0 0 "" } + { EntityLister "entity_lister" "Entity List" Null Null 0 0 0 0 0 0 0 "" } { SymbolLister "symbol_lister" "Symbols" Null Null 0 0 0 0 0 0 0 "" } { Target "target" "Target" EntityName Target 1 0 0 0 0 0 0 "" } { Targets "targets" "Targets" Null Target 0 1 0 1 0 1 1 "Displays a list of all targets, as well as controls for enabling, disabling, launching, editing, or deleting each target. For more information on targets, read the `Targets` section." } { FilePathMap "file_path_map" "File Path Map" Null FileOutline 0 1 0 0 0 0 1 "Displays a table of *path maps*. Each path map is a pair of file or folder paths, one being a 'source' path, and one being a 'destination' path. These pairs are used by the debugger when automatically searching for specific files - for instance, when attempting to snap to a source code location specified by debug info. If debug info refers to a path on the machine on which a target executable was originally built, but that path is not valid on the debugger machine, but some alternative path exists, then path maps may be used to redirect the debugger from the debug info's specified paths to the associated appropriate debugger machine file paths." } + { AutoViewRules "auto_view_rules" "Auto View Rules" Null Binoculars 0 1 0 0 0 0 1 "Displays a table of *auto view rules*. Each *auto view rule* is a pair, with one element being a type, and the other being a view rule, which should be automatically applied to expressions of that type, when possible." } { Scheduler "scheduler" "Scheduler" Null Scheduler 0 1 0 1 1 1 1 "Displays all processes and threads to which the debugger is currently attached, and contains controls for selecting and freezing threads." } { CallStack "call_stack" "Call Stack" Null Thread 0 1 0 0 0 0 1 "Displays the call stack of the currently selected thread. Each frame in the call stack contains the associated module, function name, and return address. Allows selection of a particular call stack frame other than the top." } { Modules "modules" "Modules" Null Module 0 1 0 1 0 1 1 "Displays a table of all modules currently loaded by any process to which the debugger is attached. This table displays each module's name, virtual address range in the containing process' address space, and which debug info file is being used by the debugger for the associated module." } { PendingEntity "pending_entity" "Pending Entity" EntityName FileOutline 1 0 0 0 0 0 0 "" } { Code "code" "Code" EntityName FileOutline 1 1 1 0 0 0 0 "" } { Disassembly "disassembly" "Disassembly" Null Glasses 0 1 0 0 0 0 1 "Displays disassembled instructions in a textual form from the selected thread's containing process virtual address space." } - { EvalViewer "eval_viewer" "Evaluation Viewer" Null Binoculars 0 1 0 0 0 0 0 "." } { Watch "watch" "Watch" Null Binoculars 0 1 0 1 1 1 1 "The familiar 'watch window' debugger interface. Allows the inputting of a number of expressions. Each expression in the table is evaluated within the context of the selected thread's selected call stack frame. If applicable (depending on visualization rules and the expression's type), these expressions may be hierarchically expanded, which displays children as more rows in the table. The values of these expressions may also be edited, and if possible, can be used to write to registers or memory in attached processes. Also contains a new *view rule* column, not found in other major debuggers, which allows per-row specification of various visualization rules. These view rules may be used to visualize and inspect the evaluation of expressions in a variety of ways. To learn more, read the 'View Rules' section." } { Locals "locals" "Locals" Null Binoculars 0 1 0 1 1 1 1 "Nearly identical to `Watch`, but automatically filled with local variables found within the selected call stack frame of the selected thread, according to the associated debug info. View rules and evaluation values can be edited, like in `Watch`, but unlike `Watch`, expressions cannot be edited or added to the table." } { Registers "registers" "Registers" Null Binoculars 0 1 0 1 1 1 1 "Nearly identical to `Watch`, but automatically filled with all register names according to the selected thread's architecture. View rules and evaluation values can be edited, like in `Watch`, but unlike `Watch`, expressions cannot be edited or added to the table." } @@ -240,25 +240,25 @@ DF_CmdParamSlot2ViewSpecMap: // // NOTE(rjf): see @view_rule_info -@table(string vr ls ru bu wu) +@table(string vr ls ru bu tu tab_display_string) DF_GfxViewRuleTable: { - {"array" - - - - - } - {"slice" - - - - - } - {"list" x - - - - } - {"dec" - x - - - } - {"bin" - x - - - } - {"oct" - x - - - } - {"hex" - x - - - } - {"only" x x - - - } - {"omit" x x - - - } - {"no_addr" - x - - - } - {"rgba" - - x x - } - {"text" - - - x - } - {"disasm" - - - x - } - {"bitmap" - - x x x } - {"odin_map" - - x x x } - {"geo" - - x x - } + {"array" - - - - - "" } + {"slice" - - - - - "" } + {"list" x - - - - "" } + {"dec" - x - - - "" } + {"bin" - x - - - "" } + {"oct" - x - - - "" } + {"hex" - x - - - "" } + {"only" x x - - - "" } + {"omit" x x - - - "" } + {"no_addr" - x - - - "" } + {"rgba" - - x x - "" } + {"text" - - - x x "Text" } + {"disasm" - - - x x "Disassembly" } + {"bitmap" - - x x x "Bitmap" } + {"odin_map" - - x x x "Odin HashMap" } + {"geo" - - x x x "Geometry" } } //////////////////////////////// @@ -559,7 +559,13 @@ DF_ThemePresetColorTable: @expand(DF_GfxViewRuleTable a) `$(a.bu == "x" -> "DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(" .. a.name_lower .. ");")`; @expand(DF_GfxViewRuleTable a) - `$(a.wu == "x" -> "DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_DEF(" .. a.name_lower .. ");")`; + `$(a.tu == "x" -> "DF_VIEW_SETUP_FUNCTION_DEF(" .. a.name_lower .. ");")`; + @expand(DF_GfxViewRuleTable a) + `$(a.tu == "x" -> "DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(" .. a.name_lower .. ");")`; + @expand(DF_GfxViewRuleTable a) + `$(a.tu == "x" -> "DF_VIEW_CMD_FUNCTION_DEF(" .. a.name_lower .. ");")`; + @expand(DF_GfxViewRuleTable a) + `$(a.tu == "x" -> "DF_VIEW_UI_FUNCTION_DEF(" .. a.name_lower .. ");")`; } //- rjf: gfx view rule tables @@ -567,7 +573,13 @@ DF_ThemePresetColorTable: @data(DF_GfxViewRuleSpecInfo) @c_file df_g_gfx_view_rule_spec_info_table: { @expand(DF_GfxViewRuleTable a) - ```{ str8_lit_comp("$(a.string)"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*$(a.vr == "x"))|(DF_GfxViewRuleSpecInfoFlag_LineStringize*$(a.ls == "x"))|(DF_GfxViewRuleSpecInfoFlag_RowUI*$(a.ru == "x"))|(DF_GfxViewRuleSpecInfoFlag_BlockUI*$(a.bu == "x")), $(a.vr == "x" -> "DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME("..a.name_lower..")") $(a.vr != "x" -> 0), $(a.ls == "x" -> "DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME("..a.name_lower..")") $(a.ls != "x" -> 0), $(a.ru == "x" -> "DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME("..a.name_lower..")") $(a.ru != "x" -> 0), $(a.bu == "x" -> "DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME("..a.name_lower..")") $(a.bu != "x" -> 0), $(a.wu == "x" -> "DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_NAME("..a.name_lower..")") $(a.wu != "x" -> 0) }```; + ```{ str8_lit_comp("$(a.string)"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*$(a.vr == "x"))|(DF_GfxViewRuleSpecInfoFlag_LineStringize*$(a.ls == "x"))|(DF_GfxViewRuleSpecInfoFlag_RowUI*$(a.ru == "x"))|(DF_GfxViewRuleSpecInfoFlag_BlockUI*$(a.bu == "x")), $(a.vr == "x" -> "DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME("..a.name_lower..")") $(a.vr != "x" -> 0), $(a.ls == "x" -> "DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME("..a.name_lower..")") $(a.ls != "x" -> 0), $(a.ru == "x" -> "DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME("..a.name_lower..")") $(a.ru != "x" -> 0), $(a.bu == "x" -> "DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME("..a.name_lower..")") $(a.bu != "x" -> 0), str8_lit_comp("$(a.tu == 'x' -> a.string..'_view_rule')") }```; +} + +@data(DF_ViewSpecInfo) @c_file df_g_gfx_view_rule_tab_view_spec_info_table: +{ + @expand(DF_GfxViewRuleTable a) + ```$(a.tu == "x" -> '{ DF_ViewSpecFlag_CanSerialize|DF_ViewSpecFlag_CanSerializeQuery, str8_lit_comp("' .. a.string .. '_view_rule"), str8_lit_comp("' .. a.tab_display_string .. '"), DF_NameKind_Null, DF_IconKind_Binoculars, ' .. 'DF_VIEW_SETUP_FUNCTION_NAME(' .. a.string .. '), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(' .. a.string .. '), DF_VIEW_CMD_FUNCTION_NAME(' .. a.string .. '), DF_VIEW_UI_FUNCTION_NAME(' .. a.string .. ') }')```; } //- rjf: default view spec info table diff --git a/src/df/gfx/df_view_rule_hooks.h b/src/df/gfx/df_view_rule_hooks.h deleted file mode 100644 index 4ac8729e..00000000 --- a/src/df/gfx/df_view_rule_hooks.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2024 Epic Games Tools -// Licensed under the MIT license (https://opensource.org/license/mit/) - -#ifndef DF_VIEW_RULE_HOOKS_H -#define DF_VIEW_RULE_HOOKS_H - -//////////////////////////////// -//~ rjf: Helper Types - -typedef struct DF_BitmapTopologyInfo DF_BitmapTopologyInfo; -struct DF_BitmapTopologyInfo -{ - U64 width; - U64 height; - R_Tex2DFormat fmt; -}; - -typedef struct DF_GeoTopologyInfo DF_GeoTopologyInfo; -struct DF_GeoTopologyInfo -{ - U64 index_count; - Rng1U64 vertices_vaddr_range; -}; - -typedef struct DF_TxtTopologyInfo DF_TxtTopologyInfo; -struct DF_TxtTopologyInfo -{ - TXT_LangKind lang; - U64 size_cap; -}; - -typedef struct DF_DisasmTopologyInfo DF_DisasmTopologyInfo; -struct DF_DisasmTopologyInfo -{ - Architecture arch; - U64 size_cap; -}; - -//////////////////////////////// -//~ rjf: Helpers - -internal Vec4F32 df_view_rule_hooks__rgba_from_eval(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_Entity *process); -internal void df_view_rule_hooks__eval_commit_rgba(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_CtrlCtx *ctrl_ctx, Vec4F32 rgba); -internal DF_BitmapTopologyInfo df_view_rule_hooks__bitmap_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); -internal DF_GeoTopologyInfo df_view_rule_hooks__geo_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); -internal DF_TxtTopologyInfo df_view_rule_hooks__txt_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); -internal DF_DisasmTopologyInfo df_view_rule_hooks__disasm_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); - -#endif //DF_VIEW_RULE_HOOKS_H diff --git a/src/df/gfx/df_view_rule_hooks.c b/src/df/gfx/df_view_rules.c similarity index 69% rename from src/df/gfx/df_view_rule_hooks.c rename to src/df/gfx/df_view_rules.c index 9f4161a2..a60847ea 100644 --- a/src/df/gfx/df_view_rule_hooks.c +++ b/src/df/gfx/df_view_rules.c @@ -2,10 +2,124 @@ // Licensed under the MIT license (https://opensource.org/license/mit/) //////////////////////////////// -//~ rjf: Helpers +//~ rjf: "array" + +DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(array) +{ + Temp scratch = scratch_begin(&arena, 1); + TG_Key type_key = eval.type_key; + TG_Kind type_kind = tg_kind_from_key(type_key); + if(type_kind == TG_Kind_Ptr || type_kind == TG_Kind_LRef || type_kind == TG_Kind_RRef) + { + DF_CfgNode *array_node = val->last; + if(array_node != &df_g_nil_cfg_node) + { + // rjf: determine array size + U64 array_size = 0; + { + String8List array_size_expr_strs = {0}; + for(DF_CfgNode *child = array_node->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &array_size_expr_strs, child->string); + } + String8 array_size_expr = str8_list_join(scratch.arena, &array_size_expr_strs, 0); + DF_Eval array_size_eval = df_eval_from_string(arena, dbgi_scope, ctrl_ctx, parse_ctx, macro_map, array_size_expr); + DF_Eval array_size_eval_value = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, array_size_eval); + eval_error_list_concat_in_place(&eval.errors, &array_size_eval.errors); + array_size = array_size_eval_value.imm_u64; + } + + // rjf: apply array size to type + TG_Key pointee = tg_ptee_from_graph_rdi_key(parse_ctx->type_graph, parse_ctx->rdi, type_key); + TG_Key array_type = tg_cons_type_make(parse_ctx->type_graph, TG_Kind_Array, pointee, array_size); + eval.type_key = tg_cons_type_make(parse_ctx->type_graph, TG_Kind_Ptr, array_type, 0); + } + } + scratch_end(scratch); + return eval; +} + +//////////////////////////////// +//~ rjf: "list" + +DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(list){} +DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_DEF(list){} + +//////////////////////////////// +//~ rjf: "bswap" + +DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(bswap) +{ + Temp scratch = scratch_begin(&arena, 1); + TG_Key type_key = eval.type_key; + TG_Kind type_kind = tg_kind_from_key(type_key); + U64 type_size_bytes = tg_byte_size_from_graph_rdi_key(parse_ctx->type_graph, parse_ctx->rdi, type_key); + if(TG_Kind_Char8 <= type_kind && type_kind <= TG_Kind_S256 && + (type_size_bytes == 2 || + type_size_bytes == 4 || + type_size_bytes == 8)) + { + DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); + if(value_eval.mode == EVAL_EvalMode_Value) + { + switch(type_size_bytes) + { + default:{}break; + case 2:{U16 v = (U16)value_eval.imm_u64; v = bswap_u16(v); value_eval.imm_u64 = (U64)v;}break; + case 4:{U32 v = (U32)value_eval.imm_u64; v = bswap_u32(v); value_eval.imm_u64 = (U64)v;}break; + case 8:{U64 v = value_eval.imm_u64; v = bswap_u64(v); value_eval.imm_u64 = v;}break; + } + } + eval = value_eval; + } + scratch_end(scratch); + return eval; +} + +//////////////////////////////// +//~ rjf: "dec" + +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(dec){} + +//////////////////////////////// +//~ rjf: "bin" + +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(bin){} + +//////////////////////////////// +//~ rjf: "oct" + +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(oct){} + +//////////////////////////////// +//~ rjf: "hex" + +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(hex){} + +//////////////////////////////// +//~ rjf: "only" + +DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(only){} +DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_DEF(only){} +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(only){} + +//////////////////////////////// +//~ rjf: "omit" + +DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(omit){} +DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_DEF(omit){} +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(omit){} + +//////////////////////////////// +//~ rjf: "no_addr" + +DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(no_addr){} + +//////////////////////////////// +//~ rjf: "rgba" internal Vec4F32 -df_view_rule_hooks__rgba_from_eval(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_Entity *process) +df_vr_rgba_from_eval(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_Entity *process) { Vec4F32 rgba = {0}; Temp scratch = scratch_begin(0, 0); @@ -102,7 +216,7 @@ df_view_rule_hooks__rgba_from_eval(DF_Eval eval, TG_Graph *graph, RDI_Parsed *ra } internal void -df_view_rule_hooks__eval_commit_rgba(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_CtrlCtx *ctrl_ctx, Vec4F32 rgba) +df_vr_eval_commit_rgba(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_CtrlCtx *ctrl_ctx, Vec4F32 rgba) { TG_Key type_key = eval.type_key; TG_Kind type_kind = tg_kind_from_key(type_key); @@ -913,6 +1027,7 @@ DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(rgba) { DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); vb->eval = eval; + vb->string = string; vb->cfg_table = *cfg_table; vb->visual_idx_range = r1u64(0, 8); vb->semantic_idx_range = r1u64(0, 1); @@ -927,7 +1042,7 @@ DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(rgba) //- rjf: grab hsva DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); - Vec4F32 rgba = df_view_rule_hooks__rgba_from_eval(value_eval, parse_ctx->type_graph, parse_ctx->rdi, process); + Vec4F32 rgba = df_vr_rgba_from_eval(value_eval, parse_ctx->type_graph, parse_ctx->rdi, process); Vec4F32 hsva = hsva_from_rgba(rgba); //- rjf: build text box @@ -987,7 +1102,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(rgba) Temp scratch = scratch_begin(0, 0); DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_ViewRuleHooks_RGBAState *state = df_view_rule_block_user_state(key, DF_ViewRuleHooks_RGBAState); + DF_VR_RGBAState *state = df_view_rule_block_user_state(key, DF_VR_RGBAState); //- rjf: grab hsva Vec4F32 rgba = {0}; @@ -1001,7 +1116,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(rgba) else { DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); - rgba = df_view_rule_hooks__rgba_from_eval(value_eval, parse_ctx->type_graph, parse_ctx->rdi, process); + rgba = df_vr_rgba_from_eval(value_eval, parse_ctx->type_graph, parse_ctx->rdi, process); state->hsva = hsva = hsva_from_rgba(rgba); state->memgen_idx = ctrl_mem_gen(); } @@ -1051,7 +1166,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(rgba) if(commit) { Vec4F32 rgba = rgba_from_hsva(hsva); - df_view_rule_hooks__eval_commit_rgba(eval, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, rgba); + df_vr_eval_commit_rgba(eval, parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, rgba); state->memgen_idx = ctrl_mem_gen(); } @@ -1064,21 +1179,38 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(rgba) //////////////////////////////// //~ rjf: "text" -typedef struct DF_ViewRuleHooks_TextState DF_ViewRuleHooks_TextState; -struct DF_ViewRuleHooks_TextState +internal DF_TxtTopologyInfo +df_vr_txt_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg) { - B32 initialized; - TxtPt cursor; - TxtPt mark; - S64 preferred_column; - U64 last_open_frame_idx; - F32 loaded_t; -}; + Temp scratch = scratch_begin(0, 0); + DF_TxtTopologyInfo result = zero_struct; + { + StringJoin join = {0}; + join.sep = str8_lit(" "); + DF_CfgNode *size_cfg = df_cfg_node_child_from_string(cfg, str8_lit("size"), 0); + DF_CfgNode *lang_cfg = df_cfg_node_child_from_string(cfg, str8_lit("lang"), 0); + String8List size_expr_strs = {0}; + String8 lang_string = {0}; + for(DF_CfgNode *child = size_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &size_expr_strs, child->string); + } + lang_string = lang_cfg->first->string; + String8 size_expr = str8_list_join(scratch.arena, &size_expr_strs, &join); + DF_Eval size_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, size_expr); + DF_Eval size_val_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, size_eval); + result.lang = txt_lang_kind_from_extension(lang_string); + result.size_cap = size_val_eval.imm_u64; + } + scratch_end(scratch); + return result; +} DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(text) { DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); vb->eval = eval; + vb->string = string; vb->cfg_table = *cfg_table; vb->visual_idx_range = r1u64(0, 8); vb->semantic_idx_range = r1u64(0, 1); @@ -1094,7 +1226,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text) ////////////////////////////// //- rjf: get & initialize state // - DF_ViewRuleHooks_TextState *state = df_view_rule_block_user_state(key, DF_ViewRuleHooks_TextState); + DF_VR_TextState *state = df_view_rule_block_user_state(key, DF_VR_TextState); if(!state->initialized) { state->initialized = 1; @@ -1106,7 +1238,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text) // DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_TxtTopologyInfo top = df_view_rule_hooks__txt_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); + DF_TxtTopologyInfo top = df_vr_txt_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; Rng1U64 vaddr_range = r1u64(base_vaddr, base_vaddr + (top.size_cap ? top.size_cap : 2048)); @@ -1178,24 +1310,51 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text) scratch_end(scratch); } +DF_VIEW_SETUP_FUNCTION_DEF(text) {} +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(text) { return str8_lit(""); } +DF_VIEW_CMD_FUNCTION_DEF(text) {} +DF_VIEW_UI_FUNCTION_DEF(text) +{ +} + //////////////////////////////// //~ rjf: "disasm" -typedef struct DF_ViewRuleHooks_DisasmState DF_ViewRuleHooks_DisasmState; -struct DF_ViewRuleHooks_DisasmState +internal DF_DisasmTopologyInfo +df_vr_disasm_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg) { - B32 initialized; - TxtPt cursor; - TxtPt mark; - S64 preferred_column; - U64 last_open_frame_idx; - F32 loaded_t; -}; + Temp scratch = scratch_begin(0, 0); + DF_DisasmTopologyInfo result = zero_struct; + { + StringJoin join = {0}; + join.sep = str8_lit(" "); + DF_CfgNode *size_cfg = df_cfg_node_child_from_string(cfg, str8_lit("size"), 0); + DF_CfgNode *arch_cfg = df_cfg_node_child_from_string(cfg, str8_lit("arch"), 0); + String8List size_expr_strs = {0}; + String8 arch_string = {0}; + for(DF_CfgNode *child = size_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &size_expr_strs, child->string); + } + arch_string = arch_cfg->first->string; + String8 size_expr = str8_list_join(scratch.arena, &size_expr_strs, &join); + DF_Eval size_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, size_expr); + DF_Eval size_val_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, size_eval); + if(str8_match(arch_string, str8_lit("x64"), StringMatchFlag_CaseInsensitive)) + { + result.arch = Architecture_x64; + } + result.size_cap = size_val_eval.imm_u64; + } + scratch_end(scratch); + return result; +} DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(disasm) { DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); vb->eval = eval; + vb->string = string; vb->cfg_table = *cfg_table; vb->visual_idx_range = r1u64(0, 8); vb->semantic_idx_range = r1u64(0, 1); @@ -1208,7 +1367,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm) HS_Scope *hs_scope = hs_scope_open(); TXT_Scope *txt_scope = txt_scope_open(); DASM_Scope *dasm_scope = dasm_scope_open(); - DF_ViewRuleHooks_DisasmState *state = df_view_rule_block_user_state(key, DF_ViewRuleHooks_DisasmState); + DF_VR_DisasmState *state = df_view_rule_block_user_state(key, DF_VR_DisasmState); if(!state->initialized) { state->initialized = 1; @@ -1221,7 +1380,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm) state->last_open_frame_idx = df_frame_index(); { //- rjf: unpack params - DF_DisasmTopologyInfo top = df_view_rule_hooks__disasm_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); + DF_DisasmTopologyInfo top = df_vr_disasm_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); //- rjf: resolve to address value & range DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); @@ -1237,7 +1396,16 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm) //- rjf: key -> parsed text info U128 data_hash = {0}; - DASM_Info dasm_info = dasm_info_from_key_addr_arch_style(dasm_scope, dasm_key, vaddr_range.min, top.arch, 0, DASM_Syntax_Intel, &data_hash); + DASM_Params dasm_params = {0}; + { + dasm_params.vaddr = vaddr_range.min; + dasm_params.arch = top.arch; + dasm_params.style_flags = DASM_StyleFlag_Addresses; + dasm_params.syntax = DASM_Syntax_Intel; + dasm_params.base_vaddr = 0; + dasm_params.exe_path = str8_zero(); + } + DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &data_hash); String8 dasm_text_data = {0}; TXT_TextInfo dasm_text_info = {0}; for(U64 rewind_idx = 0; rewind_idx < 2; rewind_idx += 1) @@ -1292,37 +1460,127 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm) scratch_end(scratch); } +DF_VIEW_SETUP_FUNCTION_DEF(disasm) {} +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(disasm) { return str8_lit(""); } +DF_VIEW_CMD_FUNCTION_DEF(disasm) {} +DF_VIEW_UI_FUNCTION_DEF(disasm) +{ +} + +//////////////////////////////// +//~ rjf: "graph" + +DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(graph) +{ + DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); + vb->eval = eval; + vb->string = string; + vb->cfg_table = *cfg_table; + vb->visual_idx_range = r1u64(0, 8); + vb->semantic_idx_range = r1u64(0, 1); + df_eval_viz_block_end(out, vb); +} + +DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(graph) +{ +} + +DF_VIEW_SETUP_FUNCTION_DEF(graph) {} +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(graph) { return str8_lit(""); } +DF_VIEW_CMD_FUNCTION_DEF(graph) {} +DF_VIEW_UI_FUNCTION_DEF(graph) +{ +} + //////////////////////////////// //~ rjf: "bitmap" -typedef struct DF_ViewRuleHooks_BitmapState DF_ViewRuleHooks_BitmapState; -struct DF_ViewRuleHooks_BitmapState +internal Vec2F32 +df_bitmap_view_state__screen_from_canvas_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 cvs) { - U64 last_open_frame_idx; - F32 loaded_t; -}; + Vec2F32 scr = + { + (rect.x0+rect.x1)/2 + (cvs.x - bvs->view_center_pos.x) * bvs->zoom, + (rect.y0+rect.y1)/2 + (cvs.y - bvs->view_center_pos.y) * bvs->zoom, + }; + return scr; +} -typedef struct DF_ViewRuleHooks_BitmapBoxDrawData DF_ViewRuleHooks_BitmapBoxDrawData; -struct DF_ViewRuleHooks_BitmapBoxDrawData +internal Rng2F32 +df_bitmap_view_state__screen_from_canvas_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 cvs) { - Rng2F32 src; - R_Handle texture; - F32 loaded_t; - B32 hovered; - Vec2S32 mouse_px; - F32 ui_per_bmp_px; -}; + Rng2F32 scr = r2f32(df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p0), df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p1)); + return scr; +} -typedef struct DF_ViewRuleHooks_BitmapZoomDrawData DF_ViewRuleHooks_BitmapZoomDrawData; -struct DF_ViewRuleHooks_BitmapZoomDrawData +internal Vec2F32 +df_bitmap_view_state__canvas_from_screen_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 scr) { - Rng2F32 src; - R_Handle texture; -}; + Vec2F32 cvs = + { + (scr.x - (rect.x0+rect.x1)/2) / bvs->zoom + bvs->view_center_pos.x, + (scr.y - (rect.y0+rect.y1)/2) / bvs->zoom + bvs->view_center_pos.y, + }; + return cvs; +} -internal UI_BOX_CUSTOM_DRAW(df_view_rule_hooks__bitmap_box_draw) +internal Rng2F32 +df_bitmap_view_state__canvas_from_screen_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 scr) { - DF_ViewRuleHooks_BitmapBoxDrawData *draw_data = (DF_ViewRuleHooks_BitmapBoxDrawData *)user_data; + Rng2F32 cvs = r2f32(df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p0), df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p1)); + return cvs; +} + +internal DF_BitmapTopologyInfo +df_vr_bitmap_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg) +{ + Temp scratch = scratch_begin(0, 0); + DF_BitmapTopologyInfo info = {0}; + { + info.fmt = R_Tex2DFormat_RGBA8; + } + { + DF_CfgNode *width_cfg = df_cfg_node_child_from_string(cfg, str8_lit("w"), 0); + DF_CfgNode *height_cfg = df_cfg_node_child_from_string(cfg, str8_lit("h"), 0); + DF_CfgNode *fmt_cfg = df_cfg_node_child_from_string(cfg, str8_lit("fmt"), 0); + String8List width_expr_strs = {0}; + String8List height_expr_strs = {0}; + for(DF_CfgNode *child = width_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &width_expr_strs, child->string); + } + for(DF_CfgNode *child = height_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &height_expr_strs, child->string); + } + String8 width_expr = str8_list_join(scratch.arena, &width_expr_strs, 0); + String8 height_expr = str8_list_join(scratch.arena, &height_expr_strs, 0); + String8 fmt_string = fmt_cfg->first->string; + DF_Eval width_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, width_expr); + DF_Eval width_eval_value = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, width_eval); + info.width = width_eval_value.imm_u64; + DF_Eval height_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, height_expr); + DF_Eval height_eval_value = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, height_eval); + info.height = height_eval_value.imm_u64; + if(fmt_string.size != 0) + { + for(R_Tex2DFormat fmt = (R_Tex2DFormat)0; fmt < R_Tex2DFormat_COUNT; fmt = (R_Tex2DFormat)(fmt+1)) + { + if(str8_match(r_tex2d_format_display_string_table[fmt], fmt_string, StringMatchFlag_CaseInsensitive)) + { + info.fmt = fmt; + break; + } + } + } + } + scratch_end(scratch); + return info; +} + +internal UI_BOX_CUSTOM_DRAW(df_vr_bitmap_box_draw) +{ + DF_VR_BitmapBoxDrawData *draw_data = (DF_VR_BitmapBoxDrawData *)user_data; Vec4F32 bg_color = box->background_color; d_img(box->rect, draw_data->src, draw_data->texture, v4f32(1, 1, 1, 1), 0, 0, 0); if(draw_data->loaded_t < 0.98f) @@ -1355,16 +1613,11 @@ internal UI_BOX_CUSTOM_DRAW(df_view_rule_hooks__bitmap_box_draw) } } -internal UI_BOX_CUSTOM_DRAW(df_view_rule_hooks__bitmap_zoom_draw) -{ - DF_ViewRuleHooks_BitmapZoomDrawData *draw_data = (DF_ViewRuleHooks_BitmapZoomDrawData *)user_data; - d_img(box->rect, draw_data->src, draw_data->texture, v4f32(1, 1, 1, 1), 0, 0, 0); -} - DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(bitmap) { DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); vb->eval = eval; + vb->string = string; vb->cfg_table = *cfg_table; vb->visual_idx_range = r1u64(0, 8); vb->semantic_idx_range = r1u64(0, 1); @@ -1375,7 +1628,7 @@ DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(bitmap) { DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; - DF_BitmapTopologyInfo topology = df_view_rule_hooks__bitmap_topology_info_from_cfg(scope, ctrl_ctx, parse_ctx, macro_map, cfg); + DF_BitmapTopologyInfo topology = df_vr_bitmap_topology_info_from_cfg(scope, ctrl_ctx, parse_ctx, macro_map, cfg); U64 expected_size = topology.width*topology.height*r_tex2d_format_bytes_per_pixel_table[topology.fmt]; UI_Font(df_font_from_slot(DF_FontSlot_Code)) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) ui_labelf("0x%I64x -> Bitmap (%I64u x %I64u)", base_vaddr, topology.width, topology.height); @@ -1386,35 +1639,59 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap) Temp scratch = scratch_begin(0, 0); HS_Scope *hs_scope = hs_scope_open(); TEX_Scope *tex_scope = tex_scope_open(); - DF_ViewRuleHooks_BitmapState *state = df_view_rule_block_user_state(key, DF_ViewRuleHooks_BitmapState); + DF_VR_BitmapState *state = df_view_rule_block_user_state(key, DF_VR_BitmapState); if(state->last_open_frame_idx+1 < df_frame_index()) { state->loaded_t = 0; } state->last_open_frame_idx = df_frame_index(); - //- rjf: resolve to address value - DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); - U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; - - //- rjf: unpack thread/process of eval + ////////////////////////////// + //- rjf: unpack context + // DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - //- rjf: unpack image dimensions & form vaddr range - DF_BitmapTopologyInfo topology_info = df_view_rule_hooks__bitmap_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); + ////////////////////////////// + //- rjf: evaluate expression + // + DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, eval); + U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; + DF_BitmapTopologyInfo topology_info = df_vr_bitmap_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); U64 expected_size = topology_info.width*topology_info.height*r_tex2d_format_bytes_per_pixel_table[topology_info.fmt]; Rng1U64 vaddr_range = r1u64(base_vaddr, base_vaddr+expected_size); - //- rjf: obtain key for this data range + ////////////////////////////// + //- rjf: map expression artifacts -> texture + // U128 texture_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 0); - - //- rjf: hash & topology -> texture TEX_Topology topology = tex_topology_make(v2s32((S32)topology_info.width, (S32)topology_info.height), topology_info.fmt); R_Handle texture = tex_texture_from_key_topology(tex_scope, texture_key, topology); + ////////////////////////////// + //- rjf: animate + // + if(expected_size != 0) + { + if(r_handle_match(r_handle_zero(), texture)) + { + df_gfx_request_frame(); + state->loaded_t = 0; + } + else + { + F32 rate = 1 - pow_f32(2, (-15.f * df_dt())); + state->loaded_t += (1.f - state->loaded_t) * rate; + if(state->loaded_t < 0.99f) + { + df_gfx_request_frame(); + } + } + } + + ////////////////////////////// //- rjf: build preview - F32 rate = 1 - pow_f32(2, (-15.f * df_dt())); + // if(expected_size != 0) { F32 img_dim = dim.y - ui_top_font_size()*2.f; @@ -1423,105 +1700,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap) UI_Column UI_Padding(ui_pct(1.f, 0.f)) UI_PrefHeight(ui_px(img_dim, 1.f)) { - ui_set_next_hover_cursor(OS_Cursor_HandPoint); - UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clickable|UI_BoxFlag_DrawHotEffects, "image_box"); - UI_Signal sig = ui_signal_from_box(box); - F32 ui_per_bmp_px = dim.y / (F32)topology_info.height; - Vec2F32 mouse_ui_px_off = sub_2f32(ui_mouse(), box->rect.p0); - Vec2S32 mouse_bitmap_px_off = v2s32(floor_f32(mouse_ui_px_off.x/ui_per_bmp_px), floor_f32(mouse_ui_px_off.y/ui_per_bmp_px)); - DF_ViewRuleHooks_BitmapBoxDrawData *draw_data = push_array(ui_build_arena(), DF_ViewRuleHooks_BitmapBoxDrawData, 1); - draw_data->texture = texture; - draw_data->src = r2f32(v2f32(0, 0), v2f32((F32)topology_info.width, (F32)topology_info.height)); - draw_data->loaded_t = state->loaded_t; - draw_data->hovered = ui_hovering(sig); - draw_data->mouse_px = mouse_bitmap_px_off; - draw_data->ui_per_bmp_px = ui_per_bmp_px; - ui_box_equip_custom_draw(box, df_view_rule_hooks__bitmap_box_draw, draw_data); - if(r_handle_match(r_handle_zero(), texture)) - { - df_gfx_request_frame(); - state->loaded_t = 0; - } - else - { - state->loaded_t += (1.f - state->loaded_t) * rate; - if(state->loaded_t < 0.99f) - { - df_gfx_request_frame(); - } - } - if(ui_hovering(sig) && r_handle_match(texture, r_handle_zero())) UI_Tooltip - { - ui_labelf("Texture not loaded."); - } - if(ui_hovering(sig) && !r_handle_match(texture, r_handle_zero())) - { - if(dim.y > (F32)topology_info.height) - { - U128 hash = hs_hash_from_key(texture_key, 0); - String8 data = hs_data_from_hash(hs_scope, hash); - U64 bytes_per_pixel = r_tex2d_format_bytes_per_pixel_table[topology.fmt]; - U64 mouse_pixel_off = mouse_bitmap_px_off.y*topology_info.width + mouse_bitmap_px_off.x; - U64 mouse_byte_off = mouse_pixel_off * bytes_per_pixel; - B32 got_color = 0; - Vec4F32 hsva = {0}; - if(mouse_byte_off + bytes_per_pixel <= data.size) - { - got_color = 1; - switch(topology.fmt) - { - default:{got_color = 0;}break; - case R_Tex2DFormat_RGBA8: - { - U8 r = data.str[mouse_byte_off+0]; - U8 g = data.str[mouse_byte_off+1]; - U8 b = data.str[mouse_byte_off+2]; - U8 a = data.str[mouse_byte_off+3]; - Vec4F32 rgba = v4f32(r/255.f, g/255.f, b/255.f, a/255.f); - hsva = hsva_from_rgba(rgba); - }break; - case R_Tex2DFormat_BGRA8: - { - U8 r = data.str[mouse_byte_off+2]; - U8 g = data.str[mouse_byte_off+1]; - U8 b = data.str[mouse_byte_off+0]; - U8 a = data.str[mouse_byte_off+3]; - Vec4F32 rgba = v4f32(r/255.f, g/255.f, b/255.f, a/255.f); - hsva = hsva_from_rgba(rgba); - }break; - case R_Tex2DFormat_R8: - { - U8 r = data.str[mouse_byte_off+0]; - Vec4F32 rgba = v4f32(r/255.f, 0, 0, 1.f); - hsva = hsva_from_rgba(rgba); - }break; - } - } - if(got_color) - { - ui_do_color_tooltip_hsva(hsva); - } - } - else UI_Tooltip UI_Font(df_font_from_slot(DF_FontSlot_Code)) - { - ui_label(r_tex2d_format_display_string_table[topology.fmt]); - ui_labelf("%I64u x %I64u", topology_info.width, topology_info.height); - UI_Padding(ui_em(2.f, 1.f)) - UI_PrefWidth(ui_children_sum(1.f)) - UI_PrefHeight(ui_children_sum(1.f)) - UI_Row - UI_PrefWidth(ui_em(15.f, 1.f)) - UI_PrefHeight(ui_em(15.f, 1.f)) - UI_Padding(ui_em(2.f, 1.f)) - { - UI_Box *zoom_box = ui_build_box_from_key(UI_BoxFlag_DrawBorder, ui_key_zero()); - DF_ViewRuleHooks_BitmapZoomDrawData *draw_data = push_array(ui_build_arena(), DF_ViewRuleHooks_BitmapZoomDrawData, 1); - draw_data->src = r2f32p(mouse_bitmap_px_off.x - 16, mouse_bitmap_px_off.y - 16, mouse_bitmap_px_off.x + 16, mouse_bitmap_px_off.y + 16); - draw_data->texture = texture; - ui_box_equip_custom_draw(zoom_box, df_view_rule_hooks__bitmap_zoom_draw, draw_data); - } - } - } + ui_image(texture, R_Tex2DSampleKind_Nearest, r2f32(v2f32(0, 0), v2f32((F32)topology_info.width, (F32)topology_info.height)), v4f32(1, 1, 1, state->loaded_t), 10.f*(1-state->loaded_t), str8_lit("image_box")); } } @@ -1530,41 +1709,226 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap) scratch_end(scratch); } -DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_DEF(bitmap) +DF_VIEW_SETUP_FUNCTION_DEF(bitmap) { + DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState); + DBGI_Scope *dbgi_scope = dbgi_scope_open(); + DF_CfgNode *view_center_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("view_center"), StringMatchFlag_CaseInsensitive); + DF_CfgNode *zoom_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("zoom"), StringMatchFlag_CaseInsensitive); + DF_CfgNode *bitmap_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("bitmap"), StringMatchFlag_CaseInsensitive); + DF_CtrlCtx ctrl_ctx = df_ctrl_ctx_from_view(ws, view); + DF_Entity *thread = df_entity_from_handle(ctrl_ctx.thread); + DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); + U64 thread_unwind_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx.unwind_count); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(dbgi_scope, process, thread_unwind_rip_vaddr); + bvs->view_center_pos.x = (F32)f64_from_str8(bitmap_cfg->first->string); + bvs->view_center_pos.y = (F32)f64_from_str8(bitmap_cfg->first->next->string); + bvs->zoom = (F32)f64_from_str8(zoom_cfg->first->string); + bvs->top = df_vr_bitmap_topology_info_from_cfg(dbgi_scope, &ctrl_ctx, &parse_ctx, &eval_string2expr_map_nil, bitmap_cfg); + if(bvs->zoom == 0) + { + bvs->zoom = 1.f; + } + dbgi_scope_close(dbgi_scope); +} + +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(bitmap) +{ + DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState); + String8 result = push_str8f(arena, "view_center:(%.2f %.2f) zoom:(%.2f) bitmap:(w:%I64u, h:%I64u, fmt:%S)", + bvs->view_center_pos.x, + bvs->view_center_pos.y, + bvs->zoom, + bvs->top.width, + bvs->top.height, + r_tex2d_format_display_string_table[bvs->top.fmt]); + return result; +} + +DF_VIEW_CMD_FUNCTION_DEF(bitmap) +{ +} + +internal UI_BOX_CUSTOM_DRAW(df_bitmap_view_canvas_box_draw) +{ + DF_BitmapViewState *bvs = (DF_BitmapViewState *)user_data; + Rng2F32 rect_scrn = box->rect; + Rng2F32 rect_cvs = df_bitmap_view_state__canvas_from_screen_rect(bvs, rect_scrn, rect_scrn); + F32 grid_cell_size_cvs = box->font_size*10.f; + F32 grid_line_thickness_px = Max(2.f, box->font_size*0.1f); + Vec4F32 grid_line_color = df_rgba_from_theme_color(DF_ThemeColor_WeakText); + for(EachEnumVal(Axis2, axis)) + { + for(F32 v = rect_cvs.p0.v[axis] - mod_f32(rect_cvs.p0.v[axis], grid_cell_size_cvs); + v < rect_cvs.p1.v[axis]; + v += grid_cell_size_cvs) + { + Vec2F32 p_cvs = {0}; + p_cvs.v[axis] = v; + Vec2F32 p_scr = df_bitmap_view_state__screen_from_canvas_pos(bvs, rect_scrn, p_cvs); + Rng2F32 rect = {0}; + rect.p0.v[axis] = p_scr.v[axis] - grid_line_thickness_px/2; + rect.p1.v[axis] = p_scr.v[axis] + grid_line_thickness_px/2; + rect.p0.v[axis2_flip(axis)] = box->rect.p0.v[axis2_flip(axis)]; + rect.p1.v[axis2_flip(axis)] = box->rect.p1.v[axis2_flip(axis)]; + d_rect(rect, grid_line_color, 0, 0, 1.f); + } + } +} + +DF_VIEW_UI_FUNCTION_DEF(bitmap) +{ + DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState); + Temp scratch = scratch_begin(0, 0); + DBGI_Scope *dbgi_scope = dbgi_scope_open(); + HS_Scope *hs_scope = hs_scope_open(); + TEX_Scope *tex_scope = tex_scope_open(); + ////////////////////////////// + //- rjf: unpack context + // + DF_CtrlCtx ctrl_ctx = df_ctrl_ctx_from_view(ws, view); + DF_Entity *thread = df_entity_from_handle(ctrl_ctx.thread); + DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); + U64 thread_unwind_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx.unwind_count); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(dbgi_scope, process, thread_unwind_rip_vaddr); + + ////////////////////////////// + //- rjf: evaluate expression + // + String8 expr = str8(view->query_buffer, view->query_string_size); + DF_Eval eval = df_eval_from_string(scratch.arena, dbgi_scope, &ctrl_ctx, &parse_ctx, &eval_string2expr_map_nil, expr); + DF_Eval value_eval = df_value_mode_eval_from_eval(parse_ctx.type_graph, parse_ctx.rdi, &ctrl_ctx, eval); + U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; + U64 expected_size = bvs->top.width*bvs->top.height*r_tex2d_format_bytes_per_pixel_table[bvs->top.fmt]; + Rng1U64 vaddr_range = r1u64(base_vaddr, base_vaddr+expected_size); + + ////////////////////////////// + //- rjf: map expression artifacts -> texture + // + U128 texture_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 0); + TEX_Topology topology = tex_topology_make(v2s32((S32)bvs->top.width, (S32)bvs->top.height), bvs->top.fmt); + R_Handle texture = tex_texture_from_key_topology(tex_scope, texture_key, topology); + + ////////////////////////////// + //- rjf: build canvas box + // + UI_Box *canvas_box = &ui_g_nil_box; + Vec2F32 canvas_dim = dim_2f32(rect); + Rng2F32 canvas_rect = r2f32p(0, 0, canvas_dim.x, canvas_dim.y); + UI_Rect(canvas_rect) + { + canvas_box = ui_build_box_from_stringf(UI_BoxFlag_Clip|UI_BoxFlag_Clickable|UI_BoxFlag_Scroll, "bmp_canvas_%p", view); + ui_box_equip_custom_draw(canvas_box, df_bitmap_view_canvas_box_draw, bvs); + } + + ////////////////////////////// + //- rjf: canvas box interaction + // + { + UI_Signal canvas_sig = ui_signal_from_box(canvas_box); + if(ui_dragging(canvas_sig)) + { + if(ui_pressed(canvas_sig)) + { + DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FocusPanel)); + ui_store_drag_struct(&bvs->view_center_pos); + } + Vec2F32 start_view_center_pos = *ui_get_drag_struct(Vec2F32); + Vec2F32 drag_delta_scr = ui_drag_delta(); + Vec2F32 drag_delta_cvs = scale_2f32(drag_delta_scr, 1.f/bvs->zoom); + Vec2F32 new_view_center_pos = sub_2f32(start_view_center_pos, drag_delta_cvs); + bvs->view_center_pos = new_view_center_pos; + } + if(canvas_sig.scroll.y != 0) + { + F32 new_zoom = bvs->zoom - bvs->zoom*canvas_sig.scroll.y/10.f; + new_zoom = Clamp(1.f/256.f, new_zoom, 256.f); + Vec2F32 mouse_scr_pre = sub_2f32(ui_mouse(), rect.p0); + Vec2F32 mouse_cvs = df_bitmap_view_state__canvas_from_screen_pos(bvs, canvas_rect, mouse_scr_pre); + bvs->zoom = new_zoom; + Vec2F32 mouse_scr_pst = df_bitmap_view_state__screen_from_canvas_pos(bvs, canvas_rect, mouse_cvs); + Vec2F32 drift_scr = sub_2f32(mouse_scr_pst, mouse_scr_pre); + bvs->view_center_pos = add_2f32(bvs->view_center_pos, scale_2f32(drift_scr, 1.f/new_zoom)); + } + if(ui_double_clicked(canvas_sig)) + { + ui_kill_action(); + MemoryZeroStruct(&bvs->view_center_pos); + bvs->zoom = 1.f; + } + } + + ////////////////////////////// + //- rjf: build image + // + UI_Parent(canvas_box) + { + Rng2F32 img_rect_cvs = r2f32p(-topology.dim.x/2, -topology.dim.y/2, +topology.dim.x/2, +topology.dim.y/2); + Rng2F32 img_rect_scr = df_bitmap_view_state__screen_from_canvas_rect(bvs, canvas_rect, img_rect_cvs); + UI_Rect(img_rect_scr) UI_Flags(UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawDropShadow|UI_BoxFlag_Floating) + { + ui_image(texture, R_Tex2DSampleKind_Nearest, r2f32p(0, 0, (F32)bvs->top.width, (F32)bvs->top.height), v4f32(1, 1, 1, 1), 0, str8_lit("bmp_image")); + } + } + + hs_scope_close(hs_scope); + tex_scope_close(tex_scope); + dbgi_scope_close(dbgi_scope); + scratch_end(scratch); } //////////////////////////////// //~ rjf: "geo" -typedef struct DF_ViewRuleHooks_GeoState DF_ViewRuleHooks_GeoState; -struct DF_ViewRuleHooks_GeoState +internal DF_GeoTopologyInfo +df_vr_geo_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg) { - B32 initialized; - U64 last_open_frame_idx; - F32 loaded_t; - F32 pitch; - F32 pitch_target; - F32 yaw; - F32 yaw_target; - F32 zoom; - F32 zoom_target; -}; + Temp scratch = scratch_begin(0, 0); + DF_GeoTopologyInfo result = {0}; + { + StringJoin join = {0}; + join.sep = str8_lit(" "); + DF_CfgNode *count_cfg = df_cfg_node_child_from_string(cfg, str8_lit("count"), 0); + DF_CfgNode *vertices_base_cfg = df_cfg_node_child_from_string(cfg, str8_lit("vertices_base"), 0); + DF_CfgNode *vertices_size_cfg = df_cfg_node_child_from_string(cfg, str8_lit("vertices_size"), 0); + String8List count_expr_strs = {0}; + String8List vertices_base_expr_strs = {0}; + String8List vertices_size_expr_strs = {0}; + for(DF_CfgNode *child = count_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &count_expr_strs, child->string); + } + for(DF_CfgNode *child = vertices_base_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &vertices_base_expr_strs, child->string); + } + for(DF_CfgNode *child = vertices_size_cfg->first; child != &df_g_nil_cfg_node; child = child->next) + { + str8_list_push(scratch.arena, &vertices_size_expr_strs, child->string); + } + String8 count_expr = str8_list_join(scratch.arena, &count_expr_strs, &join); + String8 vertices_base_expr = str8_list_join(scratch.arena, &vertices_base_expr_strs, &join); + String8 vertices_size_expr = str8_list_join(scratch.arena, &vertices_size_expr_strs, &join); + DF_Eval count_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, count_expr); + DF_Eval vertices_base_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, vertices_base_expr); + DF_Eval vertices_size_eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, parse_ctx, macro_map, vertices_size_expr); + DF_Eval count_val_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, count_eval); + DF_Eval vertices_base_val_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, vertices_base_eval); + DF_Eval vertices_size_val_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdi, ctrl_ctx, vertices_size_eval); + U64 vertices_base_vaddr = vertices_base_val_eval.imm_u64 ? vertices_base_val_eval.imm_u64 : vertices_base_val_eval.offset; + result.index_count = count_val_eval.imm_u64; + result.vertices_vaddr_range = r1u64(vertices_base_vaddr, vertices_base_vaddr+vertices_size_val_eval.imm_u64); + } + scratch_end(scratch); + return result; +} -typedef struct DF_ViewRuleHooks_GeoBoxDrawData DF_ViewRuleHooks_GeoBoxDrawData; -struct DF_ViewRuleHooks_GeoBoxDrawData +internal UI_BOX_CUSTOM_DRAW(df_vr_geo_box_draw) { - DF_ExpandKey key; - R_Handle vertex_buffer; - R_Handle index_buffer; - F32 loaded_t; -}; - -internal UI_BOX_CUSTOM_DRAW(df_view_rule_hooks__geo_box_draw) -{ - DF_ViewRuleHooks_GeoBoxDrawData *draw_data = (DF_ViewRuleHooks_GeoBoxDrawData *)user_data; - DF_ViewRuleHooks_GeoState *state = df_view_rule_block_user_state(draw_data->key, DF_ViewRuleHooks_GeoState); + DF_VR_GeoBoxDrawData *draw_data = (DF_VR_GeoBoxDrawData *)user_data; + DF_VR_GeoState *state = df_view_rule_block_user_state(draw_data->key, DF_VR_GeoState); Vec4F32 bg_color = box->background_color; // rjf: get clip @@ -1602,6 +1966,7 @@ DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(geo) { DF_EvalVizBlock *vb = df_eval_viz_block_begin(arena, DF_EvalVizBlockKind_Canvas, key, df_expand_key_make(df_hash_from_expand_key(key), 1), depth); vb->eval = eval; + vb->string = string; vb->cfg_table = *cfg_table; vb->visual_idx_range = r1u64(0, 16); vb->semantic_idx_range = r1u64(0, 1); @@ -1620,7 +1985,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo) { Temp scratch = scratch_begin(0, 0); GEO_Scope *geo_scope = geo_scope_open(); - DF_ViewRuleHooks_GeoState *state = df_view_rule_block_user_state(key, DF_ViewRuleHooks_GeoState); + DF_VR_GeoState *state = df_view_rule_block_user_state(key, DF_VR_GeoState); if(!state->initialized) { state->initialized = 1; @@ -1639,7 +2004,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo) U64 base_vaddr = value_eval.imm_u64 ? value_eval.imm_u64 : value_eval.offset; //- rjf: extract extra geo topology info from view rule - DF_GeoTopologyInfo top = df_view_rule_hooks__geo_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); + DF_GeoTopologyInfo top = df_vr_geo_topology_info_from_cfg(dbgi_scope, ctrl_ctx, parse_ctx, macro_map, cfg); Rng1U64 index_buffer_vaddr_range = r1u64(base_vaddr, base_vaddr+top.index_count*sizeof(U32)); Rng1U64 vertex_buffer_vaddr_range = top.vertices_vaddr_range; @@ -1687,12 +2052,12 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo) { df_gfx_request_frame(); } - DF_ViewRuleHooks_GeoBoxDrawData *draw_data = push_array(ui_build_arena(), DF_ViewRuleHooks_GeoBoxDrawData, 1); + DF_VR_GeoBoxDrawData *draw_data = push_array(ui_build_arena(), DF_VR_GeoBoxDrawData, 1); draw_data->key = key; draw_data->vertex_buffer = vertex_buffer; draw_data->index_buffer = index_buffer; draw_data->loaded_t = state->loaded_t; - ui_box_equip_custom_draw(box, df_view_rule_hooks__geo_box_draw, draw_data); + ui_box_equip_custom_draw(box, df_vr_geo_box_draw, draw_data); if(r_handle_match(r_handle_zero(), vertex_buffer)) { df_gfx_request_frame(); @@ -1712,3 +2077,10 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo) geo_scope_close(geo_scope); scratch_end(scratch); } + +DF_VIEW_SETUP_FUNCTION_DEF(geo) {} +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(geo) { return str8_lit(""); } +DF_VIEW_CMD_FUNCTION_DEF(geo) {} +DF_VIEW_UI_FUNCTION_DEF(geo) +{ +} diff --git a/src/df/gfx/df_view_rules.h b/src/df/gfx/df_view_rules.h new file mode 100644 index 00000000..d69435ca --- /dev/null +++ b/src/df/gfx/df_view_rules.h @@ -0,0 +1,144 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef DF_VIEW_RULES_H +#define DF_VIEW_RULES_H + +//////////////////////////////// +//~ rjf: "rgba" + +typedef struct DF_VR_RGBAState DF_VR_RGBAState; +struct DF_VR_RGBAState +{ + Vec4F32 hsva; + U64 memgen_idx; +}; + +internal Vec4F32 df_vr_rgba_from_eval(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_Entity *process); +internal void df_vr_eval_commit_rgba(DF_Eval eval, TG_Graph *graph, RDI_Parsed *raddbg, DF_CtrlCtx *ctrl_ctx, Vec4F32 rgba); + +//////////////////////////////// +//~ rjf: "text" + +typedef struct DF_TxtTopologyInfo DF_TxtTopologyInfo; +struct DF_TxtTopologyInfo +{ + TXT_LangKind lang; + U64 size_cap; +}; + +typedef struct DF_VR_TextState DF_VR_TextState; +struct DF_VR_TextState +{ + B32 initialized; + TxtPt cursor; + TxtPt mark; + S64 preferred_column; + U64 last_open_frame_idx; + F32 loaded_t; +}; + +internal DF_TxtTopologyInfo df_vr_txt_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); + +//////////////////////////////// +//~ rjf: "disasm" + +typedef struct DF_DisasmTopologyInfo DF_DisasmTopologyInfo; +struct DF_DisasmTopologyInfo +{ + Architecture arch; + U64 size_cap; +}; + +typedef struct DF_VR_DisasmState DF_VR_DisasmState; +struct DF_VR_DisasmState +{ + B32 initialized; + TxtPt cursor; + TxtPt mark; + S64 preferred_column; + U64 last_open_frame_idx; + F32 loaded_t; +}; + +internal DF_DisasmTopologyInfo df_vr_disasm_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); + +//////////////////////////////// +//~ rjf: "bitmap" + +typedef struct DF_BitmapTopologyInfo DF_BitmapTopologyInfo; +struct DF_BitmapTopologyInfo +{ + U64 width; + U64 height; + R_Tex2DFormat fmt; +}; + +typedef struct DF_BitmapViewState DF_BitmapViewState; +struct DF_BitmapViewState +{ + Vec2F32 view_center_pos; + F32 zoom; + DF_BitmapTopologyInfo top; +}; + +typedef struct DF_VR_BitmapState DF_VR_BitmapState; +struct DF_VR_BitmapState +{ + U64 last_open_frame_idx; + F32 loaded_t; +}; + +typedef struct DF_VR_BitmapBoxDrawData DF_VR_BitmapBoxDrawData; +struct DF_VR_BitmapBoxDrawData +{ + Rng2F32 src; + R_Handle texture; + F32 loaded_t; + B32 hovered; + Vec2S32 mouse_px; + F32 ui_per_bmp_px; +}; + +internal Vec2F32 df_bitmap_view_state__screen_from_canvas_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 cvs); +internal Rng2F32 df_bitmap_view_state__screen_from_canvas_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 cvs); +internal Vec2F32 df_bitmap_view_state__canvas_from_screen_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 scr); +internal Rng2F32 df_bitmap_view_state__canvas_from_screen_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 scr); +internal DF_BitmapTopologyInfo df_vr_bitmap_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); + +//////////////////////////////// +//~ rjf: "geo" + +typedef struct DF_GeoTopologyInfo DF_GeoTopologyInfo; +struct DF_GeoTopologyInfo +{ + U64 index_count; + Rng1U64 vertices_vaddr_range; +}; + +typedef struct DF_VR_GeoState DF_VR_GeoState; +struct DF_VR_GeoState +{ + B32 initialized; + U64 last_open_frame_idx; + F32 loaded_t; + F32 pitch; + F32 pitch_target; + F32 yaw; + F32 yaw_target; + F32 zoom; + F32 zoom_target; +}; + +typedef struct DF_VR_GeoBoxDrawData DF_VR_GeoBoxDrawData; +struct DF_VR_GeoBoxDrawData +{ + DF_ExpandKey key; + R_Handle vertex_buffer; + R_Handle index_buffer; + F32 loaded_t; +}; + +internal DF_GeoTopologyInfo df_vr_geo_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, EVAL_String2ExprMap *macro_map, DF_CfgNode *cfg); + +#endif // DF_VIEW_RULES_H diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index d963cc39..303a6f5b 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -997,7 +997,7 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW for(DF_EvalVizRow *row = rows.first; row != 0; row = row->next, semantic_idx += 1) { U64 row_hash = df_hash_from_expand_key(row->key); - U64 expr_hash = df_hash_from_string(row->expr); + U64 expr_hash = df_hash_from_string(row->display_expr); df_expand_tree_table_animate(&eval_view->expand_tree_table, df_dt()); B32 row_selected = ((semantic_idx+1) == cursor_tbl.y); B32 row_expanded = df_expand_key_is_set(&eval_view->expand_tree_table, row->key); @@ -1037,6 +1037,7 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW //- rjf: build canvas row if(row->flags & DF_EvalVizRowFlag_Canvas) UI_FocusHot(row_selected ? UI_FocusKind_On : UI_FocusKind_Off) ProfScope("canvas row") { + //- rjf: build ui_set_next_flags(disabled_flags); ui_set_next_pref_width(ui_pct(1, 0)); ui_set_next_pref_height(ui_px(scroll_list_params.row_height_px*row->size_in_rows, 1.f)); @@ -1053,22 +1054,40 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW { Vec2F32 canvas_dim = v2f32(scroll_list_params.dim_px.x - ui_top_font_size()*1.5f, (row->skipped_size_in_rows+row->size_in_rows+row->chopped_size_in_rows)*scroll_list_params.row_height_px); - row->expand_ui_rule_spec->info.block_ui(ws, row->key, row->eval, scope, &ctrl_ctx, &parse_ctx, ¯o_map, row->expand_ui_rule_node, canvas_dim); + row->expand_ui_rule_spec->info.block_ui(ws, row->key, row->eval, row->edit_expr, scope, &ctrl_ctx, &parse_ctx, ¯o_map, row->expand_ui_rule_node, canvas_dim); } } } + + //- rjf: take interaction UI_Signal sig = ui_signal_from_box(vector); + + //- rjf: press -> focus if(ui_pressed(sig)) { edit_commit = edit_commit || (!row_selected && ewv->input_editing); next_cursor_tbl = v2s64(DF_EvalWatchViewColumnKind_Expr, (semantic_idx+1)); pressed = 1; } - if(ui_double_clicked(sig)) + + //- rjf: double clicked or keyboard clicked -> open dedicated tab + if(ui_double_clicked(sig) || sig.f & UI_SignalFlag_KeyboardPressed) { + DF_CfgNode *cfg = df_cfg_tree_copy(scratch.arena, row->expand_ui_rule_node); + DF_CfgNode *cfg_root = push_array(scratch.arena, DF_CfgNode, 1); + cfg_root->first = cfg_root->last = cfg; + cfg_root->next = cfg_root->parent = &df_g_nil_cfg_node; + if(cfg != &df_g_nil_cfg_node) + { + cfg->parent = cfg_root; + } DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); - p.view_spec = df_view_spec_from_gfx_view_kind(DF_GfxViewKind_EvalViewer); + p.string = row->edit_expr; + p.view_spec = df_tab_view_spec_from_gfx_view_rule_spec(row->expand_ui_rule_spec); + p.cfg_node = cfg_root; + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_String); df_cmd_params_mark_slot(&p, DF_CmdParamSlot_ViewSpec); + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_CfgNode); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OpenTab)); } } @@ -1130,8 +1149,8 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW if(cell_selected && (edit_begin || (edit_begin_or_expand && !(row->flags & DF_EvalVizRowFlag_CanExpand))) && can_edit_expr) { ewv->input_editing = 1; - ewv->input_size = Min(sizeof(ewv->input_buffer), row->expr.size); - MemoryCopy(ewv->input_buffer, row->expr.str, ewv->input_size); + ewv->input_size = Min(sizeof(ewv->input_buffer), row->display_expr.size); + MemoryCopy(ewv->input_buffer, row->display_expr.str, ewv->input_size); ewv->input_cursor = txt_pt(1, 1+ewv->input_size); ewv->input_mark = txt_pt(1, 1); } @@ -1163,7 +1182,7 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW FuzzyMatchRangeList matches = {0}; if(filter.size != 0) { - matches = fuzzy_match_find(scratch.arena, filter, row->expr); + matches = fuzzy_match_find(scratch.arena, filter, row->display_expr); } sig = df_line_editf((DF_LineEditFlag_CodeContents*(!(row->flags & DF_EvalVizRowFlag_ExprIsSpecial))| DF_LineEditFlag_NoBackground*(!is_inherited)| @@ -1174,7 +1193,7 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW row->depth, filter.size ? &matches : 0, &ewv->input_cursor, &ewv->input_mark, ewv->input_buffer, sizeof(ewv->input_buffer), &ewv->input_size, &next_expanded, - row->expr, + row->display_expr, "###row_%I64x", row_hash); } edit_commit = edit_commit || ui_committed(sig); @@ -1206,7 +1225,7 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW if(DEV_eval_compiler_tooltips && row->depth == 0 && ui_hovering(sig)) UI_Tooltip { Temp scratch = scratch_begin(0, 0); - String8 string = row->expr; + String8 string = row->display_expr; // rjf: lex & parse EVAL_TokenArray tokens = eval_token_array_from_text(scratch.arena, string); @@ -1270,8 +1289,8 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW { ui_kill_action(); ewv->input_editing = 1; - ewv->input_size = Min(sizeof(ewv->input_buffer), row->expr.size); - MemoryCopy(ewv->input_buffer, row->expr.str, ewv->input_size); + ewv->input_size = Min(sizeof(ewv->input_buffer), row->display_expr.size); + MemoryCopy(ewv->input_buffer, row->display_expr.str, ewv->input_size); ewv->input_cursor = txt_pt(1, 1+ewv->input_size); ewv->input_mark = txt_pt(1, 1); } @@ -2136,7 +2155,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem) if(query_normalized_with_opt_slash_props.flags & FilePropertyFlag_IsFolder) { String8 new_path = push_str8f(scratch.arena, "%S%S/", path_query.path, path_query.search); - df_view_equip_spec(view, view->spec, df_entity_from_handle(view->entity), new_path, &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, view->spec, df_entity_from_handle(view->entity), new_path, &df_g_nil_cfg_node); } // rjf: is a file -> complete view @@ -2166,7 +2185,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem) { String8 existing_path = str8_chop_last_slash(path_query.path); String8 new_path = push_str8f(scratch.arena, "%S/%S/", existing_path, files[0].filename); - df_view_equip_spec(view, view->spec, df_entity_from_handle(view->entity), new_path, &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, view->spec, df_entity_from_handle(view->entity), new_path, &df_g_nil_cfg_node); } else { @@ -2298,7 +2317,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem) { new_path = path_normalized_from_string(scratch.arena, new_path); String8 new_cmd = push_str8f(scratch.arena, "%S/", new_path); - df_view_equip_spec(view, view->spec, df_entity_from_handle(view->entity), new_cmd, &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, view->spec, df_entity_from_handle(view->entity), new_cmd, &df_g_nil_cfg_node); } } } @@ -2381,7 +2400,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem) if(file->props.flags & FilePropertyFlag_IsFolder) { String8 new_cmd = push_str8f(scratch.arena, "%S/", new_path); - df_view_equip_spec(view, view->spec, df_entity_from_handle(view->entity), new_cmd, &df_g_nil_cfg_node); + df_view_equip_spec(ws, view, view->spec, df_entity_from_handle(view->entity), new_cmd, &df_g_nil_cfg_node); } else { @@ -3435,7 +3454,7 @@ DF_VIEW_UI_FUNCTION_DEF(FilePathMap) B32 edit_end = 0; B32 edit_commit = 0; B32 edit_submit = 0; - if(ui_is_focus_active()) + UI_Focus(UI_FocusKind_On) if(ui_is_focus_active()) { if(!fpms->input_editing) { @@ -3699,6 +3718,296 @@ DF_VIEW_UI_FUNCTION_DEF(FilePathMap) ProfEnd(); } +//////////////////////////////// +//~ rjf: AutoViewRules @view_hook_impl + +DF_VIEW_SETUP_FUNCTION_DEF(AutoViewRules) +{ + DF_AutoViewRulesViewState *avrs = df_view_user_state(view, DF_AutoViewRulesViewState); + if(avrs->initialized == 0) + { + avrs->initialized = 1; + avrs->src_column_pct = 0.5f; + avrs->dst_column_pct = 0.5f; + } +} + +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(AutoViewRules) +{ + DF_AutoViewRulesViewState *avrs = df_view_user_state(view, DF_AutoViewRulesViewState); + return str8_lit(""); +} + +DF_VIEW_CMD_FUNCTION_DEF(AutoViewRules) +{ + DF_AutoViewRulesViewState *avrs = df_view_user_state(view, DF_AutoViewRulesViewState); + + // rjf: process commands + for(DF_CmdNode *n = cmds->first; n != 0; n = n->next) + { + DF_Cmd *cmd = &n->cmd; + + // rjf: mismatched window/panel => skip + if(df_window_from_handle(cmd->params.window) != ws || + df_panel_from_handle(cmd->params.panel) != panel) + { + continue; + } + } +} + +DF_VIEW_UI_FUNCTION_DEF(AutoViewRules) +{ + ProfBeginFunction(); + Temp scratch = scratch_begin(0, 0); + DF_EntityList maps_list = df_query_cached_entity_list_with_kind(DF_EntityKind_AutoViewRule); + DF_EntityArray maps = df_entity_array_from_list(scratch.arena, &maps_list); + F32 row_height_px = floor_f32(ui_top_font_size()*2.5f); + + //- rjf: grab state + DF_AutoViewRulesViewState *avrs = df_view_user_state(view, DF_AutoViewRulesViewState); + + //- rjf: take controls to start/end editing + B32 edit_begin = 0; + B32 edit_end = 0; + B32 edit_commit = 0; + B32 edit_submit = 0; + UI_Focus(UI_FocusKind_On) if(ui_is_focus_active()) + { + if(!avrs->input_editing) + { + UI_NavActionList *nav_actions = ui_nav_actions(); + for(UI_NavActionNode *n = nav_actions->first; n != 0; n = n->next) + { + if(n->v.insertion.size != 0 || n->v.flags & UI_NavActionFlag_Paste) + { + edit_begin = 1; + break; + } + } + if(os_key_press(ui_events(), ui_window(), 0, OS_Key_F2)) + { + edit_begin = 1; + } + } + if(avrs->input_editing) + { + if(os_key_press(ui_events(), ui_window(), 0, OS_Key_Esc)) + { + edit_end = 1; + edit_commit = 0; + } + if(os_key_press(ui_events(), ui_window(), 0, OS_Key_Return)) + { + edit_end = 1; + edit_commit = 1; + edit_submit = 1; + } + } + } + + //- rjf: build + DF_Handle commit_map = df_handle_zero(); + Side commit_side = Side_Invalid; + F32 *col_pcts[] = { &avrs->src_column_pct, &avrs->dst_column_pct }; + Vec2S64 next_cursor = avrs->cursor; + Rng1S64 visible_row_range = {0}; + UI_ScrollListParams scroll_list_params = {0}; + { + scroll_list_params.flags = UI_ScrollListFlag_All; + scroll_list_params.row_height_px = row_height_px; + scroll_list_params.dim_px = dim_2f32(rect); + scroll_list_params.cursor_range = r2s64(v2s64(0, 0), v2s64(1, maps.count + 1)); + scroll_list_params.item_range = r1s64(0, maps.count+2); + scroll_list_params.cursor_min_is_empty_selection[Axis2_Y] = 1; + } + UI_ScrollListSignal scroll_list_sig = {0}; + UI_Focus(UI_FocusKind_On) + UI_ScrollList(&scroll_list_params, &view->scroll_pos.y, avrs->input_editing ? 0 : &avrs->cursor, &visible_row_range, &scroll_list_sig) + UI_Focus(UI_FocusKind_Null) + UI_TableF(ArrayCount(col_pcts), col_pcts, "###tbl") + { + next_cursor = avrs->cursor; + + //- rjf: header + if(visible_row_range.min == 0) UI_TableVector UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText)) + { + UI_TableCell ui_label(str8_lit("Type")); + UI_TableCell ui_label(str8_lit("View Rule")); + } + + //- rjf: map rows + for(S64 row_idx = Max(1, visible_row_range.min); + row_idx <= visible_row_range.max && row_idx <= maps.count+1; + row_idx += 1) UI_TableVector + { + U64 map_idx = row_idx-1; + DF_Entity *map = (map_idx < maps.count ? maps.v[map_idx] : &df_g_nil_entity); + DF_Entity *source = df_entity_child_from_kind(map, DF_EntityKind_Source); + DF_Entity *dest = df_entity_child_from_kind(map, DF_EntityKind_Dest); + String8 type = source->name; + String8 view_rule = dest->name; + B32 row_selected = (avrs->cursor.y == row_idx); + + //- rjf: type + UI_TableCell UI_WidthFill + { + //- rjf: editor + { + B32 value_selected = (row_selected && avrs->cursor.x == 0); + + // rjf: begin editing + if(value_selected && edit_begin) + { + avrs->input_editing = 1; + avrs->input_size = Min(sizeof(avrs->input_buffer), type.size); + MemoryCopy(avrs->input_buffer, type.str, avrs->input_size); + avrs->input_cursor = txt_pt(1, 1+avrs->input_size); + avrs->input_mark = txt_pt(1, 1); + } + + // rjf: build + UI_Signal sig = {0}; + UI_FocusHot(value_selected ? UI_FocusKind_On : UI_FocusKind_Off) + UI_FocusActive((value_selected && avrs->input_editing) ? UI_FocusKind_On : UI_FocusKind_Off) + UI_Font(df_font_from_slot(DF_FontSlot_Code)) + { + sig = df_line_editf(DF_LineEditFlag_CodeContents|DF_LineEditFlag_NoBackground|DF_LineEditFlag_DisplayStringIsCode, 0, 0, &avrs->input_cursor, &avrs->input_mark, avrs->input_buffer, sizeof(avrs->input_buffer), &avrs->input_size, 0, type, "###src_editor_%p", map); + edit_commit = edit_commit || ui_committed(sig); + } + + // rjf: focus panel on press + if(ui_pressed(sig)) + { + DF_CmdParams p = df_cmd_params_from_panel(ws, panel); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FocusPanel)); + } + + // rjf: begin editing on double-click + if(!avrs->input_editing && ui_double_clicked(sig)) + { + avrs->input_editing = 1; + avrs->input_size = Min(sizeof(avrs->input_buffer), type.size); + MemoryCopy(avrs->input_buffer, type.str, avrs->input_size); + avrs->input_cursor = txt_pt(1, 1+avrs->input_size); + avrs->input_mark = txt_pt(1, 1); + } + + // rjf: press on non-selected => commit edit, change selected cell + if(ui_pressed(sig) && !value_selected) + { + edit_end = 1; + edit_commit = avrs->input_editing; + next_cursor.x = 0; + next_cursor.y = map_idx+1; + } + + // rjf: store commit information + if(value_selected) + { + commit_side = Side_Min; + commit_map = df_handle_from_entity(map); + } + } + } + + //- rjf: dst + UI_TableCell UI_WidthFill + { + //- rjf: editor + { + B32 value_selected = (row_selected && avrs->cursor.x == 1); + + // rjf: begin editing + if(value_selected && edit_begin) + { + avrs->input_editing = 1; + avrs->input_size = Min(sizeof(avrs->input_buffer), view_rule.size); + MemoryCopy(avrs->input_buffer, view_rule.str, avrs->input_size); + avrs->input_cursor = txt_pt(1, 1+avrs->input_size); + avrs->input_mark = txt_pt(1, 1); + } + + // rjf: build + UI_Signal sig = {0}; + UI_FocusHot(value_selected ? UI_FocusKind_On : UI_FocusKind_Off) + UI_FocusActive((value_selected && avrs->input_editing) ? UI_FocusKind_On : UI_FocusKind_Off) + UI_Font(df_font_from_slot(DF_FontSlot_Code)) + { + sig = df_line_editf(DF_LineEditFlag_CodeContents|DF_LineEditFlag_NoBackground|DF_LineEditFlag_DisplayStringIsCode, 0, 0, &avrs->input_cursor, &avrs->input_mark, avrs->input_buffer, sizeof(avrs->input_buffer), &avrs->input_size, 0, view_rule, "###dst_editor_%p", map); + edit_commit = edit_commit || ui_committed(sig); + } + + // rjf: focus panel on press + if(ui_pressed(sig)) + { + DF_CmdParams p = df_cmd_params_from_panel(ws, panel); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FocusPanel)); + } + + // rjf: begin editing on double-click + if(!avrs->input_editing && ui_double_clicked(sig)) + { + avrs->input_editing = 1; + avrs->input_size = Min(sizeof(avrs->input_buffer), view_rule.size); + MemoryCopy(avrs->input_buffer, view_rule.str, avrs->input_size); + avrs->input_cursor = txt_pt(1, 1+avrs->input_size); + avrs->input_mark = txt_pt(1, 1); + } + + // rjf: press on non-selected => commit edit, change selected cell + if(ui_pressed(sig) && !value_selected) + { + edit_end = 1; + edit_commit = avrs->input_editing; + next_cursor.x = 1; + next_cursor.y = map_idx+1; + } + + // rjf: store commit information + if(value_selected) + { + commit_side = Side_Max; + commit_map = df_handle_from_entity(map); + } + } + } + } + } + + //- rjf: apply commit + if(edit_commit && commit_side != Side_Invalid) + { + String8 new_string = str8(avrs->input_buffer, avrs->input_size); + DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); + p.entity = commit_map; + p.string = new_string; + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_Entity); + df_cmd_params_mark_slot(&p, DF_CmdParamSlot_FilePath); + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(commit_side == Side_Min ? + DF_CoreCmdKind_SetAutoViewRuleType : + DF_CoreCmdKind_SetAutoViewRuleViewRule)); + } + + //- rjf: apply editing finish + if(edit_end) + { + avrs->input_editing = 0; + } + + //- rjf: move down one row if submitted + if(edit_submit) + { + next_cursor.y += 1; + } + + //- rjf: apply moves to selection + avrs->cursor = next_cursor; + + scratch_end(scratch); + ProfEnd(); +} + //////////////////////////////// //~ rjf: Scheduler @view_hook_impl @@ -4593,7 +4902,7 @@ DF_VIEW_CMD_FUNCTION_DEF(PendingEntity) { view_spec = df_view_spec_from_gfx_view_kind(viewer_kind); } - df_view_equip_spec(view, view_spec, entity, str8_lit(""), cfg_root); + df_view_equip_spec(ws, view, view_spec, entity, str8_lit(""), cfg_root); df_panel_notify_mutation(ws, panel); } @@ -5729,7 +6038,7 @@ DF_VIEW_SETUP_FUNCTION_DEF(Disassembly) dv->mark = txt_pt(1, 1); dv->preferred_column = 1; dv->find_text_arena = df_view_push_arena_ext(view); - dv->style_flags = DASM_StyleFlag_Addresses; + dv->style_flags = DASM_StyleFlag_Addresses|DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines|DASM_StyleFlag_SymbolNames; } } @@ -5752,10 +6061,21 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly) DF_Entity *process = df_entity_from_handle(dv->process); Architecture arch = df_architecture_from_entity(process); U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(64)); + DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr); + DF_Entity *dasm_binary = df_binary_file_from_module(dasm_module); Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(64)); U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0); U128 dasm_data_hash = {0}; - DASM_Info dasm_info = dasm_info_from_key_addr_arch_style(dasm_scope, dasm_key, dasm_vaddr_range.min, arch, dv->style_flags, DASM_Syntax_Intel, &dasm_data_hash); + DASM_Params dasm_params = {0}; + { + dasm_params.vaddr = dasm_vaddr_range.min; + dasm_params.arch = arch; + dasm_params.style_flags = dv->style_flags; + dasm_params.syntax = DASM_Syntax_Intel; + dasm_params.base_vaddr = dasm_module->vaddr_rng.min; + dasm_params.exe_path = df_full_path_from_entity(scratch.arena, dasm_binary); + } + DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash); U128 dasm_text_hash = {0}; TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(txt_scope, dasm_info.text_key, txt_lang_kind_from_architecture(arch), &dasm_text_hash); String8 dasm_text_data = hs_data_from_hash(hs_scope, dasm_text_hash); @@ -5995,10 +6315,21 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) DF_Entity *process = df_entity_from_handle(dv->process); Architecture arch = df_architecture_from_entity(process); U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(64)); + DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr); + DF_Entity *dasm_binary = df_binary_file_from_module(dasm_module); Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(64)); U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0); U128 dasm_data_hash = {0}; - DASM_Info dasm_info = dasm_info_from_key_addr_arch_style(dasm_scope, dasm_key, dasm_vaddr_range.min, arch, dv->style_flags, DASM_Syntax_Intel, &dasm_data_hash); + DASM_Params dasm_params = {0}; + { + dasm_params.vaddr = dasm_vaddr_range.min; + dasm_params.arch = arch; + dasm_params.style_flags = dv->style_flags; + dasm_params.syntax = DASM_Syntax_Intel; + dasm_params.base_vaddr = dasm_module->vaddr_rng.min; + dasm_params.exe_path = df_full_path_from_entity(scratch.arena, dasm_binary); + } + DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash); U128 dasm_text_hash = {0}; TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(txt_scope, dasm_info.text_key, txt_lang_kind_from_architecture(arch), &dasm_text_hash); String8 dasm_text_data = hs_data_from_hash(hs_scope, dasm_text_hash); @@ -6538,16 +6869,6 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) ProfEnd(); } -//////////////////////////////// -//~ rjf: EvalViewer @view_hook_impl - -DF_VIEW_SETUP_FUNCTION_DEF(EvalViewer) {} -DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(EvalViewer) { return str8_lit(""); } -DF_VIEW_CMD_FUNCTION_DEF(EvalViewer) {} -DF_VIEW_UI_FUNCTION_DEF(EvalViewer) -{ -} - //////////////////////////////// //~ rjf: Watch @view_hook_impl diff --git a/src/df/gfx/df_views.h b/src/df/gfx/df_views.h index ebccf953..fabaa30b 100644 --- a/src/df/gfx/df_views.h +++ b/src/df/gfx/df_views.h @@ -230,6 +230,23 @@ struct DF_FilePathMapViewState F32 dst_column_pct; }; +//////////////////////////////// +//~ rjf: AutoViewRules @view_types + +typedef struct DF_AutoViewRulesViewState DF_AutoViewRulesViewState; +struct DF_AutoViewRulesViewState +{ + B32 initialized; + Vec2S64 cursor; + TxtPt input_cursor; + TxtPt input_mark; + U8 input_buffer[1024]; + U64 input_size; + B32 input_editing; + F32 src_column_pct; + F32 dst_column_pct; +}; + //////////////////////////////// //~ rjf: Modules @view_types diff --git a/src/df/gfx/generated/df_gfx.meta.c b/src/df/gfx/generated/df_gfx.meta.c index 4bb7504a..b5bfe355 100644 --- a/src/df/gfx/generated/df_gfx.meta.c +++ b/src/df/gfx/generated/df_gfx.meta.c @@ -713,24 +713,30 @@ str8_lit_comp("open_user"), str8_lit_comp("open_profile"), }; -DF_GfxViewRuleSpecInfo df_g_gfx_view_rule_spec_info_table[16] = +DF_GfxViewRuleSpecInfo df_g_gfx_view_rule_spec_info_table[14] = { -{ str8_lit_comp("array"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, 0, 0, 0, 0 }, -{ str8_lit_comp("slice"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, 0, 0, 0, 0 }, -{ str8_lit_comp("list"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(list) , 0, 0, 0, 0 }, -{ str8_lit_comp("dec"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(dec) , 0, 0, 0 }, -{ str8_lit_comp("bin"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(bin) , 0, 0, 0 }, -{ str8_lit_comp("oct"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(oct) , 0, 0, 0 }, -{ str8_lit_comp("hex"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(hex) , 0, 0, 0 }, -{ str8_lit_comp("only"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(only) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(only) , 0, 0, 0 }, -{ str8_lit_comp("omit"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(omit) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(omit) , 0, 0, 0 }, -{ str8_lit_comp("no_addr"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(no_addr) , 0, 0, 0 }, -{ str8_lit_comp("rgba"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(rgba) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(rgba) , 0 }, -{ str8_lit_comp("text"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(text) , 0 }, -{ str8_lit_comp("disasm"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(disasm) , 0 }, -{ str8_lit_comp("bitmap"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(bitmap) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(bitmap) , DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_NAME(bitmap) }, -{ str8_lit_comp("odin_map"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(odin_map) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(odin_map) , DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_NAME(odin_map) }, -{ str8_lit_comp("geo"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(geo) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(geo) , 0 }, +{ str8_lit_comp("array"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, 0, 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("list"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(list) , 0, 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("dec"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(dec) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("bin"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(bin) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("oct"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(oct) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("hex"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(hex) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("only"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(only) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(only) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("omit"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(omit) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(omit) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("no_addr"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(no_addr) , 0, 0, str8_lit_comp("") }, +{ str8_lit_comp("rgba"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(rgba) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(rgba) , str8_lit_comp("") }, +{ str8_lit_comp("text"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(text) , str8_lit_comp("text_view_rule") }, +{ str8_lit_comp("disasm"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(disasm) , str8_lit_comp("disasm_view_rule") }, +{ str8_lit_comp("bitmap"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(bitmap) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(bitmap) , str8_lit_comp("bitmap_view_rule") }, +{ str8_lit_comp("geo"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(geo) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(geo) , str8_lit_comp("geo_view_rule") }, +}; + +DF_ViewSpecInfo df_g_gfx_view_rule_tab_view_spec_info_table[4] = +{ +{ DF_ViewSpecFlag_CanSerialize|DF_ViewSpecFlag_CanSerializeQuery, str8_lit_comp("text_view_rule"), str8_lit_comp("Text"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(text), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(text), DF_VIEW_CMD_FUNCTION_NAME(text), DF_VIEW_UI_FUNCTION_NAME(text) }, +{ DF_ViewSpecFlag_CanSerialize|DF_ViewSpecFlag_CanSerializeQuery, str8_lit_comp("disasm_view_rule"), str8_lit_comp("Disassembly"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(disasm), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(disasm), DF_VIEW_CMD_FUNCTION_NAME(disasm), DF_VIEW_UI_FUNCTION_NAME(disasm) }, +{ DF_ViewSpecFlag_CanSerialize|DF_ViewSpecFlag_CanSerializeQuery, str8_lit_comp("bitmap_view_rule"), str8_lit_comp("Bitmap"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(bitmap), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(bitmap), DF_VIEW_CMD_FUNCTION_NAME(bitmap), DF_VIEW_UI_FUNCTION_NAME(bitmap) }, +{ DF_ViewSpecFlag_CanSerialize|DF_ViewSpecFlag_CanSerializeQuery, str8_lit_comp("geo_view_rule"), str8_lit_comp("Geometry"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(geo), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(geo), DF_VIEW_CMD_FUNCTION_NAME(geo), DF_VIEW_UI_FUNCTION_NAME(geo) }, }; DF_ViewSpecInfo df_g_gfx_view_kind_spec_info_table[30] = @@ -740,18 +746,18 @@ DF_ViewSpecInfo df_g_gfx_view_kind_spec_info_table[30] = {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("commands"), str8_lit_comp("Commands"), DF_NameKind_Null, DF_IconKind_List, DF_VIEW_SETUP_FUNCTION_NAME(Commands), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Commands), DF_VIEW_CMD_FUNCTION_NAME(Commands), DF_VIEW_UI_FUNCTION_NAME(Commands)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("file_system"), str8_lit_comp("File System"), DF_NameKind_Null, DF_IconKind_FileOutline, DF_VIEW_SETUP_FUNCTION_NAME(FileSystem), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(FileSystem), DF_VIEW_CMD_FUNCTION_NAME(FileSystem), DF_VIEW_UI_FUNCTION_NAME(FileSystem)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("system_processes"), str8_lit_comp("System Processes"), DF_NameKind_Null, DF_IconKind_Null, DF_VIEW_SETUP_FUNCTION_NAME(SystemProcesses), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(SystemProcesses), DF_VIEW_CMD_FUNCTION_NAME(SystemProcesses), DF_VIEW_UI_FUNCTION_NAME(SystemProcesses)}, -{(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("entity_lister"), str8_lit_comp("Entity List"), DF_NameKind_EntityKindName, DF_IconKind_Null, DF_VIEW_SETUP_FUNCTION_NAME(EntityLister), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(EntityLister), DF_VIEW_CMD_FUNCTION_NAME(EntityLister), DF_VIEW_UI_FUNCTION_NAME(EntityLister)}, +{(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("entity_lister"), str8_lit_comp("Entity List"), DF_NameKind_Null, DF_IconKind_Null, DF_VIEW_SETUP_FUNCTION_NAME(EntityLister), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(EntityLister), DF_VIEW_CMD_FUNCTION_NAME(EntityLister), DF_VIEW_UI_FUNCTION_NAME(EntityLister)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("symbol_lister"), str8_lit_comp("Symbols"), DF_NameKind_Null, DF_IconKind_Null, DF_VIEW_SETUP_FUNCTION_NAME(SymbolLister), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(SymbolLister), DF_VIEW_CMD_FUNCTION_NAME(SymbolLister), DF_VIEW_UI_FUNCTION_NAME(SymbolLister)}, {(0|1*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("target"), str8_lit_comp("Target"), DF_NameKind_EntityName, DF_IconKind_Target, DF_VIEW_SETUP_FUNCTION_NAME(Target), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Target), DF_VIEW_CMD_FUNCTION_NAME(Target), DF_VIEW_UI_FUNCTION_NAME(Target)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("targets"), str8_lit_comp("Targets"), DF_NameKind_Null, DF_IconKind_Target, DF_VIEW_SETUP_FUNCTION_NAME(Targets), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Targets), DF_VIEW_CMD_FUNCTION_NAME(Targets), DF_VIEW_UI_FUNCTION_NAME(Targets)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("file_path_map"), str8_lit_comp("File Path Map"), DF_NameKind_Null, DF_IconKind_FileOutline, DF_VIEW_SETUP_FUNCTION_NAME(FilePathMap), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(FilePathMap), DF_VIEW_CMD_FUNCTION_NAME(FilePathMap), DF_VIEW_UI_FUNCTION_NAME(FilePathMap)}, +{(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("auto_view_rules"), str8_lit_comp("Auto View Rules"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(AutoViewRules), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(AutoViewRules), DF_VIEW_CMD_FUNCTION_NAME(AutoViewRules), DF_VIEW_UI_FUNCTION_NAME(AutoViewRules)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|1*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("scheduler"), str8_lit_comp("Scheduler"), DF_NameKind_Null, DF_IconKind_Scheduler, DF_VIEW_SETUP_FUNCTION_NAME(Scheduler), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Scheduler), DF_VIEW_CMD_FUNCTION_NAME(Scheduler), DF_VIEW_UI_FUNCTION_NAME(Scheduler)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("call_stack"), str8_lit_comp("Call Stack"), DF_NameKind_Null, DF_IconKind_Thread, DF_VIEW_SETUP_FUNCTION_NAME(CallStack), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(CallStack), DF_VIEW_CMD_FUNCTION_NAME(CallStack), DF_VIEW_UI_FUNCTION_NAME(CallStack)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("modules"), str8_lit_comp("Modules"), DF_NameKind_Null, DF_IconKind_Module, DF_VIEW_SETUP_FUNCTION_NAME(Modules), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Modules), DF_VIEW_CMD_FUNCTION_NAME(Modules), DF_VIEW_UI_FUNCTION_NAME(Modules)}, {(0|1*DF_ViewSpecFlag_ParameterizedByEntity|0*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("pending_entity"), str8_lit_comp("Pending Entity"), DF_NameKind_EntityName, DF_IconKind_FileOutline, DF_VIEW_SETUP_FUNCTION_NAME(PendingEntity), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(PendingEntity), DF_VIEW_CMD_FUNCTION_NAME(PendingEntity), DF_VIEW_UI_FUNCTION_NAME(PendingEntity)}, {(0|1*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|1*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("code"), str8_lit_comp("Code"), DF_NameKind_EntityName, DF_IconKind_FileOutline, DF_VIEW_SETUP_FUNCTION_NAME(Code), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Code), DF_VIEW_CMD_FUNCTION_NAME(Code), DF_VIEW_UI_FUNCTION_NAME(Code)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("disassembly"), str8_lit_comp("Disassembly"), DF_NameKind_Null, DF_IconKind_Glasses, DF_VIEW_SETUP_FUNCTION_NAME(Disassembly), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Disassembly), DF_VIEW_CMD_FUNCTION_NAME(Disassembly), DF_VIEW_UI_FUNCTION_NAME(Disassembly)}, -{(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|0*DF_ViewSpecFlag_CanFilter|0*DF_ViewSpecFlag_FilterIsCode|0*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("eval_viewer"), str8_lit_comp("Evaluation Viewer"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(EvalViewer), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(EvalViewer), DF_VIEW_CMD_FUNCTION_NAME(EvalViewer), DF_VIEW_UI_FUNCTION_NAME(EvalViewer)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|1*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("watch"), str8_lit_comp("Watch"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(Watch), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Watch), DF_VIEW_CMD_FUNCTION_NAME(Watch), DF_VIEW_UI_FUNCTION_NAME(Watch)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|1*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("locals"), str8_lit_comp("Locals"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(Locals), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Locals), DF_VIEW_CMD_FUNCTION_NAME(Locals), DF_VIEW_UI_FUNCTION_NAME(Locals)}, {(0|0*DF_ViewSpecFlag_ParameterizedByEntity|1*DF_ViewSpecFlag_CanSerialize|0*DF_ViewSpecFlag_CanSerializeEntityPath|1*DF_ViewSpecFlag_CanFilter|1*DF_ViewSpecFlag_FilterIsCode|1*DF_ViewSpecFlag_TypingAutomaticallyFilters), str8_lit_comp("registers"), str8_lit_comp("Registers"), DF_NameKind_Null, DF_IconKind_Binoculars, DF_VIEW_SETUP_FUNCTION_NAME(Registers), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME(Registers), DF_VIEW_CMD_FUNCTION_NAME(Registers), DF_VIEW_UI_FUNCTION_NAME(Registers)}, diff --git a/src/df/gfx/generated/df_gfx.meta.h b/src/df/gfx/generated/df_gfx.meta.h index 1f4ba593..bee55a8e 100644 --- a/src/df/gfx/generated/df_gfx.meta.h +++ b/src/df/gfx/generated/df_gfx.meta.h @@ -10,7 +10,6 @@ typedef enum DF_NameKind { DF_NameKind_Null, DF_NameKind_EntityName, -DF_NameKind_EntityKindName, DF_NameKind_COUNT, } DF_NameKind; @@ -26,13 +25,13 @@ DF_GfxViewKind_SymbolLister, DF_GfxViewKind_Target, DF_GfxViewKind_Targets, DF_GfxViewKind_FilePathMap, +DF_GfxViewKind_AutoViewRules, DF_GfxViewKind_Scheduler, DF_GfxViewKind_CallStack, DF_GfxViewKind_Modules, DF_GfxViewKind_PendingEntity, DF_GfxViewKind_Code, DF_GfxViewKind_Disassembly, -DF_GfxViewKind_EvalViewer, DF_GfxViewKind_Watch, DF_GfxViewKind_Locals, DF_GfxViewKind_Registers, @@ -132,13 +131,13 @@ DF_VIEW_SETUP_FUNCTION_DEF(SymbolLister); DF_VIEW_SETUP_FUNCTION_DEF(Target); DF_VIEW_SETUP_FUNCTION_DEF(Targets); DF_VIEW_SETUP_FUNCTION_DEF(FilePathMap); +DF_VIEW_SETUP_FUNCTION_DEF(AutoViewRules); DF_VIEW_SETUP_FUNCTION_DEF(Scheduler); DF_VIEW_SETUP_FUNCTION_DEF(CallStack); DF_VIEW_SETUP_FUNCTION_DEF(Modules); DF_VIEW_SETUP_FUNCTION_DEF(PendingEntity); DF_VIEW_SETUP_FUNCTION_DEF(Code); DF_VIEW_SETUP_FUNCTION_DEF(Disassembly); -DF_VIEW_SETUP_FUNCTION_DEF(EvalViewer); DF_VIEW_SETUP_FUNCTION_DEF(Watch); DF_VIEW_SETUP_FUNCTION_DEF(Locals); DF_VIEW_SETUP_FUNCTION_DEF(Registers); @@ -162,13 +161,13 @@ DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(SymbolLister); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Target); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Targets); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(FilePathMap); +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(AutoViewRules); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Scheduler); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(CallStack); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Modules); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(PendingEntity); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Code); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Disassembly); -DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(EvalViewer); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Watch); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Locals); DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Registers); @@ -192,13 +191,13 @@ DF_VIEW_CMD_FUNCTION_DEF(SymbolLister); DF_VIEW_CMD_FUNCTION_DEF(Target); DF_VIEW_CMD_FUNCTION_DEF(Targets); DF_VIEW_CMD_FUNCTION_DEF(FilePathMap); +DF_VIEW_CMD_FUNCTION_DEF(AutoViewRules); DF_VIEW_CMD_FUNCTION_DEF(Scheduler); DF_VIEW_CMD_FUNCTION_DEF(CallStack); DF_VIEW_CMD_FUNCTION_DEF(Modules); DF_VIEW_CMD_FUNCTION_DEF(PendingEntity); DF_VIEW_CMD_FUNCTION_DEF(Code); DF_VIEW_CMD_FUNCTION_DEF(Disassembly); -DF_VIEW_CMD_FUNCTION_DEF(EvalViewer); DF_VIEW_CMD_FUNCTION_DEF(Watch); DF_VIEW_CMD_FUNCTION_DEF(Locals); DF_VIEW_CMD_FUNCTION_DEF(Registers); @@ -222,13 +221,13 @@ DF_VIEW_UI_FUNCTION_DEF(SymbolLister); DF_VIEW_UI_FUNCTION_DEF(Target); DF_VIEW_UI_FUNCTION_DEF(Targets); DF_VIEW_UI_FUNCTION_DEF(FilePathMap); +DF_VIEW_UI_FUNCTION_DEF(AutoViewRules); DF_VIEW_UI_FUNCTION_DEF(Scheduler); DF_VIEW_UI_FUNCTION_DEF(CallStack); DF_VIEW_UI_FUNCTION_DEF(Modules); DF_VIEW_UI_FUNCTION_DEF(PendingEntity); DF_VIEW_UI_FUNCTION_DEF(Code); DF_VIEW_UI_FUNCTION_DEF(Disassembly); -DF_VIEW_UI_FUNCTION_DEF(EvalViewer); DF_VIEW_UI_FUNCTION_DEF(Watch); DF_VIEW_UI_FUNCTION_DEF(Locals); DF_VIEW_UI_FUNCTION_DEF(Registers); @@ -255,16 +254,28 @@ DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(omit); DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(no_addr); DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(rgba); DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(bitmap); -DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(odin_map); DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(geo); DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(rgba); DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text); DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm); DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap); -DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(odin_map); DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo); -DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_DEF(bitmap); -DF_GFX_VIEW_RULE_WHOLE_UI_FUNCTION_DEF(odin_map); +DF_VIEW_SETUP_FUNCTION_DEF(text); +DF_VIEW_SETUP_FUNCTION_DEF(disasm); +DF_VIEW_SETUP_FUNCTION_DEF(bitmap); +DF_VIEW_SETUP_FUNCTION_DEF(geo); +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(text); +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(disasm); +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(bitmap); +DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(geo); +DF_VIEW_CMD_FUNCTION_DEF(text); +DF_VIEW_CMD_FUNCTION_DEF(disasm); +DF_VIEW_CMD_FUNCTION_DEF(bitmap); +DF_VIEW_CMD_FUNCTION_DEF(geo); +DF_VIEW_UI_FUNCTION_DEF(text); +DF_VIEW_UI_FUNCTION_DEF(disasm); +DF_VIEW_UI_FUNCTION_DEF(bitmap); +DF_VIEW_UI_FUNCTION_DEF(geo); C_LINKAGE_BEGIN extern String8 df_g_theme_preset_display_string_table[9]; extern String8 df_g_theme_preset_code_string_table[9]; @@ -4867,6 +4878,132 @@ read_only global U8 df_g_default_code_font_bytes__data[] = }; read_only global String8 df_g_default_code_font_bytes = {df_g_default_code_font_bytes__data, sizeof(df_g_default_code_font_bytes__data)}; +read_only global U8 df_g_icon_file_bytes__data[] = +{ +0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x20,0x00,0x02,0x1e,0x00,0x00,0x16,0x00,0x00,0x00,0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x06,0x00,0x00,0x00,0x5c,0x72,0xa8,0x66,0x00,0x00,0x1d,0xc9,0x49,0x44,0x41,0x54,0x78, +0x9c,0xed,0xdd,0x7b,0x7c,0x14,0xe5,0xbd,0xc7,0xf1,0xcf,0x6e,0xb2,0x9b,0x04,0x12,0x20,0x10,0xae,0xe2,0x25,0x52,0x06,0x05,0xe5,0x12,0x14,0x6f,0xc7,0x56,0x99,0x5a,0xd4,0xaa,0xd5,0xda,0x8b,0xb7,0xa2,0x55,0x4f,0x6d,0x6b,0xab,0xb5,0xf6,0x72,0x7a,0xb1,0xb5,0x1e,0x41,0xce,0xd1,0xb6,0x5a,0x4f,0xeb,0xa9,0x56,0x8b,0x37,0xb4,0x5a, +0xfb,0xaa,0x56,0x5a,0xa4,0x1d,0xb5,0x20,0x2d,0x95,0x8a,0x8a,0xf5,0xa0,0x83,0x8a,0x37,0x10,0x08,0x90,0x70,0x0b,0xe4,0xb6,0x7b,0xfe,0x98,0x8d,0x44,0x48,0x42,0x36,0xf3,0xcc,0xfc,0x66,0x77,0x7e,0xef,0xd7,0x8b,0x57,0xbc,0x24,0xcf,0xf3,0xcb,0x32,0xcf,0x77,0x9f,0x99,0x9d,0x79,0x1e,0x50,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5, +0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x54,0xe1,0x4a,0x48,0x17,0xa0,0x82,0xe5,0x58,0x54,0x01,0xd5,0xc0,0xa0,0x4e,0x5f,0x3b,0xff,0x33,0x40,0x23,0xd0,0x90,0xfb,0xda,0xf9,0x9f,0x1b,0x6c,0x97,0x6d,0x61,0xd7,0xac,0xc2,0xa3,0x01,0x50,0xa0,0x1c,0x8b,0xa1,0xc0,0x54,0x60,0x0a,0x70,0x30,0x7b, +0x0f,0xec,0x6a,0x60,0x20,0x50,0xe2,0xb3,0xab,0x76,0x60,0x0b,0x9d,0x42,0x81,0xdd,0x41,0xf1,0x06,0xf0,0x3c,0xf0,0x9c,0xed,0x52,0xef,0xb3,0x1f,0x25,0x40,0x03,0xa0,0x00,0x38,0x16,0xfb,0x03,0x75,0x78,0x83,0xbd,0x2e,0xf7,0x67,0x3f,0xd1,0xa2,0xf6,0xb6,0x06,0x58,0xde,0xf9,0x8f,0xed,0xf2,0xae,0x6c,0x49,0x6a,0x5f,0x34,0x00,0x22, +0xc4,0xb1,0x48,0xe0,0xbd,0x9b,0xd7,0x75,0xfa,0x33,0x05,0x18,0x2a,0x59,0x97,0x0f,0xf5,0x78,0x33,0x84,0xce,0xa1,0xf0,0xba,0x6c,0x49,0xaa,0x33,0x0d,0x80,0x88,0x70,0x2c,0x7e,0x0f,0x9c,0x80,0x37,0x6d,0x2f,0x66,0x5b,0x80,0xa7,0x6d,0x97,0x33,0xa5,0x0b,0x51,0x1a,0x00,0x91,0xe0,0x58,0xd4,0xe2,0x9d,0x4f,0xc7,0x49,0xad,0xed,0xf2, +0xa6,0x74,0x11,0x71,0x97,0x94,0x2e,0x40,0x01,0x30,0x5d,0xba,0x00,0x01,0x71,0xfc,0x9d,0x23,0x47,0x03,0x20,0x1a,0xe2,0x38,0x18,0xe2,0xf8,0x3b,0x47,0x8e,0x06,0x40,0x34,0x9c,0x28,0x5d,0x80,0x80,0x38,0xfe,0xce,0x91,0xa3,0x01,0x20,0xcc,0xb1,0x38,0x04,0x18,0x29,0x5d,0x87,0x80,0x51,0x8e,0xc5,0x38,0xe9,0x22,0xe2,0x4e,0x03,0x40, +0x5e,0x9c,0xa7,0xc2,0x71,0xfe,0xdd,0x23,0x41,0x03,0x40,0x5e,0x9c,0x07,0x41,0x9c,0x7f,0xf7,0x48,0xd0,0x8f,0x01,0x05,0xe5,0x6e,0xfc,0xa9,0x07,0x86,0x48,0xd7,0x22,0x64,0x23,0x30,0xcc,0x76,0xc9,0x4a,0x17,0x12,0x57,0x3a,0x03,0x90,0x35,0x91,0xf8,0x0e,0x7e,0x80,0x1a,0xe0,0x70,0xe9,0x22,0xe2,0x4c,0x03,0x40,0x96,0x4e,0x81,0xf5, +0x35,0x10,0xa5,0x01,0x20,0x4b,0x0f,0x7e,0x7d,0x0d,0x44,0xe9,0x35,0x00,0x21,0x8e,0x45,0x09,0xb0,0x19,0x18,0x20,0x5d,0x8b,0xb0,0x2d,0xc0,0x10,0xdb,0xa5,0x5d,0xba,0x90,0x38,0xd2,0x19,0x80,0x9c,0xa9,0xe8,0xe0,0x07,0xef,0xe1,0xa7,0x3a,0xe9,0x22,0xe2,0x4a,0x03,0x40,0x8e,0x4e,0x7d,0x77,0xd3,0xd7,0x42,0x88,0x06,0x80,0x1c,0x3d, +0xe8,0x77,0xd3,0xd7,0x42,0x88,0x5e,0x03,0x10,0xe0,0x58,0xa4,0xf1,0x96,0xd6,0xea,0x27,0x5d,0x4b,0x44,0x34,0x01,0x83,0x6c,0x97,0x56,0xe9,0x42,0xe2,0x46,0x67,0x00,0x32,0x8e,0x42,0x07,0x7f,0x67,0xfd,0xf0,0x5e,0x13,0x15,0x32,0x0d,0x00,0x19,0x3a,0xe5,0xdd,0x9b,0xbe,0x26,0x02,0x34,0x00,0x64,0xe8,0xc1,0xbe,0x37,0x7d,0x4d,0x04, +0xe8,0x35,0x80,0x90,0x39,0x16,0x15,0x78,0x4b,0x6a,0xa7,0xa5,0x6b,0x89,0x98,0x66,0xa0,0xda,0x76,0xd9,0x29,0x5d,0x48,0x9c,0xe8,0x0c,0x20,0x7c,0xc7,0xa1,0x83,0xbf,0x2b,0x65,0xc0,0xb1,0xd2,0x45,0xc4,0x8d,0x06,0x40,0xf8,0x74,0xaa,0xdb,0x3d,0x7d,0x6d,0x42,0xa6,0x01,0x10,0x3e,0x3d,0xc8,0xbb,0xa7,0xaf,0x4d,0xc8,0xf4,0x1a,0x40, +0x88,0x1c,0x8b,0x01,0x78,0xf7,0xff,0xfb,0xdd,0xae,0xab,0x58,0xb5,0x01,0x83,0x75,0x3f,0xc2,0xf0,0xe8,0x0c,0x20,0x5c,0xc7,0xa3,0x83,0xbf,0x27,0xa5,0x78,0xaf,0x91,0x0a,0x89,0xce,0x00,0x42,0xe0,0x58,0x94,0x03,0x5f,0x00,0xbe,0x0d,0x8c,0x12,0x2e,0x27,0xea,0xd6,0x02,0x73,0x80,0x3b,0x6c,0x97,0x5d,0xd2,0xc5,0x14,0x3b,0x0d,0x80, +0x00,0xe5,0x3e,0xf2,0xfb,0x22,0xf0,0x2d,0x60,0x84,0x70,0x39,0x85,0xe6,0x3d,0xe0,0x46,0xe0,0x7f,0xf5,0xa3,0xc1,0xe0,0x68,0x00,0x04,0xc0,0xb1,0xe8,0x0f,0x7c,0x19,0xb8,0x1a,0x18,0x2e,0x5c,0x4e,0xa1,0x5b,0x0f,0xdc,0x04,0xdc,0x66,0xbb,0xec,0x90,0x2e,0xa6,0xd8,0x68,0x00,0x18,0xe4,0x58,0x54,0x02,0x5f,0x01,0xbe,0x4e,0xe1,0xee, +0xe8,0x1b,0x55,0xf5,0xc0,0x4f,0x80,0xff,0xb1,0x5d,0xb6,0x4b,0x17,0x53,0x2c,0x34,0x00,0x0c,0xc8,0x5d,0xdd,0xbf,0x02,0xf8,0x1a,0xf1,0x5e,0xe4,0x33,0x0c,0x9b,0x80,0x9b,0x81,0x9f,0xd9,0x2e,0x5b,0xa5,0x8b,0x29,0x74,0x05,0x15,0x00,0x8e,0x45,0x12,0xf8,0x11,0xb0,0x1a,0x58,0x60,0xbb,0xac,0x15,0xae,0x27,0x0d,0x7c,0x13,0xf8,0x06, +0x30,0x48,0xb2,0x96,0x18,0x6a,0x00,0x7e,0x0c,0xdc,0x68,0xbb,0xb4,0x48,0x16,0xe2,0x58,0x8c,0x02,0x4e,0x06,0x0e,0x02,0xae,0xb5,0x5d,0x32,0x92,0xf5,0xe4,0xa3,0xd0,0x02,0xe0,0x66,0xe0,0xca,0x4e,0xff,0xe9,0x5f,0xc0,0x02,0xe0,0x09,0x60,0xb1,0xed,0xd2,0x1c,0x62,0x2d,0x75,0xc0,0x5c,0x74,0x59,0x6b,0x69,0x2f,0x01,0x17,0xda,0x2e, +0xcf,0x87,0xd5,0xa1,0x63,0x51,0x86,0xf7,0x71,0xe5,0x0c,0xbc,0x81,0x7f,0x58,0xa7,0xff,0x7d,0xb3,0xed,0x72,0x55,0x58,0xb5,0xf8,0x55,0x30,0x01,0xe0,0x58,0x5c,0x89,0x37,0xf5,0xeb,0x4e,0x13,0xf0,0x34,0xb9,0x40,0xb0,0x5d,0xdc,0x80,0xea,0x48,0x01,0xd7,0x00,0xdf,0xc1,0xfb,0xdc,0x5a,0xc9,0x6b,0x03,0x6e,0x00,0xfe,0x33,0xa8,0x45, +0x45,0x1c,0x0b,0x8b,0xdd,0x03,0xfe,0x04,0x7a,0x5e,0xcf,0xe1,0x4a,0xdb,0xe5,0x67,0x41,0xd4,0x61,0x5a,0x41,0x04,0x80,0x63,0x71,0x26,0xf0,0x08,0xf9,0xdd,0xb8,0xb4,0x1a,0x6f,0x66,0xb0,0x00,0x78,0xd2,0xc4,0xdd,0x65,0x8e,0xc5,0x14,0xbc,0x77,0xfd,0x89,0x7e,0xdb,0x52,0x81,0x58,0x01,0x5c,0x64,0x62,0x36,0xe0,0x58,0x54,0x01,0x36, +0xde,0xa0,0x9f,0x01,0xd4,0xe6,0xf1,0xe3,0x19,0xe0,0x93,0xb6,0xcb,0xa3,0x7e,0xeb,0x08,0x5a,0xe4,0x03,0xc0,0xb1,0x98,0x86,0xf7,0xce,0x5e,0xe1,0xa3,0x99,0x56,0xe0,0x6f,0xec,0x0e,0x84,0x17,0xf2,0xd9,0x8e,0x2a,0xf7,0xae,0xff,0x7d,0xe0,0xbb,0xe8,0xbb,0x7e,0xd4,0xb5,0x02,0xb3,0x81,0x59,0xf9,0xcc,0x06,0x72,0xdb,0xb4,0x4d,0x61, +0xf7,0xbb,0xfc,0x31,0x40,0xca,0x47,0x1d,0x4d,0xc0,0x09,0xb6,0xcb,0x32,0x1f,0x6d,0x04,0x2e,0xd2,0x01,0xe0,0x58,0xd4,0x02,0x4b,0x81,0x61,0x86,0x9b,0x5e,0x0f,0x2c,0xc4,0x0b,0x84,0x85,0xb6,0x4b,0x7d,0x0f,0x35,0x4c,0xc6,0x7b,0xd7,0x9f,0x64,0xb8,0x06,0x15,0xac,0x17,0xf1,0xae,0x0d,0xbc,0xd8,0xdd,0x37,0x38,0x16,0x43,0x81,0x8f, +0xe1,0x0d,0xf8,0x93,0x30,0x7f,0xcf,0xc6,0x06,0xe0,0x68,0xdb,0x65,0xb5,0xe1,0x76,0x8d,0x89,0x6c,0x00,0x38,0x16,0xd5,0x78,0xef,0xda,0x87,0x04,0xdc,0x55,0x16,0x58,0xce,0xee,0xd9,0xc1,0xdf,0x6d,0x97,0xb6,0xdc,0xbb,0xfe,0xf7,0xf0,0xde,0xf5,0xfd,0xbc,0x13,0x28,0x39,0xad,0xc0,0x2c,0x60,0xb6,0xed,0xd2,0xea,0x58,0x94,0xe2,0xbd, +0xb3,0x9f,0x8c,0xf7,0x4e,0x5f,0x47,0xf0,0x63,0xe0,0x15,0xe0,0x58,0xdb,0xa5,0x21,0xe0,0x7e,0xfa,0x24,0x92,0x01,0x90,0xbb,0xca,0xba,0x10,0xf8,0xb0,0x40,0xf7,0x5b,0x01,0x07,0xef,0x9c,0x6f,0xb2,0x40,0xff,0xca,0xbc,0x17,0xf0,0xae,0x09,0xd9,0xc8,0x6c,0xc6,0xb2,0x08,0x38,0x49,0xfa,0xe3,0xca,0xae,0x44,0x2e,0x00,0x72,0xe7,0x62, +0xf7,0x03,0xe7,0x4a,0xd7,0xa2,0x94,0x41,0xf3,0x80,0x0b,0xa2,0xb6,0x15,0x7a,0x14,0x1f,0x07,0xbe,0x1e,0x1d,0xfc,0xaa,0xf8,0x9c,0x07,0xfc,0xa7,0x74,0x11,0x7b,0x8a,0xd4,0x0c,0xc0,0xb1,0xb8,0x14,0xb8,0x43,0xba,0x0e,0xa5,0x02,0x74,0xa9,0xed,0x72,0xa7,0x74,0x11,0x1d,0x22,0x13,0x00,0x8e,0xc5,0x47,0x81,0x3f,0xa1,0x1f,0xb3,0xa9, +0xe2,0xd6,0x06,0x9c,0x62,0xbb,0xfc,0x45,0xba,0x10,0x88,0x48,0x00,0xe4,0xae,0xf8,0xbf,0x0c,0x8c,0x94,0xae,0x45,0xa9,0x10,0xbc,0x07,0x4c,0x88,0xc2,0x27,0x03,0x51,0xb9,0x06,0xf0,0x33,0x74,0xf0,0xab,0xf8,0x18,0x09,0xdc,0x22,0x5d,0x04,0x44,0x60,0x06,0xe0,0x58,0x9c,0x0e,0x3c,0x26,0x5d,0x87,0x52,0x02,0x4e,0xb7,0x5d,0x1e,0x97, +0x2c,0x40,0x34,0x00,0x74,0xea,0xaf,0x62,0x4e,0xfc,0x54,0x40,0xfa,0x14,0xe0,0x16,0x74,0xf0,0xab,0xf8,0x1a,0x49,0xcf,0x4f,0xb8,0x06,0x4e,0x6c,0x06,0xa0,0x53,0x7f,0xa5,0xde,0x27,0x76,0x2a,0x20,0x12,0x00,0x3a,0xf5,0x57,0xea,0x03,0xd6,0xe2,0x9d,0x0a,0x34,0x86,0xdd,0xb1,0xd4,0x29,0x80,0x4e,0xfd,0x95,0xda,0x6d,0x14,0x42,0x9f, +0x0a,0x84,0x3e,0x03,0xd0,0xa9,0xbf,0x52,0xdd,0x0a,0xfd,0x54,0x20,0xd4,0x00,0xd0,0xa9,0xbf,0x52,0x3d,0x0a,0xfd,0x54,0x20,0xec,0x53,0x00,0x9d,0xfa,0x2b,0xd5,0xbd,0xd0,0x4f,0x05,0x42,0x9b,0x01,0x38,0x16,0xa7,0x01,0x7f,0x08,0xab,0x3f,0xa5,0x0a,0x58,0x68,0xa7,0x02,0xa1,0x04,0x40,0x6e,0x81,0x8f,0x55,0xc0,0xfe,0x61,0xf4,0xa7, +0x54,0x81,0x7b,0x07,0xf8,0x50,0x18,0x0b,0x88,0x84,0x75,0x0a,0x70,0x09,0x3a,0xf8,0x95,0xea,0xad,0xfd,0xf1,0xc6,0x4c,0xe0,0x02,0x9f,0x01,0xe4,0x76,0xcf,0x79,0x0d,0x0d,0x00,0xa5,0xf2,0xf1,0x36,0x30,0x36,0xe8,0x59,0x40,0x18,0x33,0x80,0xcf,0xa3,0x83,0x5f,0xa9,0x7c,0x1d,0x00,0x5c,0x14,0x74,0x27,0x81,0xce,0x00,0x72,0x2b,0xeb, +0xae,0x02,0x0e,0x0c,0xb2,0x1f,0xa5,0x8a,0xd4,0x5b,0x78,0xb3,0x80,0x40,0x76,0x3b,0x82,0xe0,0x67,0x00,0x17,0xa2,0x83,0x5f,0xa9,0xbe,0x3a,0x10,0x98,0x19,0x64,0x07,0x81,0xcd,0x00,0x72,0x6b,0xb0,0xbb,0xe4,0xb7,0xa5,0x92,0x52,0xea,0x83,0x56,0x03,0x96,0xed,0xd2,0x16,0x44,0xe3,0x41,0xce,0x00,0x66,0xa2,0x83,0x5f,0x29,0xbf,0x6a, +0x81,0xcf,0x05,0xd5,0x78,0x20,0x33,0x80,0xdc,0xbb,0xff,0xab,0xc0,0xc1,0x41,0xb4,0xaf,0x54,0xcc,0xbc,0x0e,0x8c,0xb3,0x5d,0xda,0x4d,0x37,0x1c,0xd4,0x0c,0xe0,0x7c,0x74,0xf0,0x2b,0x65,0xca,0x18,0xbc,0x31,0x65,0x9c,0xf1,0x19,0x80,0x63,0x51,0x82,0xb7,0x1f,0xda,0x87,0x4c,0xb7,0xad,0x54,0x8c,0xad,0x02,0x0e,0x35,0x3d,0x0b,0x08, +0x62,0x0d,0xfe,0xf3,0xd0,0xc1,0xdf,0xa3,0x64,0x2a,0xcd,0x90,0xe9,0xa7,0x33,0xea,0xd3,0x97,0x52,0x7d,0xe4,0x47,0x00,0xc8,0x66,0xb3,0x40,0x16,0x32,0x19,0xef,0x9f,0x73,0x7f,0xb2,0xd9,0xcc,0xfb,0xff,0x4c,0x36,0x4b,0x36,0x93,0xf1,0xbe,0x2f,0x9b,0xf5,0xbe,0xaf,0xf3,0xf7,0x93,0xfb,0xff,0xdd,0xfc,0x7c,0xc7,0xf7,0x43,0x76,0xf7, +0xcf,0x7c,0xa0,0xbf,0x3d,0xfa,0xee,0xa2,0x2f,0xb2,0x59,0xb2,0x74,0xf5,0xb3,0xbd,0xab,0xb5,0xf3,0xcf,0xaf,0x7b,0xf4,0x3e,0x36,0x3e,0xa9,0x4f,0x86,0xf7,0xd2,0x58,0xbc,0x1d,0xb3,0xee,0x33,0xd9,0xa8,0xd1,0x19,0x80,0x63,0x91,0x04,0x56,0x02,0x96,0xc9,0x76,0x8b,0x59,0xbf,0x03,0xc7,0x32,0xf2,0x33,0x97,0x32,0xf2,0xac,0x8b,0x48, +0x0f,0x31,0xbd,0x0b,0x7a,0xb4,0x65,0xdb,0x5a,0x59,0xf1,0xc5,0x33,0xd8,0xb4,0x78,0x81,0x74,0x29,0x85,0xe2,0x55,0x60,0xbc,0xed,0x92,0x31,0xd5,0xa0,0xe9,0x00,0x38,0x07,0x78,0xc0,0x64,0x9b,0x71,0x91,0x4c,0xa5,0x19,0x72,0xe2,0x69,0x1c,0x70,0xf1,0x37,0x18,0x38,0xe5,0x18,0xe9,0x72,0x42,0x93,0x69,0xde,0xc5,0x8b,0x97,0x9e,0x42, +0xc3,0xb3,0x4f,0x4b,0x97,0x52,0x28,0xce,0xb5,0x5d,0x1e,0x34,0xd5,0x98,0xe9,0x8b,0x80,0xa1,0x3c,0xc0,0x50,0x8c,0x32,0xad,0x2d,0xd4,0x2f,0xfc,0x1d,0xcb,0xcf,0x3f,0x9e,0x55,0x37,0x7c,0x9d,0x4c,0xf3,0x2e,0xe9,0x92,0x42,0x91,0x2c,0x2b,0x67,0xe2,0xed,0x8f,0x33,0x60,0xf2,0xd1,0xd2,0xa5,0x14,0x8a,0x8b,0x4d,0x36,0x66,0x6c,0x06, +0xe0,0x58,0x0c,0xc3,0x5b,0xd1,0xa4,0xc4,0x54,0x9b,0x71,0xd6,0xef,0xe0,0x43,0x18,0x3f,0x67,0x2e,0x03,0x26,0x1d,0x25,0x5d,0x4a,0x28,0xda,0xb6,0x36,0xb2,0x7c,0xe6,0x89,0x6c,0x5f,0xf9,0x82,0x74,0x29,0x51,0xd7,0x0e,0x8c,0xb4,0x5d,0xea,0x4d,0x34,0x66,0x72,0x06,0xf0,0x69,0x74,0xf0,0x1b,0xd3,0xf4,0xc6,0x2b,0x3c,0x77,0xee,0xbf, +0xf1,0xfa,0x8f,0xbf,0x43,0xa6,0x35,0xf0,0xc7,0xc2,0xc5,0x95,0x0e,0x18,0xc4,0x94,0x5f,0xff,0x99,0xfe,0x1f,0x1a,0x2f,0x5d,0x4a,0xd4,0x95,0xe0,0x8d,0x35,0x23,0x4c,0x06,0xc0,0x39,0x06,0xdb,0x52,0x40,0xb6,0xbd,0x8d,0xb7,0x6e,0x9f,0xc3,0xb2,0xb3,0xa6,0xd2,0xb4,0xfa,0x55,0xe9,0x72,0x02,0x97,0xaa,0xae,0x61,0xca,0xdc,0xbf,0x50, +0x71,0xc0,0x18,0xe9,0x52,0xa2,0xce,0xd8,0x58,0x33,0x72,0x0a,0xe0,0x58,0x8c,0xc6,0x7b,0x7e,0x59,0x7c,0xaf,0xc1,0x62,0x55,0x36,0x7c,0x3f,0xea,0xe6,0x2d,0xa6,0x62,0x74,0xf1,0xdf,0x5d,0xbd,0x6b,0xed,0x5b,0x2c,0x3f,0xff,0xc3,0xec,0x5a,0xfb,0xb6,0x74,0x29,0x51,0x95,0x05,0xf6,0xb7,0x5d,0xd6,0xf8,0x6d,0xc8,0x54,0x00,0x5c,0x0d, +0xdc,0x64,0xa2,0xad,0x42,0x52,0x5a,0x99,0xa0,0xfa,0xb0,0x34,0xe5,0x43,0x4b,0x28,0xab,0x4e,0x92,0xae,0x4e,0x52,0x36,0x38,0x49,0x32,0x95,0xa0,0x79,0x73,0x86,0x96,0xcd,0x19,0x9a,0x1b,0xda,0x69,0xde,0x94,0xa1,0x71,0x65,0x2b,0xbb,0xea,0xfd,0xdd,0xc3,0x51,0x31,0xba,0x96,0xba,0x79,0x8b,0x29,0x1b,0xbe,0x9f,0xa1,0xdf,0x20,0xba, +0x9a,0xde,0x5a,0xc5,0xf2,0xf3,0x3e,0x4c,0xcb,0xc6,0x75,0xd2,0xa5,0x44,0xd5,0xd5,0xb6,0xcb,0x4f,0xfc,0x36,0x62,0x2a,0x00,0x96,0x01,0x47,0x98,0x68,0x2b,0xea,0xca,0x6b,0x4a,0xa8,0x99,0x96,0x66,0xe8,0xb4,0x32,0x06,0x8d,0x4f,0x93,0xc8,0xe3,0xaa,0xc7,0xf6,0xd5,0x6d,0xd4,0x3f,0xdb,0x4c,0xfd,0xb2,0x66,0xb6,0xbf,0xd9,0xe6,0xe5, +0x78,0x9e,0xfa,0xd5,0x8e,0xa3,0xee,0xfe,0x45,0xb1,0xb8,0x67,0x60,0xc7,0xaa,0x97,0x59,0xfe,0xb9,0x13,0x68,0x6d,0xd8,0x28,0x5d,0x4a,0x14,0x2d,0xb3,0x5d,0xa6,0xf9,0x6d,0xc4,0x77,0x00,0x38,0x16,0x63,0xf0,0x96,0xfc,0x2a,0x6a,0xfd,0x46,0x95,0x30,0xe6,0x82,0x4a,0x86,0x1e,0x55,0x66,0xa4,0xbd,0x6d,0xaf,0xb7,0xf1,0xda,0xbd,0xdb, +0x69,0x78,0x29,0xff,0x0b,0x7c,0x95,0xe3,0x26,0x52,0x77,0xdf,0xd3,0x94,0x0e,0xa8,0x36,0x52,0x4b,0x94,0x6d,0x7b,0x79,0x39,0xcf,0x5f,0x38,0x9d,0xb6,0x6d,0x5b,0xa4,0x4b,0x89,0xa2,0x31,0xb6,0xcb,0x1b,0x7e,0x1a,0x30,0x71,0x11,0xb0,0xa8,0x2f,0xfe,0xa5,0xab,0x93,0x8c,0xbb,0xac,0x8a,0xa3,0x6e,0x19,0x62,0x6c,0xf0,0x03,0x54,0x8d, +0x29,0x65,0xca,0xb5,0x83,0x98,0x7c,0xcd,0x20,0x2a,0x0f,0xca,0xef,0x8e,0xec,0xed,0xaf,0xae,0xe0,0x85,0x4b,0x4e,0x8e,0xc5,0xbd,0x02,0x55,0x13,0xea,0x98,0x74,0xc7,0x1f,0x29,0xe9,0x57,0x29,0x5d,0x4a,0x14,0xf9,0x1e,0x7b,0xbe,0x3f,0xb6,0xbb,0x70,0x08,0xbf,0x00,0x8a,0x72,0x3e,0x3a,0xfc,0xdf,0xca,0x99,0x72,0xed,0x20,0x06,0x8e, +0x4b,0x91,0x08,0xe8,0xf2,0x66,0xc5,0x88,0x12,0xf6,0xfb,0x58,0x05,0xc9,0x74,0x82,0xc6,0x7f,0xb5,0xf4,0xfa,0xb4,0xa0,0x79,0xfd,0x1a,0x48,0x24,0xa8,0x3e,0x7a,0x7a,0x30,0x85,0x45,0x48,0xf9,0xc8,0xfd,0x19,0x38,0xf9,0x68,0x36,0x2c,0x78,0x98,0x6c,0x5b,0x20,0xeb,0x62,0x14,0xaa,0x61,0xf7,0x6c,0xe2,0x36,0x3f,0x0d,0xf8,0x3a,0xac, +0x1d,0x8b,0x09,0xc0,0xbf,0xfc,0xb4,0x11,0x45,0x89,0x04,0xd4,0x9e,0xdb,0x9f,0x83,0xce,0xee,0x1f,0x6a,0xbf,0x9b,0x9e,0x6b,0xe1,0xe5,0x9f,0x6e,0xa1,0x6d,0x67,0xef,0x52,0x20,0x99,0x2e,0x63,0xda,0xe3,0x2f,0xd1,0xef,0xc0,0xb1,0x01,0x57,0x16,0x0d,0x9b,0xfe,0xfa,0x47,0x5e,0xba,0xfc,0xac,0x58,0xdc,0x17,0x91,0x87,0x09,0xb6,0xcb, +0xff,0xf5,0xf5,0x87,0xfd,0x9e,0x02,0x14,0xdd,0xf4,0xbf,0xa4,0x3c,0xc1,0x61,0xdf,0x1a,0x18,0xfa,0xe0,0x07,0x18,0x32,0x35,0xcd,0xd4,0x39,0xd5,0x54,0x0c,0xef,0xdd,0xc4,0x2c,0xd3,0xd2,0x8c,0x7b,0xdd,0x57,0x02,0xae,0x2a,0x3a,0x86,0x7c,0xe4,0x54,0xc6,0xff,0xf8,0x7e,0x12,0x25,0x41,0x3c,0xc4,0x5a,0xb0,0x7c,0x8d,0x41,0xbf,0x01, +0xf0,0x59,0x9f,0x3f,0x1f,0x29,0x89,0x12,0x98,0xf8,0x9d,0x81,0x0c,0x9d,0x66,0xee,0x5c,0x3f,0x5f,0xfd,0x47,0x97,0x52,0x77,0x7d,0x35,0x65,0x83,0x7b,0xf7,0x57,0xb3,0xf9,0x99,0x85,0x6c,0x58,0xf0,0x70,0xc0,0x55,0x45,0xc7,0xb0,0x19,0x9f,0xe2,0xd0,0x1b,0xee,0x22,0x91,0x94,0xda,0xd9,0x3e,0x72,0x7c,0x8d,0xc1,0x3e,0xbf,0x8a,0x8e, +0x45,0x1d,0xde,0x33,0xca,0x45,0xc3,0xba,0xa4,0x8a,0xea,0xc3,0xd2,0xd2,0x65,0x50,0x36,0x38,0xc9,0xe1,0xdf,0x1e,0x48,0x32,0xdd,0xbb,0x33,0xb4,0x55,0xb3,0xaf,0xa2,0xbd,0x69,0x7b,0xc0,0x55,0x45,0xc7,0x88,0x4f,0x7c,0x0e,0xeb,0x07,0x3f,0x27,0xb0,0x0b,0x33,0x85,0xc5,0xca,0x8d,0xc5,0x3e,0xe9,0xf3,0x45,0xc0,0x0b,0x87,0xd0,0x04, +0x9c,0x08,0x8c,0xee,0x6b,0x1b,0x51,0xb2,0xdf,0xc9,0x15,0xd4,0x7e,0x26,0xfc,0x69,0x7f,0x77,0xca,0x06,0x97,0x50,0x31,0xbc,0x84,0xfa,0x7f,0x34,0xef,0xf3,0x7b,0xdb,0x77,0x6c,0xa3,0x75,0xd3,0x06,0x4a,0xaa,0x06,0xd0,0xb2,0x61,0x2d,0xad,0x9b,0xd6,0xd3,0xda,0xb0,0x91,0xb6,0xad,0x0d,0xb4,0x6d,0xdf,0x4a,0x66,0xe7,0x0e,0x32,0xcd, +0xbb,0xc8,0xb6,0xb5,0x92,0xcd,0x64,0x48,0x24,0x13,0x05,0xff,0x0e,0x3a,0xe0,0xf0,0x23,0x28,0xe9,0x5f,0xc5,0xe6,0x25,0x7f,0x96,0x2e,0x45,0xda,0x52,0xe0,0xd6,0x7b,0x36,0xb1,0xef,0x03,0xa5,0x0b,0x7e,0x2f,0x02,0x0e,0x00,0xfe,0x04,0x1c,0xeb,0xa7,0x1d,0x69,0x03,0xac,0x14,0x53,0x67,0x55,0x93,0x88,0xe0,0x98,0x58,0x75,0xd7,0x76, +0xde,0x99,0xdf,0x64,0xbc,0xdd,0x44,0x32,0x49,0xa2,0x34,0x45,0x22,0x95,0x26,0x99,0x4a,0xbf,0xff,0x35,0x99,0x4a,0x93,0x48,0x7f,0xf0,0xbf,0x75,0xf7,0x3d,0x89,0xd2,0xd4,0xee,0x7f,0xcf,0x7d,0x4d,0x0d,0x1a,0xc2,0x7e,0xe7,0x5f,0x4e,0xa2,0x24,0x9c,0xe7,0xc2,0x56,0x7c,0xf1,0x74,0x36,0x3e,0x15,0xca,0x46,0xba,0x51,0xb4,0x04,0x38, +0xc5,0x76,0xd9,0xd6,0xd7,0x06,0x7c,0x5d,0x4d,0xb1,0x5d,0xb6,0x3a,0x16,0x33,0x80,0xf9,0xc0,0x87,0xfd,0xb4,0x25,0x26,0x01,0x63,0x2f,0xaa,0x8c,0xe4,0xe0,0x07,0xa8,0x3d,0xa7,0x3f,0xeb,0x16,0xed,0xa2,0x75,0x9b,0xb1,0x45,0x60,0x00,0xc8,0x66,0x32,0x64,0x5b,0x9a,0xa1,0xa5,0xd9,0xd8,0x22,0x73,0x65,0xc3,0x46,0x31,0xe9,0xf6,0xf9, +0xa1,0x0d,0xfe,0x77,0xef,0xbd,0x95,0x8d,0x4f,0xcf,0x0f,0xa5,0xaf,0x08,0xfa,0x2b,0x70,0x9a,0xed,0xe2,0xeb,0xdc,0xcf,0xf7,0x61,0x9f,0x2b,0xe0,0x14,0xe0,0x49,0xbf,0x6d,0x49,0x18,0x3a,0xad,0x8c,0x81,0xe3,0x52,0xd2,0x65,0x74,0xab,0xb4,0x5f,0x82,0x03,0xcf,0xee,0x27,0x5d,0xc6,0x3e,0xf5,0x1f,0x7b,0x18,0x53,0x1f,0x5a,0x4a,0xe5, +0xa1,0x93,0x43,0xe9,0xef,0xdd,0x7b,0x6f,0xc5,0x9d,0x75,0x65,0x6e,0x2d,0xc4,0xd8,0x71,0x80,0x53,0xfd,0x0e,0x7e,0x30,0xf4,0x38,0xb0,0xed,0xd2,0x04,0x9c,0x06,0x2c,0x34,0xd1,0x5e,0x58,0x12,0x25,0x30,0xe6,0x82,0xe8,0xdf,0x61,0x36,0xfa,0x94,0x0a,0xca,0x87,0x45,0x77,0xa9,0x85,0xea,0x63,0x6c,0xa6,0x3e,0xb8,0x84,0xf2,0x91,0xe1, +0xec,0x01,0x1b,0xf3,0xc1,0xff,0x04,0x70,0x7a,0x6e,0xcc,0xf9,0x66,0x6c,0xe2,0x6b,0xbb,0xec,0x04,0xce,0x00,0xfe,0x68,0xaa,0xcd,0xa0,0x0d,0x3f,0xbe,0x9c,0x7e,0xa3,0xa2,0x3b,0xb0,0x3a,0x24,0x4b,0x13,0x1c,0xf4,0xc9,0x68,0xce,0x02,0x46,0x9c,0x39,0x93,0xc9,0x77,0x2e,0xa0,0xb4,0x72,0x40,0x28,0xfd,0xc5,0x7c,0xf0,0xcf,0x07,0x3e, +0x91,0x1b,0x6b,0x46,0x18,0x3d,0xf3,0xb5,0x5d,0x9a,0x81,0xb3,0x80,0x82,0x58,0xeb,0x79,0xd8,0x31,0x72,0x9f,0xf7,0xe7,0x6b,0xe8,0xd1,0x65,0x79,0x3d,0x79,0x18,0xb8,0x44,0x82,0xda,0xcb,0x7f,0xc0,0xf8,0xff,0xba,0x3b,0xb4,0x1b,0x73,0x62,0x3e,0xf8,0x1f,0x05,0x3e,0x99,0x1b,0x63,0xc6,0x18,0xbf,0xf4,0x65,0xbb,0xb4,0x00,0x9f,0x02, +0x1e,0x31,0xdd,0xb6,0x49,0x25,0xe5,0x09,0x06,0x4f,0x92,0xff,0xcc,0xbf,0xb7,0x52,0x55,0xc9,0xc8,0x5c,0xab,0x48,0x94,0xa6,0x38,0x74,0xd6,0x9d,0xd4,0x5e,0xf1,0xa3,0xd0,0xfa,0x8c,0xf9,0xe0,0x7f,0x04,0xf8,0x74,0x6e,0x6c,0x19,0x15,0xc8,0xb5,0xef,0xdc,0x7e,0xe6,0xe7,0x00,0x0f,0x05,0xd1,0xbe,0x09,0x83,0x27,0xa7,0x49,0xa6,0x0a, +0xeb,0x46,0x12,0xc9,0x3b,0x14,0x3b,0x94,0x56,0x0e,0x60,0xd2,0xed,0xf3,0x19,0x79,0xf6,0xe7,0x43,0xeb,0x33,0xe6,0x83,0xff,0x37,0xc0,0x39,0xb9,0x31,0x65,0x5c,0x60,0x1f,0x7e,0xe5,0xb6,0x33,0x3e,0x0f,0xb8,0x3f,0xa8,0x3e,0xfc,0xa8,0x39,0x52,0x7e,0x30,0xe5,0xab,0x46,0x38,0x00,0xca,0x46,0x8c,0xa6,0x6e,0xde,0x62,0x06,0x1f,0x77, +0x52,0x68,0x7d,0xc6,0x7c,0xf0,0xdf,0x07,0x9c,0x1f,0xd4,0xd6,0xe0,0x10,0xec,0xf6,0xe0,0xe4,0xf6,0x31,0x9b,0x09,0xcc,0x0d,0xb2,0x9f,0xbe,0xa8,0xdc,0xbf,0xf0,0x1e,0x28,0xa9,0x18,0x5e,0xd2,0xeb,0xdb,0x83,0x4d,0xab,0x1c,0x37,0x91,0x23,0x1e,0x5a,0x4a,0xe5,0xb8,0x89,0xa1,0xf5,0x19,0xf3,0xc1,0xff,0x6b,0xe0,0xc2,0x20,0x76,0x04, +0xee,0x2c,0xf0,0xdb,0x5f,0x72,0xdb,0x18,0x5d,0x0c,0xdc,0x11,0x74,0x5f,0xf9,0xe8,0xed,0xc3,0x36,0x51,0x53,0x56,0x1d,0x7e,0xdd,0x83,0x8f,0x3b,0x89,0xa9,0x0f,0x3c,0x13,0xea,0x5a,0x84,0x31,0x1f,0xfc,0x77,0x00,0x97,0x98,0xdc,0x02,0xac,0x3b,0xa1,0x1c,0x4d,0xb6,0x4b,0x16,0xb8,0x0c,0xf8,0x45,0x18,0xfd,0xed,0x4b,0xa2,0x04,0x52, +0x83,0x0a,0x34,0x00,0x42,0x0e,0xae,0x91,0x67,0x7f,0xde,0x5b,0x91,0xa7,0x7f,0x55,0x68,0x7d,0xc6,0x7c,0xf0,0xff,0x02,0xb8,0x2c,0x37,0x66,0x02,0x17,0xda,0x3c,0x38,0xf7,0x0b,0x5d,0xee,0x58,0xb4,0x02,0x57,0x86,0xd5,0x6f,0x57,0xd2,0x03,0x93,0x05,0xfb,0x20,0x59,0x3a,0xac,0x19,0x40,0x22,0x41,0xed,0x57,0xaf,0xa5,0xf6,0xf2,0x1f, +0x84,0xd3,0x5f,0x4e,0xcc,0x07,0xff,0xcd,0xb6,0xcb,0x55,0x61,0x76,0x18,0xfa,0xdb,0xa0,0xed,0xf2,0x35,0x84,0x97,0x10,0x4f,0x55,0x15,0xe6,0xbb,0x3f,0x40,0x6a,0x40,0xf0,0xb5,0x27,0x53,0x69,0xc6,0xcf,0x99,0xab,0x83,0x3f,0x5c,0x37,0x86,0x3d,0xf8,0x41,0x20,0x00,0x00,0x6c,0x97,0x6f,0x02,0x37,0x48,0xf4,0x0d,0x18,0x7f,0xb0,0x26, +0x4c,0xad,0x5b,0x83,0xad,0xbd,0xb4,0x6a,0x20,0x93,0x7e,0xf5,0x27,0x46,0x9c,0x39,0x33,0xd0,0x7e,0xf6,0x14,0xf3,0xc1,0x3f,0xdb,0x76,0xf9,0x96,0x44,0xc7,0x62,0x6f,0x85,0xb6,0xcb,0x77,0x81,0xeb,0x24,0xfa,0x6e,0xd9,0x92,0xe9,0xd3,0x9a,0xfc,0x51,0xd0,0xd2,0x10,0x5c,0x00,0x94,0x8f,0xdc,0x9f,0xa9,0x0f,0x3c,0x13,0xfa,0x42,0xa3, +0x31,0x1f,0xfc,0x3f,0xb2,0x5d,0xbe,0x27,0xd5,0xb9,0xe8,0x5c,0xd8,0x76,0xf9,0x21,0x70,0x4d,0xd8,0xfd,0x66,0xdb,0x73,0x21,0x50,0x80,0x9a,0x03,0x0a,0x80,0xca,0x43,0x27,0x33,0xf5,0xa1,0xa5,0xf4,0x1f,0x7b,0x58,0x20,0xed,0x77,0x27,0xe6,0x83,0xff,0xfb,0xb6,0xcb,0xb5,0x92,0x05,0x88,0x9f,0x0c,0xdb,0x2e,0xd7,0x03,0xb7,0x84,0xdd, +0x6f,0xf3,0xe6,0xc2,0x0c,0x80,0x20,0x66,0x00,0x43,0x8e,0x3f,0x99,0xa9,0xf3,0x16,0x53,0x36,0x6c,0x94,0xf1,0xb6,0x7b,0x12,0xf3,0xc1,0x7f,0xb3,0xed,0x32,0x4b,0xba,0x08,0xf1,0x00,0xc8,0x79,0x27,0xec,0x0e,0x77,0xbc,0x5b,0x78,0xeb,0xcb,0xef,0xda,0xd0,0x4e,0x7b,0xb3,0xd9,0xc1,0x32,0xea,0xd3,0x97,0x32,0xf1,0x97,0x8f,0x87,0xbe, +0xf1,0x46,0xcc,0x07,0x3f,0x08,0x1c,0xf3,0x5d,0x89,0x4a,0x00,0x0c,0x0a,0xbb,0xc3,0x8d,0xcb,0x8c,0x3e,0x54,0x15,0x8a,0x8d,0xcb,0x0c,0x3e,0x0b,0x92,0x48,0x70,0xf0,0xd7,0xae,0xe7,0x90,0xeb,0xef,0x08,0x6d,0x05,0x9f,0x0e,0x3a,0xf8,0x01,0x81,0x63,0xbe,0x2b,0x51,0xb9,0x1f,0x36,0xf4,0x4d,0xee,0x36,0x3d,0xdf,0x42,0xa6,0x2d,0x4b, +0xb2,0xb4,0x70,0x6e,0x08,0xa8,0x7f,0xd6,0x4c,0x68,0x25,0x53,0x69,0x0e,0x99,0x7d,0x27,0x23,0xce,0xb8,0xc0,0x48,0x7b,0xf9,0xd0,0xc1,0xff,0xbe,0x48,0x6c,0xec,0x18,0x95,0x19,0x40,0xe8,0x2f,0x46,0xfb,0xce,0x2c,0x0d,0x2b,0x02,0x79,0xc0,0x2a,0x10,0x6d,0xdb,0xb3,0x34,0xae,0xf4,0x3f,0x03,0x28,0x1d,0x30,0x88,0x49,0x77,0x2e,0xd0, +0xc1,0x2f,0x4f,0x03,0xa0,0x13,0x91,0x17,0x63,0xc3,0xdf,0x0b,0x67,0x73,0xcd,0xfa,0x67,0x9b,0xc9,0xfa,0x7c,0x2c,0xa4,0x7c,0xd4,0x81,0x4c,0x7d,0x60,0x09,0xd5,0x47,0x9d,0x68,0xa6,0xa8,0x3c,0xe8,0xe0,0xdf,0x8b,0x06,0x40,0x27,0x22,0xe7,0x43,0xeb,0x17,0x35,0xb3,0x73,0x5d,0xa0,0x0f,0x5b,0x19,0x91,0x6d,0x87,0x37,0x7f,0xbb,0xc3, +0x57,0x1b,0x55,0x13,0xea,0x38,0xe2,0xe1,0xa5,0xf4,0xff,0xd0,0x78,0x43,0x55,0xf5,0x9e,0x0e,0xfe,0x2e,0x45,0xe2,0x1a,0x40,0x54,0x02,0x40,0x24,0x0d,0x33,0x6d,0x59,0x5e,0xbf,0x3f,0xfa,0x3b,0xea,0xac,0x59,0xb0,0x93,0x9d,0xeb,0xfb,0x1e,0x54,0x43,0x3e,0x72,0x2a,0x75,0xf7,0x2f,0x22,0x5d,0x33,0xc2,0x60,0x55,0xbd,0xa3,0x83,0xbf, +0x5b,0x3a,0x03,0xe8,0x44,0xec,0xc5,0xd8,0xf0,0xf7,0x66,0xb6,0xbe,0x16,0xdd,0x6b,0x01,0xed,0x3b,0xb3,0xac,0xf6,0xf1,0xee,0x3f,0xea,0xb3,0x5f,0x60,0xe2,0x6d,0x8f,0x51,0x52,0x11,0xfe,0xae,0x47,0x3a,0xf8,0x7b,0xa4,0x01,0xd0,0x89,0xdc,0x74,0x28,0x0b,0xaf,0xcd,0xdd,0x1e,0xd9,0x63,0x74,0xf5,0xc3,0x3b,0xfa,0x74,0xff,0x7f,0x22, +0x99,0x64,0xcc,0xd7,0x67,0x73,0xc8,0x75,0xbf,0x0c,0xfd,0x63,0x3e,0xd0,0xc1,0xdf,0x0b,0x1a,0x00,0x00,0x8e,0x45,0x05,0x20,0xba,0xd6,0x55,0xe3,0xca,0x56,0x5e,0x9b,0x1b,0xbd,0x53,0x81,0x0d,0x7f,0x6f,0xe6,0x9d,0xc7,0xf2,0x5f,0xfe,0x3d,0x99,0x2e,0x63,0xfc,0x8d,0xf7,0x71,0xe0,0x65,0xdf,0x09,0xa0,0xaa,0x7d,0xd3,0xc1,0xdf,0x2b, +0x65,0x8e,0x45,0xb9,0x74,0x11,0xe2,0x01,0x40,0x44,0x92,0xf0,0x9d,0xf9,0x4d,0xbc,0xf7,0x64,0x74,0x3e,0x15,0xd8,0xb6,0xba,0x8d,0x95,0xb7,0x6e,0xcd,0x7b,0x0c,0xa5,0x06,0x0e,0x66,0xf2,0x5d,0x0b,0x19,0x7e,0xda,0xb9,0xc1,0x14,0xb6,0x0f,0x3a,0xf8,0xf3,0x22,0x7e,0xec,0x6b,0x00,0x74,0xc8,0xc2,0xab,0xb7,0x6f,0xa3,0x71,0xa5,0xfc, +0xf5,0x80,0x96,0xc6,0x0c,0x2f,0xcd,0xd9,0x92,0xf7,0x6d,0xbf,0x15,0xa3,0x6b,0x99,0xfa,0xe0,0x12,0x06,0x1d,0x29,0xb3,0x4d,0xa3,0x0e,0xfe,0xbc,0x89,0x1f,0xfb,0x51,0x08,0x80,0xc8,0xc8,0xb4,0x66,0x59,0x31,0xbb,0x91,0x4d,0xcb,0x8d,0x2f,0xbf,0xde,0x6b,0x4d,0xef,0xb5,0xb3,0xfc,0x07,0x0d,0xec,0xda,0x98,0xdf,0x55,0xff,0xaa,0xc3, +0x8e,0x60,0xea,0x43,0x4b,0xe9,0x77,0xf0,0x21,0x01,0x55,0xd6,0x33,0x1d,0xfc,0x85,0x29,0x0a,0x01,0xd0,0x20,0x5d,0x40,0x67,0x6d,0x4d,0x59,0x56,0xdc,0xd0,0xc8,0xdb,0x7d,0x38,0xf7,0xf6,0x6b,0xf3,0x8b,0x2d,0xfc,0xf3,0x3f,0x36,0xd3,0xb4,0x26,0xbf,0xc1,0x5f,0x33,0xfd,0x74,0xea,0xee,0xfb,0x2b,0xe9,0x21,0xc3,0x02,0xaa,0xac,0x67, +0x3a,0xf8,0xfb,0x4c,0xfc,0xd8,0xd7,0x00,0xe8,0x42,0x36,0x03,0xaf,0xdd,0xbd,0x9d,0x95,0xff,0xb3,0x95,0x4c,0x6b,0x38,0x07,0xf5,0x3b,0xf3,0x9b,0x78,0x71,0x56,0x23,0x6d,0xdb,0xf3,0xeb,0x6f,0xbf,0xf3,0xbe,0xcc,0xe1,0x3f,0xff,0x3d,0x25,0x15,0x32,0x7b,0x07,0xae,0xfb,0xfd,0x3d,0x3a,0xf8,0xfb,0x4e,0xfc,0xd8,0x8f,0xc4,0x93,0x30, +0x8e,0xc5,0x2e,0x84,0x3f,0x09,0xe8,0x4e,0x79,0x4d,0x09,0xb5,0xe7,0xf4,0x67,0xe4,0x09,0xe5,0x81,0xbc,0x5a,0x8d,0x2f,0xb7,0xf2,0xda,0xbd,0xdb,0xd9,0xba,0x2a,0xbf,0x6b,0x0f,0x89,0x64,0x92,0x31,0x57,0xcf,0xe1,0x80,0x4b,0xbf,0x69,0xbe,0xa8,0x3c,0xb4,0x6c,0x5c,0xc7,0xf2,0xcf,0x9d,0x48,0xd3,0x1b,0xaf,0x88,0xd6,0x51,0x80,0x9a, +0x6d,0x57,0xfe,0x53,0x80,0xa8,0x04,0xc0,0x3a,0x60,0xb8,0x74,0x1d,0x3d,0xa9,0x3c,0xb0,0x94,0x31,0x17,0x54,0x32,0xa4,0xce,0xcc,0x7e,0x82,0x3b,0xde,0x6e,0xe3,0xb5,0x7b,0xb7,0xb3,0xe9,0xf9,0x96,0xbc,0x97,0x27,0x4b,0x96,0x95,0x33,0xfe,0xbf,0xee,0x66,0xd8,0x29,0x9f,0x31,0x52,0x8b,0x5f,0x1a,0x02,0x7d,0xb2,0xce,0x76,0x19,0x29, +0x5d,0x44,0x54,0x02,0x60,0x25,0x20,0x73,0xf5,0x2a,0x4f,0xfd,0x46,0x95,0x50,0x73,0x64,0x19,0x43,0xa7,0x95,0x79,0x9b,0x75,0xe6,0xf1,0x0a,0x36,0xad,0x69,0xa7,0xfe,0xd9,0x66,0xea,0x9f,0x6d,0x66,0xdb,0xaa,0xd6,0x3e,0xcd,0x9a,0x4b,0xab,0x06,0x32,0xf1,0xb6,0xc7,0xc4,0xae,0xf4,0x77,0x47,0x43,0x20,0x6f,0x2b,0x6d,0x97,0xf0,0x1f, +0xcc,0xd8,0x43,0x54,0x02,0xe0,0x6f,0xc0,0x31,0xd2,0x75,0xe4,0x2b,0x3d,0x28,0xc9,0xe0,0x89,0x69,0xca,0x6a,0x92,0x94,0x0d,0x2e,0xa1,0xac,0x3a,0x49,0xba,0x3a,0x49,0x32,0x95,0xa0,0x79,0x73,0x3b,0x2d,0x0d,0x19,0x9a,0x37,0x67,0x68,0x6e,0xc8,0xd0,0xf8,0x72,0x0b,0x4d,0x6b,0xfd,0x3d,0x78,0x94,0xaa,0xae,0x61,0xf2,0x9d,0x4f,0x50, +0x35,0xa1,0xce,0xd0,0x6f,0x60,0x96,0x86,0x40,0x5e,0xfe,0x66,0xbb,0x1c,0x27,0x5d,0x44,0x54,0x16,0x04,0x69,0x94,0x2e,0xa0,0x2f,0x5a,0x1a,0x33,0xac,0x5b,0x14,0xce,0xcd,0x43,0x65,0xc3,0x46,0x31,0xf9,0xd7,0x7f,0x16,0x79,0x9a,0xaf,0xb7,0xd2,0x35,0x23,0xa8,0xbb,0xf7,0x29,0x0d,0x81,0xde,0x89,0xc4,0x31,0x1f,0x85,0x4f,0x01,0x20, +0x02,0x57,0x43,0xa3,0xac,0x62,0x74,0x2d,0x75,0xf3,0x16,0x47,0x7a,0xf0,0x77,0xe8,0x08,0x01,0xa9,0xfb,0x11,0x0a,0x48,0x24,0x8e,0x79,0x0d,0x80,0x28,0x4b,0x24,0x18,0x7e,0xea,0x67,0x39,0xe2,0x91,0x65,0x54,0xec,0x7f,0xb0,0x74,0x35,0xbd,0xa6,0x21,0xd0,0x2b,0x91,0x38,0xe6,0x35,0x00,0x22,0x2a,0x35,0x78,0x28,0x87,0xdd,0xf2,0x10, +0x13,0x7e,0xfa,0x20,0xa9,0x41,0x43,0xa4,0xcb,0xc9,0x9b,0x86,0xc0,0x3e,0x45,0xe2,0x98,0x8f,0x4a,0x00,0x44,0xe2,0x7c,0x28,0x2a,0x86,0xce,0x38,0x9b,0xa3,0xe7,0xbf,0xcc,0xb0,0x19,0x9f,0x92,0x2e,0xc5,0x17,0x0d,0x81,0x1e,0x45,0xe2,0x98,0x8f,0x4a,0x00,0xec,0x2f,0x5d,0x80,0xb4,0x44,0x32,0x49,0xcd,0xf4,0x33,0xa8,0x9b,0xb7,0x98, +0xc3,0x7f,0xf6,0x5b,0x52,0x83,0x87,0x4a,0x97,0x64,0x84,0x86,0x40,0xb7,0x22,0x71,0xcc,0x8b,0x7f,0x0c,0xe8,0x58,0x5c,0x83,0xd0,0x1e,0x81,0x51,0x90,0x2c,0x2b,0x67,0xc4,0x99,0x33,0x39,0xe0,0xe2,0xab,0xe9,0x77,0x90,0x25,0x5d,0x4e,0x60,0xf4,0x23,0xc2,0x2e,0x5d,0x93,0xdb,0x19,0x4b,0x8c,0x68,0x00,0x38,0x16,0xd7,0x21,0xb0,0x37, +0xa0,0xb4,0x54,0x75,0x0d,0xd5,0x47,0x9d,0xc8,0xe0,0x63,0x3f,0x4a,0xcd,0x47,0xcf,0x14,0x7b,0x88,0x27,0x6c,0x1a,0x02,0x5d,0xba,0x2e,0xb7,0x47,0xa6,0x08,0xb1,0x00,0x70,0x2c,0x66,0x03,0x32,0x4b,0xd6,0x98,0x92,0x48,0xf4,0xfa,0x21,0x98,0x44,0x49,0x09,0x55,0xe3,0xeb,0xa8,0x3e,0xf6,0xa3,0x54,0x1d,0x3a,0xd9,0xfb,0xd9,0x8e,0x36, +0xf6,0xfc,0xde,0xae,0xfe,0x5a,0xba,0xf8,0x3e,0x12,0x09,0x12,0x25,0x25,0x24,0x52,0x69,0x92,0xa5,0x29,0xef,0x6b,0x2a,0x9d,0xfb,0xba,0xc7,0xbf,0xef,0xf1,0xff,0x25,0x96,0x09,0x03,0x0d,0x81,0x6e,0xcc,0x96,0xda,0x21,0x58,0x24,0x00,0x1c,0x8b,0x9b,0x80,0xab,0x25,0xfa,0x56,0x9e,0x44,0x32,0x49,0xa2,0x53,0x28,0x54,0x1f,0x3d,0x9d, +0x09,0x3f,0x99,0x47,0xa2,0x24,0xf8,0x7b,0xc3,0x34,0x04,0xba,0x74,0x93,0xed,0x12,0xfa,0x93,0x5d,0xa1,0x07,0x80,0x63,0x71,0x0b,0x70,0x45,0xd8,0xfd,0xaa,0x7d,0xab,0xb1,0x3f,0xc1,0xe1,0xb7,0xfe,0x56,0x43,0x40,0xce,0x2d,0xb6,0xcb,0xd7,0xc2,0xec,0x30,0xb4,0x00,0x70,0x2c,0x12,0xc0,0xcf,0x81,0x2f,0x85,0xd5,0xa7,0xca,0x9f,0x86, +0x80,0xb8,0x5f,0x00,0x5f,0xb1,0xdd,0x7c,0x9f,0x11,0xed,0x9b,0x50,0x02,0xc0,0xb1,0x48,0x02,0xbf,0x04,0x2e,0x0d,0xa3,0x3f,0xe5,0x8f,0x86,0x80,0xb8,0x3b,0x80,0xcb,0xc2,0x08,0x81,0xc0,0x03,0x20,0x37,0xf8,0xef,0x02,0x2e,0x0c,0xba,0x2f,0x65,0x8e,0x86,0x80,0xb8,0xb9,0xc0,0x25,0xb6,0x4b,0xfe,0x9b,0x42,0xe4,0x21,0xd0,0x00,0x70, +0x2c,0x4a,0x80,0xbb,0x81,0xf3,0x83,0xec,0x47,0x05,0x43,0x43,0x40,0xdc,0xfd,0xc0,0x85,0xb6,0x4b,0x60,0x1b,0x58,0x06,0x16,0x00,0x8e,0x45,0x29,0xde,0x2f,0x10,0x8d,0x65,0x6b,0x54,0x9f,0x68,0x08,0x88,0xfb,0x0d,0x70,0x81,0xed,0xd2,0x16,0x44,0xe3,0x81,0x04,0x80,0x63,0x91,0x02,0x1e,0x04,0x3e,0x19,0x44,0xfb,0x2a,0x5c,0x1a,0x02, +0xe2,0x1e,0x01,0xce,0xb5,0x5d,0x8c,0x6f,0x5a,0x61,0x3c,0x00,0x1c,0x8b,0x34,0xf0,0x30,0x70,0x86,0xe9,0xb6,0x95,0x1c,0x0d,0x01,0x71,0x8f,0x02,0x9f,0xb1,0x5d,0x8c,0x6e,0x5a,0x61,0x34,0x00,0x1c,0x8b,0x32,0xe0,0x77,0xc0,0xa9,0x26,0xdb,0x55,0xd1,0xa0,0x21,0x20,0x6e,0x3e,0x70,0xb6,0xed,0xd2,0x6c,0xaa,0x41,0x63,0x01,0x90,0xdb, +0xe4,0xf3,0xf7,0xc0,0xc7,0x4c,0xb5,0xa9,0xa2,0x47,0x43,0x40,0xdc,0x42,0xe0,0x4c,0xdb,0x65,0xa7,0x89,0xc6,0x8c,0x04,0x80,0x63,0xd1,0x0f,0xf8,0x03,0x30,0xdd,0x44,0x7b,0x2a,0xda,0x34,0x04,0xc4,0x3d,0x09,0x9c,0x6e,0xbb,0xf8,0xde,0xbe,0xca,0x77,0x00,0x38,0x16,0x95,0x78,0x53,0x93,0x68,0xad,0x53,0xad,0x02,0xa5,0x21,0x20,0x6e, +0x11,0xf0,0x71,0xdb,0xc5,0xd7,0xbe,0xf6,0xbe,0x02,0xc0,0xb1,0x18,0x00,0xfc,0x09,0x38,0xd6,0x4f,0x3b,0xaa,0x30,0x69,0x08,0x88,0x5b,0x02,0x9c,0x62,0xbb,0x6c,0xeb,0x6b,0x03,0x7d,0x0e,0x00,0xc7,0x62,0x20,0xf0,0x04,0x70,0x54,0x5f,0xdb,0x50,0x85,0x4f,0x43,0x40,0xdc,0x3f,0x80,0x19,0xb6,0xcb,0x96,0xbe,0xfc,0xb0,0x9f,0x25,0xc1, +0xc6,0xa0,0x83,0x3f,0xf6,0x36,0x3a,0x8f,0xf2,0xd2,0x57,0x3f,0x45,0xb6,0x3d,0x90,0xfb,0x54,0x3e,0x40,0x97,0x17,0xeb,0xd2,0x51,0x78,0x63,0xb1,0x4f,0xfc,0x9e,0x02,0xb8,0xc0,0x58,0x3f,0x6d,0xa8,0xe2,0xa0,0x33,0x01,0x31,0xae,0xed,0x32,0xae,0xaf,0x3f,0xec,0x77,0x51,0xd0,0xdf,0xf8,0xfc,0x79,0x55,0x24,0x74,0x26,0x20,0xc6,0xd7, +0x18,0xf4,0x1b,0x00,0x0f,0xf8,0xfc,0x79,0x55,0x44,0x34,0x04,0x44,0xf8,0x1a,0x83,0xbe,0x02,0xc0,0x76,0xf9,0x3f,0xe0,0x5f,0x7e,0xda,0x50,0xc5,0x25,0xec,0x10,0x18,0x79,0x56,0xac,0x9f,0x32,0x7f,0xc9,0x76,0x59,0xe9,0xa7,0x01,0x13,0xfb,0x02,0x3c,0x68,0xa0,0x0d,0x55,0x44,0xc2,0x0c,0x81,0x4c,0xab,0xd1,0x5b,0xe3,0x0b,0x8d,0xef, +0xb1,0xa7,0x01,0xa0,0x02,0x11,0x56,0x08,0x64,0x35,0x00,0x7c,0xf1,0x1d,0x00,0xb6,0xcb,0xeb,0xc0,0x3f,0xfd,0xb6,0xa3,0x8a,0x4f,0x18,0x21,0x10,0xe3,0x19,0xc0,0x32,0xdb,0xe5,0x0d,0xbf,0x8d,0x98,0xda,0x1a,0x4c,0x67,0x01,0xaa,0x4b,0x41,0x87,0x40,0xb6,0xd5,0xf8,0x23,0xf2,0x85,0xc2,0xc8,0x98,0x33,0x15,0x00,0xbf,0x81,0x70,0x56, +0x31,0x55,0x85,0x27,0xc8,0x10,0x88,0xe9,0x0c,0x20,0x8b,0xa1,0x8f,0xe0,0x8d,0x04,0x80,0xed,0xf2,0x2e,0xde,0x7d,0xc9,0x4a,0x75,0x29,0xa8,0x10,0x88,0xe9,0x35,0x80,0x67,0x6c,0x97,0x35,0x26,0x1a,0x32,0xb9,0x3b,0xb0,0x9e,0x06,0xa8,0x1e,0x05,0x11,0x02,0x31,0x9d,0x01,0x18,0x1b,0x6b,0x26,0x03,0xe0,0x61,0x08,0x6e,0xf5,0x52,0x55, +0x1c,0x4c,0x87,0x40,0xb6,0x2d,0x76,0xd7,0x00,0xda,0xf1,0xc6,0x9a,0x11,0xc6,0x02,0xc0,0x76,0xd9,0x00,0x3c,0x65,0xaa,0x3d,0x55,0xbc,0x4c,0x86,0x40,0x0c,0x67,0x00,0x4f,0xda,0x2e,0xf5,0xa6,0x1a,0x33,0x39,0x03,0x00,0xb8,0xd3,0x70,0x7b,0xaa,0x48,0x99,0x0a,0x81,0x18,0x5e,0x03,0xb8,0xcb,0x64,0x63,0xa6,0x03,0xe0,0x21,0xe0,0x55, +0xc3,0x6d,0xaa,0x22,0x65,0x22,0x04,0x32,0x2d,0xb1,0x0a,0x80,0x57,0xf1,0xc6,0x98,0x31,0x46,0x03,0x20,0xb7,0x8d,0xd1,0x2c,0x93,0x6d,0xaa,0xe2,0xe6,0x37,0x04,0x62,0x76,0x0d,0xe0,0x7a,0xd3,0x5b,0x85,0x99,0x9e,0x01,0x00,0xcc,0x03,0x56,0x05,0xd0,0xae,0x2a,0x52,0x7e,0x42,0x20,0x46,0xa7,0x00,0xab,0x08,0xe0,0xe9,0x5b,0xe3,0x01, +0x90,0xdb,0xc7,0x4c,0x67,0x01,0x2a,0x2f,0x7d,0x0d,0x81,0x18,0x5d,0x04,0xbc,0x3e,0x88,0x3d,0x02,0x83,0x98,0x01,0x80,0xb7,0x27,0xe0,0xeb,0x01,0xb5,0xad,0x8a,0x54,0x5f,0x42,0x20,0x26,0x01,0xf0,0x3a,0xde,0x98,0x32,0x2e,0x90,0x00,0xc8,0x6d,0x64,0x38,0x3b,0x88,0xb6,0x55,0x71,0xcb,0x37,0x04,0x62,0x72,0x0a,0x30,0x2b,0xa8,0x1d, +0x82,0x83,0x9a,0x01,0x00,0xdc,0x03,0xac,0x0e,0xb0,0x7d,0x55,0xa4,0xf2,0x09,0x81,0x18,0x3c,0x0c,0xf4,0x06,0x70,0x6f,0x50,0x8d,0x07,0x16,0x00,0x3a,0x0b,0x50,0x7e,0xf4,0x36,0x04,0x62,0x70,0x0a,0x30,0x3b,0xa8,0xad,0xc1,0x21,0xd8,0x19,0x00,0xc0,0xdd,0xc0,0x5b,0x01,0xf7,0xa1,0x8a,0x54,0x6f,0x42,0xa0,0xc8,0x03,0xe0,0x4d,0xbc, +0x99,0x74,0x60,0x02,0x0d,0x80,0xdc,0x7e,0xe6,0x37,0x04,0xd9,0x87,0x2a,0x6e,0xfb,0x0a,0x81,0x22,0xbf,0x06,0x70,0x43,0x6e,0x0c,0x05,0x26,0xe8,0x19,0x00,0xc0,0xaf,0x81,0x77,0x42,0xe8,0x47,0x15,0xa9,0x9e,0x42,0xa0,0x88,0x6f,0x04,0x7a,0x1b,0x6f,0xec,0x04,0x2a,0xf0,0x00,0xb0,0x5d,0x5a,0x80,0x39,0x41,0xf7,0xa3,0x8a,0x5b,0x77, +0x21,0x50,0xc4,0xa7,0x00,0x73,0x82,0x7e,0xf7,0x87,0x70,0x66,0x00,0xe0,0x3d,0x24,0xa4,0xb3,0x00,0xe5,0x4b,0x57,0x21,0x50,0xa4,0x33,0x80,0x77,0x08,0xe9,0xc1,0xba,0x50,0x02,0xc0,0x76,0x69,0x06,0xbe,0x1c,0x46,0x5f,0xaa,0xb8,0x75,0x0e,0x81,0x6c,0x7b,0x3b,0xd9,0xf6,0xa2,0x5c,0x82,0xe2,0x4b,0xb9,0x99,0x73,0xe0,0xc2,0x9a,0x01, +0x60,0xbb,0x3c,0x4e,0x80,0x9f,0x67,0xaa,0xf8,0xe8,0x08,0x81,0xf6,0x9d,0x3b,0xa4,0x4b,0x09,0xc2,0x3d,0xb6,0xcb,0xfc,0xb0,0x3a,0xf3,0xb5,0x39,0x68,0xbe,0x1c,0x8b,0x6a,0xe0,0x65,0x60,0x64,0x98,0xfd,0xaa,0xe2,0x34,0xf8,0xb8,0x93,0xd8,0xbc,0xe4,0xcf,0xd2,0x65,0x98,0xb4,0x16,0x98,0x60,0xbb,0x34,0x86,0xd5,0x61,0xa8,0x01,0x00, +0xe0,0x58,0x9c,0x06,0xfc,0x21,0xec,0x7e,0x95,0x2a,0x00,0xa7,0xe7,0x66,0xca,0xa1,0x09,0xed,0x14,0xa0,0x83,0x9e,0x0a,0x28,0xd5,0xa5,0x7b,0xc2,0x1e,0xfc,0x20,0x10,0x00,0x39,0x57,0x02,0xef,0x09,0xf5,0xad,0x54,0xd4,0xac,0xc5,0x1b,0x13,0xa1,0x13,0x09,0x00,0xdb,0xa5,0x01,0xf8,0x82,0x44,0xdf,0x4a,0x45,0xd0,0x65,0x61,0x9e,0xf7, +0x77,0x26,0x35,0x03,0xd0,0x53,0x01,0xa5,0x3c,0x22,0x53,0xff,0x0e,0x62,0x01,0x90,0xa3,0xa7,0x02,0x2a,0xce,0xc4,0xa6,0xfe,0x1d,0x44,0x03,0x20,0x77,0x2a,0x70,0x99,0x64,0x0d,0x4a,0x09,0x12,0x9b,0xfa,0x77,0x90,0x9e,0x01,0x60,0xbb,0xfc,0x01,0xb8,0x4f,0xba,0x0e,0xa5,0x42,0x76,0xaf,0xe4,0xd4,0xbf,0x83,0x78,0x00,0xe4,0x5c,0x81, +0x9e,0x0a,0xa8,0xf8,0x78,0x0f,0xe1,0xa9,0x7f,0x87,0x48,0x04,0x40,0xee,0x54,0x60,0x26,0x04,0xb7,0xf2,0x89,0x52,0x11,0xd1,0x06,0xcc,0xcc,0x1d,0xf3,0xe2,0x22,0x11,0x00,0x00,0xb6,0xcb,0x5f,0x80,0x2f,0x49,0xd7,0xa1,0x54,0xc0,0xbe,0x98,0x3b,0xd6,0x23,0x21,0x32,0x01,0x00,0x60,0xbb,0xfc,0x0a,0x5d,0x47,0x50,0x15,0xaf,0x59,0xb6, +0x1b,0xad,0xfd,0x33,0x23,0x15,0x00,0x39,0xdf,0xc7,0xdb,0x5d,0x48,0xa9,0x62,0x72,0xbf,0xed,0xf2,0x7d,0xe9,0x22,0xf6,0x14,0xb9,0x00,0xb0,0x5d,0xb2,0xc0,0xc5,0xc0,0x22,0xa1,0x12,0xb6,0x00,0xbf,0x03,0x5e,0x10,0xea,0x5f,0x99,0xf7,0x02,0xde,0xdf,0xe9,0x16,0xa1,0xfe,0xff,0x8a,0x77,0x4c,0x47,0x4e,0xe4,0x02,0x00,0xde,0x5f,0x40, +0xe4,0x4c,0xe0,0x95,0x10,0xba,0xcb,0x02,0xff,0xc4,0xdb,0xce,0xec,0x78,0xa0,0xc6,0x76,0x39,0x1b,0x98,0x06,0x5c,0x0b,0xc1,0x2f,0xcb,0xa4,0x02,0xd3,0x0a,0xfc,0x10,0x38,0x32,0xf7,0x77,0x5a,0x83,0xf7,0x77,0x3c,0x0b,0xef,0xef,0x3c,0x1b,0x42,0x0d,0xaf,0x00,0x67,0x85,0xb5,0xc0,0x47,0xbe,0x42,0x7f,0x1c,0x38,0x1f,0x8e,0x45,0x2d, +0xb0,0x14,0x18,0x66,0xb8,0xe9,0xf5,0xc0,0x13,0xb9,0x3f,0x0b,0x6d,0x97,0x8d,0x3d,0xd4,0x30,0x19,0x98,0x0b,0x4c,0x32,0x5c,0x83,0x0a,0xd6,0x0b,0xc0,0x45,0xb6,0xcb,0x8b,0xdd,0x7d,0x83,0x63,0x31,0x14,0x38,0x09,0x38,0x19,0xf8,0x18,0x30,0xdc,0x70,0x0d,0xeb,0x81,0xa3,0x6d,0x97,0x37,0x0d,0xb7,0x6b,0x4c,0xa4,0x03,0x00,0xc0,0xb1, +0x98,0x06,0x3c,0x05,0xf4,0xf3,0xd1,0x4c,0x2b,0xb0,0x04,0x6f,0xc0,0x2f,0x00,0x5e,0xcc,0x9d,0x6a,0xf4,0xb6,0x86,0x14,0xf0,0x3d,0xe0,0xbb,0x40,0xca,0x47,0x1d,0x2a,0x78,0xad,0x78,0xef,0xf0,0xb3,0xf3,0x59,0x54,0xd3,0xb1,0x48,0x00,0x93,0x81,0x19,0x78,0x81,0x70,0x2c,0xfe,0xfe,0xae,0x9b,0x80,0x13,0x6c,0x97,0x65,0x3e,0xda,0x08, +0x5c,0xe4,0x03,0x00,0xc0,0xb1,0xf8,0x04,0xde,0x39,0x5c,0x3e,0xa7,0x2c,0x6f,0xb0,0x7b,0xc0,0x3f,0x65,0xbb,0x6c,0x33,0x50,0xc7,0x64,0xbc,0xcd,0x4e,0x26,0xfa,0x6d,0x4b,0x05,0xe2,0x45,0xbc,0x77,0x7d,0xdf,0xd7,0x6f,0x1c,0x8b,0x2a,0x60,0x3a,0x5e,0x20,0xcc,0x00,0x0e,0xce,0xe3,0xc7,0x33,0x78,0xd3,0xfe,0xc7,0xfc,0xd6,0x11,0xb4, +0x82,0x08,0x00,0x00,0xc7,0xe2,0x4a,0xe0,0xe6,0x1e,0xbe,0x65,0x07,0xf0,0x34,0xde,0x80,0x7f,0xc2,0x76,0x59,0x15,0x50,0x1d,0x29,0xbc,0x4f,0x2a,0xbe,0x0b,0x94,0x06,0xd1,0x87,0xca,0x5b,0xc7,0x36,0x74,0xd7,0x07,0xb5,0x94,0xb6,0x63,0x31,0x96,0xdd,0xb3,0x83,0x13,0x80,0xfe,0x3d,0x7c,0xfb,0x15,0xb6,0xcb,0xad,0x41,0xd4,0x61,0x5a, +0xc1,0x04,0x00,0x80,0x63,0x71,0x33,0x1f,0xbc,0x85,0xf2,0x25,0x72,0x03,0x1e,0x58,0x1c,0xe6,0x85,0x16,0xc7,0xa2,0x0e,0xef,0xda,0xc0,0xe1,0x61,0xf5,0xa9,0xba,0xb4,0x02,0xef,0x5d,0xff,0xf9,0xb0,0x3a,0x74,0x2c,0xd2,0x78,0x17,0x13,0x3b,0x02,0xa1,0xf3,0x31,0x70,0xb3,0xed,0x72,0x55,0x58,0xb5,0xf8,0x55,0x68,0x01,0x90,0xc4,0xbb, +0x32,0xbf,0x1a,0xef,0x5d,0x7e,0xad,0x70,0x3d,0x69,0xe0,0x9b,0xc0,0xd5,0x40,0xb5,0x64,0x2d,0x31,0xd4,0x00,0xdc,0x04,0xdc,0x18,0xc6,0x06,0x1a,0x3d,0x71,0x2c,0x46,0xe1,0x85,0x41,0x2d,0x70,0xad,0xed,0x92,0x91,0xac,0x27,0x1f,0x05,0x15,0x00,0x51,0xe5,0x58,0x0c,0x00,0xbe,0x0a,0x5c,0x05,0x0c,0x11,0x2e,0xa7,0xd8,0x6d,0x02,0x7e, +0x0a,0xdc,0x6a,0xbb,0x6c,0x95,0x2e,0xa6,0xd0,0x69,0x00,0x18,0xe4,0x58,0x54,0x02,0x97,0xe3,0xcd,0x08,0x86,0x0a,0x97,0x53,0x6c,0xea,0x81,0x1f,0x03,0x3f,0xb7,0x5d,0xb6,0x4b,0x17,0x53,0x2c,0x34,0x00,0x02,0xe0,0x58,0xf4,0xc7,0x7b,0xb0,0xe9,0x1b,0x98,0xff,0x6c,0x39,0x6e,0xd6,0x03,0x37,0x02,0xb7,0xd9,0x2e,0x4d,0xd2,0xc5,0x14, +0x1b,0x0d,0x80,0x00,0x39,0x16,0x15,0x78,0x2b,0x1e,0x7d,0x0b,0xdd,0x0c,0x25,0x5f,0xef,0x01,0xff,0x0d,0xfc,0xd2,0x76,0xd9,0x29,0x5d,0x4c,0xb1,0xd2,0x00,0x08,0x81,0x63,0x51,0x0e,0xfc,0x3b,0xf0,0x6d,0x60,0x3f,0xe1,0x72,0xa2,0x6e,0x0d,0xde,0x6e,0xd2,0xbf,0xb2,0x5d,0x76,0x49,0x17,0x53,0xec,0x34,0x00,0x42,0xe4,0x58,0x7c,0x1c, +0xe4,0x97,0x81,0x8a,0xb8,0x8f,0xdb,0x2e,0x7f,0x94,0x2e,0x22,0x2e,0x22,0xf9,0x30,0x50,0x11,0x5b,0x84,0xae,0x7a,0xd4,0x93,0x36,0x60,0xb1,0x74,0x11,0x71,0xa2,0x01,0x10,0xa2,0xdc,0xed,0xc8,0xcf,0x49,0xd7,0x11,0x61,0xff,0x34,0x71,0xcb,0xb6,0xea,0x3d,0x0d,0x80,0xf0,0x3d,0x29,0x5d,0x40,0x84,0xe9,0x6b,0x13,0x32,0x0d,0x80,0xf0, +0xe9,0x41,0xde,0x3d,0x7d,0x6d,0x42,0xa6,0x01,0x10,0xbe,0x25,0x10,0xcd,0xc5,0x21,0x84,0x35,0x03,0x7f,0x93,0x2e,0x22,0x6e,0x34,0x00,0x42,0x96,0xfb,0x4c,0x7b,0xa9,0x74,0x1d,0x11,0xb4,0x54,0x3f,0xef,0x0f,0x9f,0x06,0x80,0x0c,0x9d,0xea,0xee,0x4d,0x5f,0x13,0x01,0x1a,0x00,0x32,0xf4,0x60,0xdf,0x9b,0xbe,0x26,0x02,0x34,0x00,0x64, +0xfc,0x03,0xf4,0xbe,0xf6,0x4e,0x9a,0xf0,0x5e,0x13,0x15,0x32,0x0d,0x00,0x01,0xb9,0x85,0x4b,0x96,0x48,0xd7,0x11,0x21,0xcf,0x48,0x3f,0xd3,0x1f,0x57,0x1a,0x00,0x72,0x74,0xca,0xbb,0x9b,0xbe,0x16,0x42,0x34,0x00,0xe4,0xe8,0x41,0xbf,0x9b,0xbe,0x16,0x42,0x34,0x00,0xe4,0x3c,0x07,0xba,0xa2,0x0d,0xde,0x6e,0x3d,0xcb,0xa5,0x8b,0x88, +0x2b,0x0d,0x00,0x21,0xb6,0x4b,0x3b,0x72,0xdb,0x9f,0x45,0xc9,0xa2,0xdc,0x6b,0xa1,0x04,0x68,0x00,0xc8,0xd2,0xa9,0xaf,0xbe,0x06,0xa2,0x34,0x00,0x64,0xe9,0xc1,0xaf,0xaf,0x81,0x28,0x0d,0x00,0x59,0x2b,0xf0,0x56,0xb9,0x8d,0xab,0x8d,0x78,0x7b,0x3b,0x28,0x21,0x1a,0x00,0x82,0x72,0xfb,0x13,0x3e,0x2d,0x5d,0x87,0xa0,0xa7,0xf3,0xd9, +0xa3,0x51,0x99,0xa7,0x01,0x20,0x2f,0xce,0x53,0xe0,0x38,0xff,0xee,0x91,0xa0,0x01,0x20,0x2f,0xce,0x83,0x20,0xce,0xbf,0x7b,0x24,0xe8,0xa2,0xa0,0x11,0xe0,0x58,0xac,0x25,0x7e,0xcb,0x86,0xaf,0xb5,0x5d,0x5d,0x21,0x59,0x9a,0xce,0x00,0xa2,0xe1,0x29,0xe9,0x02,0x04,0xc4,0xf1,0x77,0x8e,0x1c,0x0d,0x80,0x68,0x88,0xe3,0x54,0x38,0x8e, +0xbf,0x73,0xe4,0x68,0x00,0x44,0x43,0x1c,0x07,0x83,0x23,0x5d,0x80,0xd2,0x00,0x88,0x04,0xdb,0x65,0x35,0xf0,0x28,0xde,0x7d,0xf1,0xc5,0xae,0x11,0x78,0xd4,0x76,0x79,0x4b,0xba,0x10,0xa5,0x17,0x01,0x23,0xc5,0xb1,0x48,0xe0,0xed,0x31,0x5f,0xb7,0xc7,0x9f,0x42,0xdd,0x69,0x78,0x03,0xf0,0x3c,0xde,0xc3,0x3e,0xcb,0x81,0xe5,0xb6,0xcb, +0x1b,0xb2,0x25,0xa9,0xce,0x34,0x00,0x0a,0x80,0x63,0x31,0x1a,0x2f,0x08,0xa6,0xb0,0x3b,0x14,0x46,0x8b,0x16,0xb5,0xb7,0x77,0xe9,0x34,0xd0,0xf1,0x06,0xfb,0x1a,0xd9,0x92,0xd4,0xbe,0x68,0x00,0x14,0x28,0xc7,0x62,0x28,0xbb,0xc3,0xa0,0x16,0x18,0x94,0xfb,0x53,0xdd,0xe9,0xeb,0x40,0xa0,0xd4,0x67,0x57,0x6d,0x78,0xa7,0x26,0x0d,0x78, +0xd3,0xf7,0x8e,0xaf,0x8d,0xc0,0x6a,0x76,0x0f,0xf6,0x7a,0x9f,0xfd,0x28,0x01,0x1a,0x00,0x45,0xce,0xb1,0xa8,0xe4,0x83,0xa1,0xb0,0x67,0x50,0xc0,0xde,0x03,0xfb,0xfd,0xc1,0x6e,0xbb,0x6c,0x0f,0xbb,0x66,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29,0xa5,0x94,0x52,0x4a,0x29, +0xd5,0x1b,0xff,0x0f,0x5c,0x56,0xd9,0x0b,0x64,0x90,0x3b,0x82,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82, +}; + +read_only global String8 df_g_icon_file_bytes = {df_g_icon_file_bytes__data, sizeof(df_g_icon_file_bytes__data)}; C_LINKAGE_END #endif // DF_GFX_META_H diff --git a/src/eval/eval_compiler.c b/src/eval/eval_compiler.c index 792d1cb9..d8adf413 100644 --- a/src/eval/eval_compiler.c +++ b/src/eval/eval_compiler.c @@ -952,8 +952,10 @@ eval_irtree_and_type_from_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, E // generate ir tree if (can_generate){ EVAL_IRTree *new_tree = l.tree; + EVAL_EvalMode mode = l.mode; if (l_resolve){ new_tree = eval_irtree_resolve_to_value(arena, graph, rdi, l.mode, new_tree, l_restype); + mode = EVAL_EvalMode_Addr; } if (r_off != 0){ EVAL_IRTree *const_tree = eval_irtree_const_u(arena, r_off); @@ -963,7 +965,7 @@ eval_irtree_and_type_from_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, E // fill result result.tree = new_tree; result.type_key = r_type; - result.mode = l.mode; + result.mode = mode; } }break; } diff --git a/src/eval/eval_parser.c b/src/eval/eval_parser.c index 71bf8a1b..bd0379f7 100644 --- a/src/eval/eval_parser.c +++ b/src/eval/eval_parser.c @@ -414,6 +414,14 @@ eval_token_array_from_text(Arena *arena, String8 text) eval_token_chunk_list_push(scratch.arena, &tokens, 256, &token); } + // rjf: symbolic strings matching `--` mean the remainder of the string + // is reserved for external usage. the rest of the stream should not + // be tokenized. + else if(idx == active_token_start_idx+2 && text.str[active_token_start_idx] == '-' && text.str[active_token_start_idx+1] == '-') + { + break; + } + // rjf: if we got a symbol string of N>1 characters, then we need to // apply the maximum-munch rule, and produce M<=N tokens, where each // formed token is the maximum size possible, given the legal diff --git a/src/file_stream/file_stream.c b/src/file_stream/file_stream.c index e1b411e5..6f1e63be 100644 --- a/src/file_stream/file_stream.c +++ b/src/file_stream/file_stream.c @@ -10,6 +10,7 @@ fs_init(void) Arena *arena = arena_alloc(); fs_shared = push_array(arena, FS_Shared, 1); fs_shared->arena = arena; + fs_shared->change_gen = 1; fs_shared->slots_count = 1024; fs_shared->stripes_count = os_logical_core_count(); fs_shared->slots = push_array(arena, FS_Slot, fs_shared->slots_count); @@ -33,6 +34,15 @@ fs_init(void) fs_shared->detector_thread = os_launch_thread(fs_detector_thread__entry_point, 0, 0); } +//////////////////////////////// +//~ rjf: Change Generation + +internal U64 +fs_change_gen(void) +{ + return ins_atomic_u64_eval(&fs_shared->change_gen); +} + //////////////////////////////// //~ rjf: Cache Interaction @@ -220,6 +230,10 @@ fs_streamer_thread__entry_point(void *p) } if(node != 0) { + if(node->timestamp != 0) + { + ins_atomic_u64_inc_eval(&fs_shared->change_gen); + } if(post_props.modified == pre_props.modified) { node->timestamp = post_props.modified; diff --git a/src/file_stream/file_stream.h b/src/file_stream/file_stream.h index 078b3547..66f88f1f 100644 --- a/src/file_stream/file_stream.h +++ b/src/file_stream/file_stream.h @@ -38,6 +38,7 @@ typedef struct FS_Shared FS_Shared; struct FS_Shared { Arena *arena; + U64 change_gen; // rjf: path info cache U64 slots_count; @@ -71,6 +72,11 @@ global FS_Shared *fs_shared = 0; internal void fs_init(void); +//////////////////////////////// +//~ rjf: Change Generation + +internal U64 fs_change_gen(void); + //////////////////////////////// //~ rjf: Cache Interaction diff --git a/src/ico/ico.c b/src/ico/ico.c new file mode 100644 index 00000000..7ea8904c --- /dev/null +++ b/src/ico/ico.c @@ -0,0 +1,2 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) diff --git a/src/ico/ico.h b/src/ico/ico.h new file mode 100644 index 00000000..18df7b54 --- /dev/null +++ b/src/ico/ico.h @@ -0,0 +1,43 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef ICO_H +#define ICO_H + +//////////////////////////////// +//~ rjf: ICO File Format Types + +#pragma pack(push, 1) + +typedef struct ICO_Header ICO_Header; +struct ICO_Header +{ + U16 reserved_padding; // must be 0 + U16 image_type; // if 1 -> ICO, if 2 -> CUR + U16 num_images; +}; + +typedef struct ICO_Entry ICO_Entry; +struct ICO_Entry +{ + U8 image_width_px; + U8 image_height_px; + U8 num_colors; + U8 reserved_padding; // should be 0 + union + { + U16 ico_color_planes; // in ICO + U16 cur_hotspot_x_px; // in CUR + }; + union + { + U16 ico_bits_per_pixel; // in ICO + U16 cur_hotspot_y_px; // in CUR + }; + U32 image_data_size; + U32 image_data_off; +}; + +#pragma pack(pop) + +#endif // ICO_H diff --git a/src/lib_raddbgi_format/raddbgi_format.h b/src/lib_raddbgi_format/raddbgi_format.h index 16a03d44..f0bc7b75 100644 --- a/src/lib_raddbgi_format/raddbgi_format.h +++ b/src/lib_raddbgi_format/raddbgi_format.h @@ -300,7 +300,8 @@ typedef enum RDI_DataSectionTagEnum{ #define RDI_DataSectionEncodingXList(X) \ -X(Unpacked, 0) +X(Unpacked, 0)\ +X(LZB, 1) typedef RDI_U32 RDI_DataSectionEncoding; typedef enum RDI_DataSectionEncodingEnum{ diff --git a/src/lib_raddbgi_format/raddbgi_format_parse.c b/src/lib_raddbgi_format/raddbgi_format_parse.c index 4f6e0b4e..3b3c2f61 100644 --- a/src/lib_raddbgi_format/raddbgi_format_parse.c +++ b/src/lib_raddbgi_format/raddbgi_format_parse.c @@ -537,23 +537,23 @@ rdi_first_voff_from_proc(RDI_Parsed *p, RDI_U32 proc_id){ RDI_PROC void* rdi_data_from_dsec(RDI_Parsed *parsed, RDI_U32 idx, RDI_U32 item_size, RDI_DataSectionTag expected_tag, - RDI_U64 *count_out){ + RDI_U64 *count_out) +{ void *result = 0; RDI_U32 count_result = 0; - - // TODO(allen): need a version of this that works with encodings other than "Unpacked" - - if (0 < idx && idx < parsed->dsec_count){ + if(0 < idx && idx < parsed->dsec_count) + { RDI_DataSection *ds = parsed->dsecs + idx; - if (ds->tag == expected_tag){ - RDI_U64 opl = ds->off + ds->encoded_size; - if (opl <= parsed->raw_data_size){ - count_result = ds->encoded_size/item_size; + if(ds->tag == expected_tag) + { + RDI_U64 encoded_opl = ds->off + ds->encoded_size; + if(encoded_opl <= parsed->raw_data_size) + { + count_result = ds->unpacked_size/item_size; result = (parsed->raw_data + ds->off); } } } - *count_out = count_result; return(result); } diff --git a/src/lib_raddbgi_make/raddbgi_make.c b/src/lib_raddbgi_make/raddbgi_make.c index 11b41166..b3acd4da 100644 --- a/src/lib_raddbgi_make/raddbgi_make.c +++ b/src/lib_raddbgi_make/raddbgi_make.c @@ -1744,11 +1744,13 @@ rdim_bake_section_list_push(RDIM_Arena *arena, RDIM_BakeSectionList *list) } RDI_PROC RDIM_BakeSection * -rdim_bake_section_list_push_new(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx) +rdim_bake_section_list_push_new_unpacked(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx) { RDIM_BakeSection *section = rdim_bake_section_list_push(arena, list); section->data = data; - section->size = size; + section->encoding = RDI_DataSectionEncoding_Unpacked; + section->encoded_size = size; + section->unpacked_size = size; section->tag = tag; section->tag_idx = tag_idx; return section; @@ -2142,7 +2144,7 @@ rdim_bake_top_level_info_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt dst_tli->exe_name_string_idx = rdim_bake_idx_from_string(strings, src_tli->exe_name); dst_tli->exe_hash = src_tli->exe_hash; dst_tli->voff_max = src_tli->voff_max; - rdim_bake_section_list_push_new(arena, §ions, dst_tli, sizeof(*dst_tli), RDI_DataSectionTag_TopLevelInfo, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_tli, sizeof(*dst_tli), RDI_DataSectionTag_TopLevelInfo, 0); return sections; } @@ -2166,7 +2168,7 @@ rdim_bake_binary_section_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt dst->foff_first = src->foff_first; dst->foff_opl = src->foff_opl; } - rdim_bake_section_list_push_new(arena, §ions, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_BinarySections, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_BinarySections, 0); return sections; } @@ -2286,11 +2288,11 @@ rdim_bake_section_list_from_unit(RDIM_Arena *arena, RDIM_Unit *unit) //- rjf: build line info sections // U64 unit_idx = rdim_idx_from_unit(unit); - rdim_bake_section_list_push_new(arena, §ions, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, unit_idx); - rdim_bake_section_list_push_new(arena, §ions, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, unit_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, unit_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, unit_idx); if(unit_cols != 0) { - rdim_bake_section_list_push_new(arena, §ions, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, unit_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, unit_idx); } return sections; @@ -2417,11 +2419,11 @@ rdim_bake_unit_top_level_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt //////////////////////// //- rjf: build line info sections // - rdim_bake_section_list_push_new(arena, §ions, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, dst_idx); - rdim_bake_section_list_push_new(arena, §ions, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, dst_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, dst_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, dst_idx); if(unit_cols != 0) { - rdim_bake_section_list_push_new(arena, §ions, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, dst_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, dst_idx); } //////////////////////// @@ -2439,7 +2441,7 @@ rdim_bake_unit_top_level_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt dst->line_info_col_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineInfoColumns, dst_idx); // TODO(rjf): @u64_to_u32 } } - rdim_bake_section_list_push_new(arena, §ions, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_Units, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_Units, 0); return sections; } @@ -2514,7 +2516,7 @@ rdim_bake_unit_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParams //- rjf: build section RDIM_BakeSectionList sections = {0}; RDI_U64 unit_vmap_size = sizeof(unit_vmap.vmap[0])*(unit_vmap.count+1); - rdim_bake_section_list_push_new(arena, §ions, unit_vmap.vmap, unit_vmap_size, RDI_DataSectionTag_UnitVmap, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, unit_vmap.vmap, unit_vmap_size, RDI_DataSectionTag_UnitVmap, 0); return sections; } @@ -2689,9 +2691,9 @@ rdim_bake_src_file_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMa dst_file->line_map_nums_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapNumbers, dst_file_idx); // TODO(rjf): @u64_to_u32 dst_file->line_map_range_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapRanges, dst_file_idx); // TODO(rjf): @u64_to_u32 dst_file->line_map_voff_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapVoffs, dst_file_idx); // TODO(rjf): @u64_to_u32 - rdim_bake_section_list_push_new(arena, §ions, src_file_line_nums, sizeof(*src_file_line_nums)*src_file_line_count, RDI_DataSectionTag_LineMapNumbers, dst_file_idx); - rdim_bake_section_list_push_new(arena, §ions, src_file_line_ranges, sizeof(*src_file_line_ranges)*(src_file_line_count + 1), RDI_DataSectionTag_LineMapRanges, dst_file_idx); - rdim_bake_section_list_push_new(arena, §ions, src_file_voffs, sizeof(*src_file_voffs)*src_file_voff_count, RDI_DataSectionTag_LineMapVoffs, dst_file_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, src_file_line_nums, sizeof(*src_file_line_nums)*src_file_line_count, RDI_DataSectionTag_LineMapNumbers, dst_file_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, src_file_line_ranges, sizeof(*src_file_line_ranges)*(src_file_line_count + 1), RDI_DataSectionTag_LineMapRanges, dst_file_idx); + rdim_bake_section_list_push_new_unpacked(arena, §ions, src_file_voffs, sizeof(*src_file_voffs)*src_file_voff_count, RDI_DataSectionTag_LineMapVoffs, dst_file_idx); } } } @@ -2699,7 +2701,7 @@ rdim_bake_src_file_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMa //////////////////////////// //- rjf: build section for all source files // - rdim_bake_section_list_push_new(arena, §ions, dst_files, sizeof(RDI_SourceFile)*dst_files_count, RDI_DataSectionTag_SourceFiles, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_files, sizeof(RDI_SourceFile)*dst_files_count, RDI_DataSectionTag_SourceFiles, 0); return sections; } @@ -2775,7 +2777,7 @@ rdim_bake_type_node_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringM //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, type_nodes, sizeof(RDI_TypeNode)*(params->types.total_count+1), RDI_DataSectionTag_TypeNodes, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, type_nodes, sizeof(RDI_TypeNode)*(params->types.total_count+1), RDI_DataSectionTag_TypeNodes, 0); return sections; } @@ -2843,9 +2845,9 @@ rdim_bake_udt_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMapTigh //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, udts, sizeof(RDI_UDT) * (params->udts.total_count+1), RDI_DataSectionTag_UDTs, 0); - rdim_bake_section_list_push_new(arena, §ions, members , sizeof(RDI_Member) * (params->udts.total_member_count+1), RDI_DataSectionTag_Members, 0); - rdim_bake_section_list_push_new(arena, §ions, enum_members, sizeof(RDI_EnumMember) * (params->udts.total_enum_val_count+1), RDI_DataSectionTag_EnumMembers, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, udts, sizeof(RDI_UDT) * (params->udts.total_count+1), RDI_DataSectionTag_UDTs, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, members , sizeof(RDI_Member) * (params->udts.total_member_count+1), RDI_DataSectionTag_Members, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, enum_members, sizeof(RDI_EnumMember) * (params->udts.total_enum_val_count+1), RDI_DataSectionTag_EnumMembers, 0); return sections; } @@ -2887,7 +2889,7 @@ rdim_bake_global_variable_section_list_from_params(RDIM_Arena *arena, RDIM_BakeS //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, global_variables, sizeof(RDI_GlobalVariable)*(params->global_variables.total_count+1), RDI_DataSectionTag_GlobalVariables, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, global_variables, sizeof(RDI_GlobalVariable)*(params->global_variables.total_count+1), RDI_DataSectionTag_GlobalVariables, 0); return sections; } @@ -2918,9 +2920,10 @@ rdim_bake_global_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParam { RDIM_Symbol *global_var = &n->v[chunk_idx]; RDI_U32 global_var_idx = (RDI_U32)rdim_idx_from_symbol(global_var); // TODO(rjf): @u64_to_u32 + RDI_U64 global_var_size = global_var->type ? global_var->type->byte_size : 1; RDI_U64 first = global_var->offset; - RDI_U64 opl = first + global_var->type->byte_size; + RDI_U64 opl = first + global_var_size; key_ptr->key = first; key_ptr->val = marker_ptr; @@ -2966,7 +2969,7 @@ rdim_bake_global_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParam //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, global_vmap.vmap, sizeof(RDI_VMapEntry)*(global_vmap.count+1), RDI_DataSectionTag_GlobalVmap, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, global_vmap.vmap, sizeof(RDI_VMapEntry)*(global_vmap.count+1), RDI_DataSectionTag_GlobalVmap, 0); return sections; } @@ -3008,7 +3011,7 @@ rdim_bake_thread_variable_section_list_from_params(RDIM_Arena *arena, RDIM_BakeS //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, thread_variables, sizeof(RDI_ThreadVariable)*(params->thread_variables.total_count+1), RDI_DataSectionTag_ThreadVariables, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, thread_variables, sizeof(RDI_ThreadVariable)*(params->thread_variables.total_count+1), RDI_DataSectionTag_ThreadVariables, 0); return sections; } @@ -3051,7 +3054,7 @@ rdim_bake_procedure_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringM //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, procedures, sizeof(RDI_Procedure)*(params->procedures.total_count+1), RDI_DataSectionTag_Procedures, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, procedures, sizeof(RDI_Procedure)*(params->procedures.total_count+1), RDI_DataSectionTag_Procedures, 0); return sections; } @@ -3218,11 +3221,11 @@ rdim_bake_scope_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMapTi RDIM_BakeSectionList sections = {0}; RDIM_ProfScope("push all symbol info sections") { - rdim_bake_section_list_push_new(arena, §ions, scopes, sizeof(RDI_Scope) * (params->scopes.total_count+1), RDI_DataSectionTag_Scopes, 0); - rdim_bake_section_list_push_new(arena, §ions, scope_voffs, sizeof(RDI_U64) * (params->scopes.scope_voff_count+1), RDI_DataSectionTag_ScopeVoffData, 0); - rdim_bake_section_list_push_new(arena, §ions, locals, sizeof(RDI_Local) * (params->scopes.local_count+1), RDI_DataSectionTag_Locals, 0); - rdim_bake_section_list_push_new(arena, §ions, location_blocks, sizeof(RDI_LocationBlock) * (params->scopes.location_count+1), RDI_DataSectionTag_LocationBlocks, 0); - rdim_bake_section_list_push_new(arena, §ions, location_data_blob.str, location_data_blob.size, RDI_DataSectionTag_LocationData, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, scopes, sizeof(RDI_Scope) * (params->scopes.total_count+1), RDI_DataSectionTag_Scopes, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, scope_voffs, sizeof(RDI_U64) * (params->scopes.scope_voff_count+1), RDI_DataSectionTag_ScopeVoffData, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, locals, sizeof(RDI_Local) * (params->scopes.local_count+1), RDI_DataSectionTag_Locals, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, location_blocks, sizeof(RDI_LocationBlock) * (params->scopes.location_count+1), RDI_DataSectionTag_LocationBlocks, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, location_data_blob.str, location_data_blob.size, RDI_DataSectionTag_LocationData, 0); } rdim_scratch_end(scratch); return sections; @@ -3280,7 +3283,7 @@ rdim_bake_scope_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParams //- rjf: build sections RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, scope_vmap.vmap, sizeof(RDI_VMapEntry)*(scope_vmap.count+1), RDI_DataSectionTag_ScopeVmap, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, scope_vmap.vmap, sizeof(RDI_VMapEntry)*(scope_vmap.count+1), RDI_DataSectionTag_ScopeVmap, 0); return sections; } @@ -3322,7 +3325,7 @@ rdim_bake_top_level_name_map_section_list_from_params_maps(RDIM_Arena *arena, RD } // rjf: push section for all name maps - rdim_bake_section_list_push_new(arena, §ions, dst_maps, sizeof(RDI_NameMap)*name_map_count, RDI_DataSectionTag_NameMaps, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_maps, sizeof(RDI_NameMap)*name_map_count, RDI_DataSectionTag_NameMaps, 0); return sections; } @@ -3424,8 +3427,8 @@ rdim_bake_name_map_section_list_from_params_kind_map(RDIM_Arena *arena, RDIM_Bak } // rjf: sections for buckets/nodes - rdim_bake_section_list_push_new(arena, §ions, baked_buckets, sizeof(RDI_NameMapBucket)* baked_buckets_count, RDI_DataSectionTag_NameMapBuckets, (RDI_U64)k); - rdim_bake_section_list_push_new(arena, §ions, baked_nodes, sizeof(RDI_NameMapNode) * baked_nodes_count, RDI_DataSectionTag_NameMapNodes, (RDI_U64)k); + rdim_bake_section_list_push_new_unpacked(arena, §ions, baked_buckets, sizeof(RDI_NameMapBucket)* baked_buckets_count, RDI_DataSectionTag_NameMapBuckets, (RDI_U64)k); + rdim_bake_section_list_push_new_unpacked(arena, §ions, baked_nodes, sizeof(RDI_NameMapNode) * baked_nodes_count, RDI_DataSectionTag_NameMapNodes, (RDI_U64)k); } return sections; } @@ -3461,7 +3464,7 @@ rdim_bake_file_path_section_list_from_path_tree(RDIM_Arena *arena, RDIM_BakeStri } } RDIM_BakeSectionList sections = {0}; - rdim_bake_section_list_push_new(arena, §ions, dst_nodes, sizeof(RDI_FilePathNode)*dst_nodes_count, RDI_DataSectionTag_FilePathNodes, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, dst_nodes, sizeof(RDI_FilePathNode)*dst_nodes_count, RDI_DataSectionTag_FilePathNodes, 0); return sections; } @@ -3507,8 +3510,8 @@ rdim_bake_string_section_list_from_string_map(RDIM_Arena *arena, RDIM_BakeString } } } - rdim_bake_section_list_push_new(arena, §ions, str_offs, sizeof(RDI_U32)*(strings->total_count+1), RDI_DataSectionTag_StringTable, 0); - rdim_bake_section_list_push_new(arena, §ions, buf, off_cursor, RDI_DataSectionTag_StringData, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, str_offs, sizeof(RDI_U32)*(strings->total_count+1), RDI_DataSectionTag_StringTable, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, buf, off_cursor, RDI_DataSectionTag_StringData, 0); return sections; } @@ -3530,7 +3533,7 @@ rdim_bake_idx_run_section_list_from_idx_run_map(RDIM_Arena *arena, RDIM_BakeIdxR out_ptr += node->count; } } - rdim_bake_section_list_push_new(arena, §ions, idx_data, sizeof(RDI_U32)*idx_runs->idx_count, RDI_DataSectionTag_IndexRuns, 0); + rdim_bake_section_list_push_new_unpacked(arena, §ions, idx_data, sizeof(RDI_U32)*idx_runs->idx_count, RDI_DataSectionTag_IndexRuns, 0); return sections; } @@ -3591,17 +3594,17 @@ rdim_serialized_strings_from_params_bake_section_list(RDIM_Arena *arena, RDIM_Ba if(src == 0) { continue; } RDI_DataSection *dst = rdi_sections+dst_idx; U64 data_section_off = 0; - if(src->size != 0) + if(src->encoded_size != 0) { rdim_str8_list_push_align(arena, &strings, 8); data_section_off = strings.total_size; - rdim_str8_list_push(arena, &strings, rdim_str8((RDI_U8 *)src->data, src->size)); + rdim_str8_list_push(arena, &strings, rdim_str8((RDI_U8 *)src->data, src->encoded_size)); } dst->tag = src->tag; - dst->encoding = RDI_DataSectionEncoding_Unpacked; + dst->encoding = src->encoding; dst->off = data_section_off; - dst->encoded_size = src->size; - dst->unpacked_size = src->size; + dst->encoded_size = src->encoded_size; + dst->unpacked_size = src->unpacked_size; } rdim_scratch_end(scratch); diff --git a/src/lib_raddbgi_make/raddbgi_make.h b/src/lib_raddbgi_make/raddbgi_make.h index 3cb989f0..6c773aa4 100644 --- a/src/lib_raddbgi_make/raddbgi_make.h +++ b/src/lib_raddbgi_make/raddbgi_make.h @@ -811,7 +811,9 @@ typedef struct RDIM_BakeSection RDIM_BakeSection; struct RDIM_BakeSection { void *data; - RDI_U64 size; + RDI_DataSectionEncoding encoding; + RDI_U64 encoded_size; + RDI_U64 unpacked_size; RDI_DataSectionTag tag; RDI_U64 tag_idx; }; @@ -1153,7 +1155,7 @@ RDI_PROC void rdim_bake_name_map_push(RDIM_Arena *arena, RDIM_BakeNameMap *map, //~ rjf: [Baking Helpers] Data Section List Building Helpers RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push(RDIM_Arena *arena, RDIM_BakeSectionList *list); -RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push_new(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx); +RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push_new_unpacked(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx); RDI_PROC void rdim_bake_section_list_concat_in_place(RDIM_BakeSectionList *dst, RDIM_BakeSectionList *to_push); //////////////////////////////// diff --git a/src/mule/mule_main.cpp b/src/mule/mule_main.cpp index 1260db25..4b56abf3 100644 --- a/src/mule/mule_main.cpp +++ b/src/mule/mule_main.cpp @@ -326,6 +326,9 @@ type_coverage_eval_tests(void){ swea.z = 'z'; } + Struct_With_Embedded_Arrays *swea_ptr = &swea; + int access_via_ptr_member = swea_ptr->x; + Custom_Index_Type custom_index = 42; Custom_Index_Type more_custom_indices[] = { 04,13,22,31,40 diff --git a/src/os/core/os_core.c b/src/os/core/os_core.c index b3cad911..cf96fe1f 100644 --- a/src/os/core/os_core.c +++ b/src/os/core/os_core.c @@ -113,6 +113,24 @@ os_write_data_list_to_file_path(String8 path, String8List list) return good; } +internal B32 +os_append_data_to_file_path(String8 path, String8 data) +{ + B32 good = 0; + if(data.size != 0) + { + OS_Handle file = os_file_open(OS_AccessFlag_Write|OS_AccessFlag_Append, path); + if(!os_handle_match(file, os_handle_zero())) + { + good = 1; + U64 pos = os_properties_from_file(file).size; + os_file_write(file, r1u64(pos, pos+data.size), data.str); + os_file_close(file); + } + } + return good; +} + internal OS_FileID os_id_from_file_path(String8 path) { diff --git a/src/os/core/os_core.h b/src/os/core/os_core.h index ea82c9d2..ea8863da 100644 --- a/src/os/core/os_core.h +++ b/src/os/core/os_core.h @@ -13,8 +13,9 @@ enum OS_AccessFlag_Read = (1<<0), OS_AccessFlag_Write = (1<<1), OS_AccessFlag_Execute = (1<<2), - OS_AccessFlag_ShareRead = (1<<3), - OS_AccessFlag_ShareWrite = (1<<4), + OS_AccessFlag_Append = (1<<3), + OS_AccessFlag_ShareRead = (1<<4), + OS_AccessFlag_ShareWrite = (1<<5), }; //////////////////////////////// @@ -171,6 +172,7 @@ internal String8List os_string_list_from_argcv(Arena *arena, int argc, char **ar internal String8 os_data_from_file_path(Arena *arena, String8 path); internal B32 os_write_data_to_file_path(String8 path, String8 data); internal B32 os_write_data_list_to_file_path(String8 path, String8List list); +internal B32 os_append_data_to_file_path(String8 path, String8 data); internal OS_FileID os_id_from_file_path(String8 path); internal S64 os_file_id_compare(OS_FileID a, OS_FileID b); internal String8 os_string_from_file_range(Arena *arena, OS_Handle file, Rng1U64 range); diff --git a/src/os/core/win32/os_core_win32.c b/src/os/core/win32/os_core_win32.c index 0d13d0e4..b131287f 100644 --- a/src/os/core/win32/os_core_win32.c +++ b/src/os/core/win32/os_core_win32.c @@ -664,6 +664,7 @@ os_file_open(OS_AccessFlags flags, String8 path) if(flags & OS_AccessFlag_ShareRead) {share_mode |= FILE_SHARE_READ;} if(flags & OS_AccessFlag_ShareWrite) {share_mode |= FILE_SHARE_WRITE|FILE_SHARE_DELETE;} if(flags & OS_AccessFlag_Write) {creation_disposition = CREATE_ALWAYS;} + if(flags & OS_AccessFlag_Append) {creation_disposition = OPEN_ALWAYS;} HANDLE file = CreateFileW((WCHAR *)path16.str, access_flags, share_mode, 0, creation_disposition, FILE_ATTRIBUTE_NORMAL, 0); if(file != INVALID_HANDLE_VALUE) { diff --git a/src/os/core/win32/os_core_win32.h b/src/os/core/win32/os_core_win32.h index 3ce6aac4..90794b7a 100644 --- a/src/os/core/win32/os_core_win32.h +++ b/src/os/core/win32/os_core_win32.h @@ -7,22 +7,12 @@ //////////////////////////////// //~ NOTE(allen): Negotiate the windows header include order -#if OS_FEATURE_SOCKET -#include -#endif - -#include +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include #include - -#if OS_FEATURE_GRAPHICAL -#include -#endif - -#if OS_FEATURE_SOCKET -#include -#include -#endif - #include //////////////////////////////// diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index 5237ff30..962820a1 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -7,6 +7,12 @@ //////////////////////////////// //~ rjf: Window Types +typedef U32 OS_WindowFlags; +enum +{ + OS_WindowFlag_CustomBorder = (1<<0), +}; + typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data); //////////////////////////////// @@ -112,7 +118,7 @@ internal String8 os_get_clipboard_text(Arena *arena); //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Handle os_window_open(Vec2F32 resolution, String8 title); +internal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title); internal void os_window_close(OS_Handle window); internal void os_window_first_paint(OS_Handle window); internal void os_window_equip_repaint(OS_Handle window, OS_WindowRepaintFunctionType *repaint, void *user_data); @@ -122,8 +128,13 @@ internal B32 os_window_is_fullscreen(OS_Handle window); internal void os_window_set_fullscreen(OS_Handle window, B32 fullscreen); internal B32 os_window_is_maximized(OS_Handle window); internal void os_window_set_maximized(OS_Handle window, B32 maximized); +internal void os_window_minimize(OS_Handle window); internal void os_window_bring_to_front(OS_Handle window); internal void os_window_set_monitor(OS_Handle window, OS_Handle monitor); +internal void os_window_clear_custom_border_data(OS_Handle handle); +internal void os_window_push_custom_title_bar(OS_Handle handle, F32 thickness); +internal void os_window_push_custom_edges(OS_Handle handle, F32 thickness); +internal void os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect); internal Rng2F32 os_rect_from_window(OS_Handle window); internal Rng2F32 os_client_rect_from_window(OS_Handle window); internal F32 os_dpi_from_window(OS_Handle window); diff --git a/src/os/gfx/stub/os_gfx_stub.c b/src/os/gfx/stub/os_gfx_stub.c index 54a2261f..00128628 100644 --- a/src/os/gfx/stub/os_gfx_stub.c +++ b/src/os/gfx/stub/os_gfx_stub.c @@ -24,7 +24,7 @@ os_get_clipboard_text(Arena *arena) //~ rjf: @os_hooks Windows (Implemented Per-OS) internal OS_Handle -os_window_open(Vec2F32 resolution, String8 title) +os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) { OS_Handle handle = {1}; return handle; @@ -78,6 +78,11 @@ os_window_set_maximized(OS_Handle window, B32 maximized) { } +internal void +os_window_minimize(OS_Handle window) +{ +} + internal void os_window_bring_to_front(OS_Handle window) { @@ -88,6 +93,26 @@ os_window_set_monitor(OS_Handle window, OS_Handle monitor) { } +internal void +os_window_clear_custom_border_data(OS_Handle handle) +{ +} + +internal void +os_window_push_custom_title_bar(OS_Handle handle, F32 thickness) +{ +} + +internal void +os_window_push_custom_edges(OS_Handle handle, F32 thickness) +{ +} + +internal void +os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect) +{ +} + internal Rng2F32 os_rect_from_window(OS_Handle window) { diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index 94d93f00..e94e07df 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -1,6 +1,17 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +//////////////////////////////// +//~ rjf: Includes + +#include +#include +#include +#pragma comment(lib, "gdi32") +#pragma comment(lib, "dwmapi") +#pragma comment(lib, "UxTheme") +#pragma comment(lib, "ole32") + //////////////////////////////// //~ rjf: Globals @@ -100,6 +111,10 @@ w32_allocate_window(void) internal void w32_free_window(W32_Window *window) { + if(window->paint_arena != 0) + { + arena_release(window->paint_arena); + } DestroyWindow(window->hwnd); DLLRemove(w32_first_window, w32_last_window, window); window->next = w32_first_free_window; @@ -530,8 +545,19 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SETCURSOR: { - if(!w32_resizing && - contains_2f32(os_client_rect_from_window(window_handle), os_mouse_from_window(window_handle))) + Rng2F32 window_rect = os_client_rect_from_window(window_handle); + Vec2F32 mouse = os_mouse_from_window(window_handle); + B32 on_border = 0; + DWORD window_style = window ? GetWindowLong(window->hwnd, GWL_STYLE) : 0; + B32 is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW); + if(window != 0 && window->custom_border && !is_fullscreen) + { + B32 on_border_x = (mouse.x <= window->custom_border_edge_thickness || window_rect.x1-window->custom_border_edge_thickness <= mouse.x); + B32 on_border_y = (mouse.y <= window->custom_border_edge_thickness || window_rect.y1-window->custom_border_edge_thickness <= mouse.y); + on_border = on_border_x || on_border_y; + } + if(!w32_resizing && !on_border && + contains_2f32(window_rect, mouse)) { SetCursor(w32_hcursor); } @@ -546,6 +572,225 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) F32 new_dpi = (F32)(wParam & 0xffff); window->dpi = new_dpi; }break; + + //- rjf: [custom border] + case WM_NCPAINT: + { + if(window != 0 && window->custom_border && !window->custom_border_composition_enabled) + { + result = 0; + } + else + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + }break; + case WM_DWMCOMPOSITIONCHANGED: + { + if(window != 0 && window->custom_border) + { + BOOL enabled = 0; + DwmIsCompositionEnabled(&enabled); + window->custom_border_composition_enabled = enabled; + if(enabled) + { + MARGINS m = { 0, 0, 1, 0 }; + DwmExtendFrameIntoClientArea(hwnd, &m); + DWORD dwmncrp_enabled = DWMNCRP_ENABLED; + DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &enabled, sizeof(dwmncrp_enabled)); + } + } + else + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + }break; + case WM_WINDOWPOSCHANGED: + { + result = 0; + }break; + case WM_NCUAHDRAWCAPTION: + case WM_NCUAHDRAWFRAME: + { + // NOTE(rjf): undocumented messages for drawing themed window borders. + if(window != 0 && window->custom_border) + { + result = 0; + } + else + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + }break; + case WM_SETICON: + case WM_SETTEXT: + { + if(window && window->custom_border && !window->custom_border_composition_enabled) + { + // NOTE(rjf): + // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ + LONG_PTR old_style = GetWindowLongPtrW(hwnd, GWL_STYLE); + SetWindowLongPtrW(hwnd, GWL_STYLE, old_style & ~WS_VISIBLE); + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + SetWindowLongPtrW(hwnd, GWL_STYLE, old_style); + } + else + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + }break; + + //- rjf: [custom border] activation - without this `result`, stuff flickers. + case WM_NCACTIVATE: + { + if(window == 0 || window->custom_border == 0) + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + else + { + result = DefWindowProcW(hwnd, uMsg, wParam, -1); + } + }break; + + //- rjf: [custom border] client/window size calculation + case WM_NCCALCSIZE: + if(window != 0) + { + if(window->custom_border == 0) + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + else + { + MARGINS m = {0, 0, 0, 0}; + RECT *r = (RECT *)lParam; + DWORD window_style = window ? GetWindowLong(window->hwnd, GWL_STYLE) : 0; + B32 is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW); + if(IsZoomed(hwnd) && !is_fullscreen) + { + int x_push_in = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); + int y_push_in = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); + r->left += x_push_in; + r->top += y_push_in; + r->bottom -= x_push_in; + r->right -= y_push_in; + m.cxLeftWidth = m.cxRightWidth = x_push_in; + m.cyTopHeight = m.cyBottomHeight = y_push_in; + } + DwmExtendFrameIntoClientArea(hwnd, &m); + } + }break; + + //- rjf: [custom border] client/window hit testing (mapping mouse -> action) + case WM_NCHITTEST: + { + DWORD window_style = window ? GetWindowLong(window->hwnd, GWL_STYLE) : 0; + B32 is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW); + if(window == 0 || window->custom_border == 0 || is_fullscreen) + { + result = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + else + { + POINT pos_monitor; + pos_monitor.x = GET_X_LPARAM(lParam); + pos_monitor.y = GET_Y_LPARAM(lParam); + POINT pos_client = pos_monitor; + ScreenToClient(hwnd, &pos_client); + + //- rjf: check against window boundaries + RECT frame_rect; + GetWindowRect(hwnd, &frame_rect); + B32 is_over_window = (frame_rect.left <= pos_monitor.x && pos_monitor.x < frame_rect.right && + frame_rect.top <= pos_monitor.y && pos_monitor.y < frame_rect.bottom); + + //- rjf: check against borders + B32 is_over_left = 0; + B32 is_over_right = 0; + B32 is_over_top = 0; + B32 is_over_bottom = 0; + { + RECT rect; + GetClientRect(hwnd, &rect); + if(!IsZoomed(hwnd)) + { + if(rect.left <= pos_client.x && pos_client.x < rect.left + window->custom_border_edge_thickness) + { + is_over_left = 1; + } + if(rect.right - window->custom_border_edge_thickness <= pos_client.x && pos_client.x < rect.right) + { + is_over_right = 1; + } + if(rect.bottom - window->custom_border_edge_thickness <= pos_client.y && pos_client.y < rect.bottom) + { + is_over_bottom = 1; + } + if(rect.top <= pos_client.y && pos_client.y < rect.top + window->custom_border_edge_thickness) + { + is_over_top = 1; + } + } + } + + //- rjf: check against title bar + B32 is_over_title_bar = 0; + { + RECT rect; + GetClientRect(hwnd, &rect); + is_over_title_bar = (rect.left <= pos_client.x && pos_client.x < rect.right && + rect.top <= pos_client.y && pos_client.y < rect.top + window->custom_border_title_thickness); + } + + //- rjf: check against title bar client areas + B32 is_over_title_bar_client_area = 0; + for(W32_TitleBarClientArea *area = window->first_title_bar_client_area; + area != 0; + area = area->next) + { + Rng2F32 rect = area->rect; + if(rect.x0 <= pos_client.x && pos_client.x < rect.x1 && + rect.y0 <= pos_client.y && pos_client.y < rect.y1) + { + is_over_title_bar_client_area = 1; + break; + } + } + + //- rjf: resolve hovering to result + result = HTNOWHERE; + if(is_over_window) + { + // rjf: default to client area + result = HTCLIENT; + + // rjf: title bar + if(is_over_title_bar) + { + result = HTCAPTION; + } + + // rjf: title bar client area + if(is_over_title_bar_client_area) + { + result = HTCLIENT; + } + + // rjf: normal edges + if(is_over_left) { result = HTLEFT; } + if(is_over_right) { result = HTRIGHT; } + if(is_over_top) { result = HTTOP; } + if(is_over_bottom) { result = HTBOTTOM; } + + // rjf: corners + if(is_over_left && is_over_top) { result = HTTOPLEFT; } + if(is_over_left && is_over_bottom) { result = HTBOTTOMLEFT; } + if(is_over_right && is_over_top) { result = HTTOPRIGHT; } + if(is_over_right && is_over_bottom) { result = HTBOTTOMRIGHT; } + } + } + }break; } } @@ -580,7 +825,7 @@ os_graphical_init(void) //- rjf: set dpi awareness w32_SetProcessDpiAwarenessContext_Type *SetProcessDpiAwarenessContext_func = 0; HMODULE module = LoadLibraryA("user32.dll"); - if (module != 0) + if(module != 0) { SetProcessDpiAwarenessContext_func = (w32_SetProcessDpiAwarenessContext_Type*)GetProcAddress(module, "SetProcessDpiAwarenessContext"); @@ -588,7 +833,7 @@ os_graphical_init(void) (w32_GetDpiForWindow_Type*)GetProcAddress(module, "GetDpiForWindow"); FreeLibrary(module); } - if (SetProcessDpiAwarenessContext_func != 0) + if(SetProcessDpiAwarenessContext_func != 0) { SetProcessDpiAwarenessContext_func(w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); } @@ -601,6 +846,7 @@ os_graphical_init(void) wndclass.lpszClassName = L"graphical-window"; wndclass.hCursor = LoadCursorA(0, IDC_ARROW); wndclass.hIcon = LoadIcon(w32_h_instance, MAKEINTRESOURCE(1)); + wndclass.style = CS_VREDRAW|CS_HREDRAW; ATOM wndatom = RegisterClassExW(&wndclass); (void)wndatom; } @@ -667,17 +913,17 @@ os_get_clipboard_text(Arena *arena) //~ rjf: @os_hooks Windows (Implemented Per-OS) internal OS_Handle -os_window_open(Vec2F32 resolution, String8 title) +os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) { //- rjf: make hwnd HWND hwnd = 0; { Temp scratch = scratch_begin(0, 0); String16 title16 = str16_from_8(scratch.arena, title); - hwnd = CreateWindowExW(0, + hwnd = CreateWindowExW(WS_EX_APPWINDOW, L"graphical-window", (WCHAR*)title16.str, - WS_OVERLAPPEDWINDOW, + WS_OVERLAPPEDWINDOW | WS_SIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, (int)resolution.x, (int)resolution.y, @@ -699,8 +945,23 @@ os_window_open(Vec2F32 resolution, String8 title) } } + //- rjf: early detection of composition + { + BOOL enabled = 0; + DwmIsCompositionEnabled(&enabled); + window->custom_border_composition_enabled = enabled; + } + + //- rjf: custom border + if(flags & OS_WindowFlag_CustomBorder) + { + window->custom_border = 1; + window->paint_arena = arena_alloc(); + } + //- rjf: convert to handle + return - return os_window_from_w32_window(window); + OS_Handle result = os_window_from_w32_window(window); + return result; } internal void @@ -825,6 +1086,16 @@ os_window_set_maximized(OS_Handle handle, B32 maximized) } } +internal void +os_window_minimize(OS_Handle handle) +{ + W32_Window *window = w32_window_from_os_window(handle); + if(window != 0) + { + ShowWindow(window->hwnd, SW_MINIMIZE); + } +} + internal void os_window_bring_to_front(OS_Handle handle) { @@ -856,6 +1127,48 @@ os_window_set_monitor(OS_Handle window_handle, OS_Handle monitor) } } +internal void +os_window_clear_custom_border_data(OS_Handle handle) +{ + W32_Window *window = w32_window_from_os_window(handle); + if(window->custom_border) + { + arena_clear(window->paint_arena); + window->first_title_bar_client_area = window->last_title_bar_client_area = 0; + window->custom_border_title_thickness = 0; + window->custom_border_edge_thickness = 0; + } +} + +internal void +os_window_push_custom_title_bar(OS_Handle handle, F32 thickness) +{ + W32_Window *window = w32_window_from_os_window(handle); + window->custom_border_title_thickness = thickness; +} + +internal void +os_window_push_custom_edges(OS_Handle handle, F32 thickness) +{ + W32_Window *window = w32_window_from_os_window(handle); + window->custom_border_edge_thickness = thickness; +} + +internal void +os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect) +{ + W32_Window *window = w32_window_from_os_window(handle); + if(window->custom_border) + { + W32_TitleBarClientArea *area = push_array(window->paint_arena, W32_TitleBarClientArea, 1); + if(area != 0) + { + area->rect = rect; + SLLQueuePush(window->first_title_bar_client_area, window->last_title_bar_client_area, area); + } + } +} + internal Rng2F32 os_rect_from_window(OS_Handle handle) { diff --git a/src/os/gfx/win32/os_gfx_win32.h b/src/os/gfx/win32/os_gfx_win32.h index 547e6822..cfb54d25 100644 --- a/src/os/gfx/win32/os_gfx_win32.h +++ b/src/os/gfx/win32/os_gfx_win32.h @@ -7,9 +7,23 @@ #pragma comment(lib, "user32") #pragma comment(lib, "gdi32") +#ifndef WM_NCUAHDRAWCAPTION +#define WM_NCUAHDRAWCAPTION (0x00AE) +#endif +#ifndef WM_NCUAHDRAWFRAME +#define WM_NCUAHDRAWFRAME (0x00AF) +#endif + //////////////////////////////// //~ rjf: Windows +typedef struct W32_TitleBarClientArea W32_TitleBarClientArea; +struct W32_TitleBarClientArea +{ + W32_TitleBarClientArea *next; + Rng2F32 rect; +}; + typedef struct W32_Window W32_Window; struct W32_Window { @@ -22,6 +36,13 @@ struct W32_Window F32 dpi; B32 first_paint_done; B32 maximized; + B32 custom_border; + F32 custom_border_title_thickness; + F32 custom_border_edge_thickness; + B32 custom_border_composition_enabled; + Arena *paint_arena; + W32_TitleBarClientArea *first_title_bar_client_area; + W32_TitleBarClientArea *last_title_bar_client_area; }; //////////////////////////////// diff --git a/src/raddbg/raddbg.c b/src/raddbg/raddbg.c index 87425b6b..218b7fa8 100644 --- a/src/raddbg/raddbg.c +++ b/src/raddbg/raddbg.c @@ -11,8 +11,22 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); + //- rjf: begin logging + if(main_thread_log == 0) + { + main_thread_log = log_alloc(); + String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData); + String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path); + main_thread_log_path = push_str8f(df_state->arena, "%S/ui_thread.raddbg_log", user_data_folder); + os_make_directory(user_data_folder); + os_write_data_to_file_path(main_thread_log_path, str8_zero()); + } + log_select(main_thread_log); + log_scope_begin(); + //- rjf: tick cache layers txt_user_clock_tick(); + dasm_user_clock_tick(); geo_user_clock_tick(); tex_user_clock_tick(); @@ -152,6 +166,10 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) window->menu_bar_focus_press_started = 0; } } + else if(OS_Key_F1 <= event->key && event->key <= OS_Key_F19) + { + window->menu_bar_focus_press_started = 0; + } df_gfx_request_frame(); } else if(event->kind == OS_EventKind_Text) @@ -324,6 +342,12 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) frame_time_us_history[frame_time_us_history_idx%ArrayCount(frame_time_us_history)] = frame_time_us; frame_time_us_history_idx += 1; + //- rjf: end logging + { + String8 log = log_scope_end(scratch.arena); + os_append_data_to_file_path(main_thread_log_path, log); + } + scratch_end(scratch); ProfEnd(); } diff --git a/src/raddbg/raddbg.h b/src/raddbg/raddbg.h index 72b217cd..bb0f5087 100644 --- a/src/raddbg/raddbg.h +++ b/src/raddbg/raddbg.h @@ -1,14 +1,6 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -//////////////////////////////// -//~ rjf: Demon/Cleanup Pass Tasks -// -// [ ] TLS eval -> in-process-memory EXE info -// [ ] unwinding -> in-process-memory EXE info -// [ ] "root" concept in hash store, which buckets keys & allows usage code to -// jettison a collection of keys in retained mode fashion - //////////////////////////////// //~ rjf: Frontend/UI Pass Tasks // @@ -22,7 +14,6 @@ // [ ] source view -> floating margin/line-nums // [ ] theme colors -> more explicit about e.g. opaque backgrounds vs. floating // & scrollbars etc. -// [ ] drag/drop tab cleanup // [ ] target/breakpoint/watch-pin reordering // [ ] watch window reordering // [ ] standard way to filter @@ -57,6 +48,9 @@ //////////////////////////////// //~ rjf: Hot, High Priority Tasks (Complete Unusability, Crashes, Fire-Worthy) // +// [ ] robustify dbgi layer to renames (cache should not be based only on +// path - must invalidate naturally when new filetime occurs) +// // [ ] raddbg jai.exe my_file.jai -- foobar -> raddbg consumes `--` incorrectly // [ ] PDB files distributed with the build are not found by DbgHelp!!! // [ ] Jai compiler debugging crash @@ -64,23 +58,17 @@ // // [ ] Jump table thunks, on code w/o /INCREMENTAL:NO // -// [ ] ** Thread/process control bullet-proofing, including solo-step mode -// -// [ ] ** In solo-stepping mode, if I step over something like CreateFileA, it -// pseudo-hangs the debugger. I can't seem to do anything else, including -// "Kill All". I have to close the debugger and restart it, AFAICT? -// -// [ ] ** I tried to debug a console program, and "step into" didn't seem to -// work. Instead, it just started running the program, but the program -// seemed to hang, and then the debugger pseudo-hung with a continual -// progress bar in the disassembly window. I had to close and restart. Is -// console app debugging not working yet, perhaps? -// // [ ] Setting the code_font/main_font values to a font name doesn't work. // Should probably make note that you have to set it to a path to a TTF, // since that's not normally how Windows fonts work. + +//////////////////////////////// +//~ rjf: Demon/Cleanup Pass Tasks // -// [ ] ** Converter performance & heuristics for asynchronously doing it early +// [ ] TLS eval -> in-process-memory EXE info +// [ ] unwinding -> in-process-memory EXE info +// [ ] "root" concept in hash store, which buckets keys & allows usage code to +// jettison a collection of keys in retained mode fashion //////////////////////////////// //~ rjf: Hot, Medium Priority Tasks (Low-Hanging-Fruit Features, UI Jank, Cleanup) @@ -88,6 +76,8 @@ // [ ] investigate /DEBUG:FASTLINK - can we somehow alert that we do not // support it? // +// [ ] ** Converter performance & heuristics for asynchronously doing it early +// // [ ] visualize conversion failures // // [ ] I was a little confused about what a profile file was. I understood @@ -182,11 +172,6 @@ // item, then releasing, does not trigger that item as expected. Instead, // it is a nop, and it waits for you to click again on the item. // -// [ ] Working with panels felt cumbersome. I couldn't figure out any way to -// quickly arrange the display without manually selecting "split panel" -// and "close panel" and stuff from the menu, which took a long time. -// - @polish @feature ui for dragging tab -> bundling panel split options -// // [ ] I found the "context menu" convention to be confusing. For example, if // I left-click on a tab, it selects the tab. If I right-click on a tab, // it opens the context menu. However, if I left-click on a module, it @@ -198,7 +183,6 @@ // the files myself in the shell, but it seemed weird that there was no // "save" option in the menus. // -// [ ] @cleanup @feature double & triple click select in source views // [ ] @feature debug info overrides (both path-based AND module-based) // [ ] configure tab size // [ ] auto-scroll output window @@ -315,8 +299,6 @@ // [ ] @bug view-snapping in scroll-lists, accounting for mapping between // visual positions & logical positions (variably sized rows in watch, // table headers, etc.) -// [ ] @bug selected frame should be keyed by run_idx or something so that it -// can gracefully reset to the top frame when running // [ ] @cleanup collapse DF_CfgNodes into just being MD trees, find another way // to encode config source - don't need it at every node // [ ] @cleanup straighten out index/number space & types & terminology for @@ -335,8 +317,6 @@ // when editing) // [ ] @feature eval system -> somehow evaluate breakpoint hit counts? "meta" // variables? -// [ ] @feature watch window labels -// [ ] @feature scheduler -> thread grid view? // // [ ] @feature disasm view improvement features // [ ] interleaved src/dasm view @@ -397,20 +377,7 @@ //////////////////////////////// //~ rjf: Recently Completed Task Log // -// [x] solidify synchronization mechanisms for usage of demon layer -// [x] TLS eval correctness -// [x] freezing thread while running -> soft-halt -// [x] Watch Window Filtering -// [x] @feature disasm keyboard navigation & copy/paste -// [x] run-to-line needs to work if no processes are running -// - place temp bp, attach "die on hit" flag or something like that? -// [x] disasm animation & go-to-address -// [x] middle mouse button on tab should close it -// [x] I didn't understand the terminology "Equip With Color". Does that just -// mean specify the color used to display it? Is "Apply Color" perhaps a -// bit more user-friendly? // -// [x] The cursor feels a bit too huge vertically. #ifndef RADDBG_H #define RADDBG_H @@ -442,6 +409,8 @@ read_only global String8 ipc_shared_memory_name = str8_lit_comp("_raddbg_ipc_sha read_only global String8 ipc_semaphore_name = str8_lit_comp("_raddbg_ipc_semaphore_"); global U64 frame_time_us_history[64] = {0}; global U64 frame_time_us_history_idx = 0; +global Log *main_thread_log = 0; +global String8 main_thread_log_path = {0}; //////////////////////////////// //~ rjf: Frontend Entry Points diff --git a/src/raddbg/raddbg_main.cpp b/src/raddbg/raddbg_main.cpp index 32b3f3df..9fe476ad 100644 --- a/src/raddbg/raddbg_main.cpp +++ b/src/raddbg/raddbg_main.cpp @@ -16,14 +16,17 @@ //- rjf: [lib] #include "lib_raddbgi_format/raddbgi_format.h" -#include "lib_raddbgi_format/raddbgi_format_parse.h" #include "lib_raddbgi_format/raddbgi_format.c" +#include "lib_raddbgi_format/raddbgi_format_parse.h" #include "lib_raddbgi_format/raddbgi_format_parse.c" +#include "third_party/rad_lzb_simple/rad_lzb_simple.h" +#include "third_party/rad_lzb_simple/rad_lzb_simple.c" //- rjf: [h] #include "base/base_inc.h" #include "os/os_inc.h" #include "task_system/task_system.h" +#include "ico/ico.h" #include "raddbgi_make_local/raddbgi_make_local.h" #include "mdesk/mdesk.h" #include "hash_store/hash_store.h" @@ -62,6 +65,7 @@ #include "base/base_inc.c" #include "os/os_inc.c" #include "task_system/task_system.c" +#include "ico/ico.c" #include "raddbgi_make_local/raddbgi_make_local.c" #include "mdesk/mdesk.c" #include "hash_store/hash_store.c" @@ -389,8 +393,15 @@ entry_point(CmdLine *cmd_line) bake2srlz = p2r_bake(scratch.arena, convert2bake); } + //- rjf: compress + P2R_Bake2Serialize *bake2srlz_compressed = bake2srlz; + if(cmd_line_has_flag(cmd_line, str8_lit("compress"))) ProfScope("compress") + { + bake2srlz_compressed = p2r_compress(scratch.arena, bake2srlz); + } + //- rjf: serialize - String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(scratch.arena, &convert2bake->bake_params, &bake2srlz->sections); + String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(scratch.arena, &convert2bake->bake_params, &bake2srlz_compressed->sections); //- rjf: write if(out_file_is_good) diff --git a/src/raddbgi_breakpad_from_pdb/raddbgi_breakpad_from_pdb_main.c b/src/raddbgi_breakpad_from_pdb/raddbgi_breakpad_from_pdb_main.c index 23b593d5..fb31b764 100644 --- a/src/raddbgi_breakpad_from_pdb/raddbgi_breakpad_from_pdb_main.c +++ b/src/raddbgi_breakpad_from_pdb/raddbgi_breakpad_from_pdb_main.c @@ -16,6 +16,9 @@ #include "lib_raddbgi_format/raddbgi_format_parse.h" #include "lib_raddbgi_format/raddbgi_format.c" #include "lib_raddbgi_format/raddbgi_format_parse.c" +#include "third_party/rad_lzb_simple/rad_lzb_simple.h" +#include "third_party/rad_lzb_simple/rad_lzb_simple.c" + //- rjf: [h] #include "base/base_inc.h" @@ -78,7 +81,7 @@ internal TS_TASK_FUNCTION_DEF(p2b_bake_unit_vmap_task__entry_point) if(vmap_section != 0) { out->vmap_entries = (RDI_VMapEntry *)vmap_section->data; - out->vmap_entries_count = vmap_section->size/sizeof(RDI_VMapEntry); + out->vmap_entries_count = vmap_section->unpacked_size/sizeof(RDI_VMapEntry); } return out; } @@ -117,7 +120,7 @@ internal TS_TASK_FUNCTION_DEF(p2b_bake_unit_task__entry_point) } if(voffs_section != 0 && lines_section != 0) { - out->unit_line_count = lines_section->size/sizeof(RDI_Line); + out->unit_line_count = lines_section->unpacked_size/sizeof(RDI_Line); out->unit_line_voffs = (U64 *)voffs_section->data; out->unit_lines = (RDI_Line *)lines_section->data; } diff --git a/src/raddbgi_from_pdb/raddbgi_from_pdb.c b/src/raddbgi_from_pdb/raddbgi_from_pdb.c index e8239e84..26901abb 100644 --- a/src/raddbgi_from_pdb/raddbgi_from_pdb.c +++ b/src/raddbgi_from_pdb/raddbgi_from_pdb.c @@ -95,11 +95,54 @@ p2r_user2convert_from_cmdln(Arena *arena, CmdLine *cmdline) } } + //- rjf: define string -> flag bits +#define FlagNameMapXList \ +Case("sections", BinarySections)\ +Case("units", Units)\ +Case("procedures", Procedures)\ +Case("globals", GlobalVariables)\ +Case("threadvars", ThreadVariables)\ +Case("scopes", Scopes)\ +Case("locals", Locals)\ +Case("types", Types)\ +Case("udts", UDTs)\ +Case("lines", LineInfo)\ +Case("globals_name_map", GlobalVariableNameMap)\ +Case("threadvars_name_map", ThreadVariableNameMap)\ +Case("procedure_name_map", ProcedureNameMap)\ +Case("type_name_map", TypeNameMap)\ +Case("link_name_map", LinkNameProcedureNameMap)\ +Case("source_path_name_map",NormalSourcePathNameMap)\ + //- rjf: get flags { result->flags = P2R_ConvertFlag_All; + String8List only_names = cmd_line_strings(cmdline, str8_lit("only")); + String8List omit_names = cmd_line_strings(cmdline, str8_lit("only")); + if(only_names.node_count != 0) + { + result->flags = 0; + for(String8Node *n = only_names.first; n != 0; n = n->next) + { + String8 string = n->string; +#define Case(str, flag) if(str8_match(string, str8_lit(str), StringMatchFlag_CaseInsensitive)) {result->flags |= P2R_ConvertFlag_##flag;} + FlagNameMapXList; +#undef Case + } + } + if(omit_names.node_count != 0) + { + for(String8Node *n = omit_names.first; n != 0; n = n->next) + { + String8 string = n->string; +#define Case(str, flag) if(str8_match(string, str8_lit(str), StringMatchFlag_CaseInsensitive)) {result->flags &= ~P2R_ConvertFlag_##flag;} + FlagNameMapXList; +#undef Case + } + } } +#undef FlagNameMapXList return result; } @@ -2755,7 +2798,7 @@ p2r_convert(Arena *arena, P2R_User2Convert *in) RDIM_TopLevelInfo top_level_info = {0}; { top_level_info.arch = arch; - top_level_info.exe_name = in->input_exe_name; + top_level_info.exe_name = str8_skip_last_slash(in->input_exe_name); top_level_info.exe_hash = exe_hash; top_level_info.voff_max = exe_voff_max; } @@ -4238,3 +4281,58 @@ p2r_bake(Arena *arena, P2R_Convert2Bake *in) scratch_end(scratch); return out; } + +//////////////////////////////// +//~ rjf: Top-Level Compression Entry Point + +internal P2R_Bake2Serialize * +p2r_compress(Arena *arena, P2R_Bake2Serialize *in) +{ + RDIM_BakeSectionList prepack_sections = in->sections; + RDIM_BakeSectionList postpack_sections = {0}; + { + //- rjf: set up compression context + rr_lzb_simple_context ctx = {0}; + ctx.m_tableSizeBits = 14; + ctx.m_hashTable = push_array(arena, U16, 1<next) + { + RDIM_BakeSection *src = &src_n->v; + + // rjf: push new section + RDIM_BakeSection *dst = rdim_bake_section_list_push(arena, &postpack_sections); + + // rjf: unpack uncompressed section info + void *data = src->data; + RDI_DataSectionEncoding encoding = src->encoding; + RDI_U64 encoded_size = src->encoded_size; + RDI_U64 unpacked_size = src->unpacked_size; + + // rjf: determine if this section should be compressed + B32 should_compress = 1; + + // rjf: compress if needed + if(should_compress) + { + MemoryZero(ctx.m_hashTable, sizeof(U16)*(1<data = data; + dst->encoding = encoding; + dst->encoded_size = encoded_size; + dst->unpacked_size = unpacked_size; + dst->tag = src->tag; + dst->tag_idx = src->tag_idx; + } + } + P2R_Bake2Serialize *out = push_array(arena, P2R_Bake2Serialize, 1); + out->sections = postpack_sections; + return out; +} diff --git a/src/raddbgi_from_pdb/raddbgi_from_pdb.h b/src/raddbgi_from_pdb/raddbgi_from_pdb.h index 7b1ae67e..226c0bde 100644 --- a/src/raddbgi_from_pdb/raddbgi_from_pdb.h +++ b/src/raddbgi_from_pdb/raddbgi_from_pdb.h @@ -5,16 +5,35 @@ #define RADDBGI_FROM_PDB_H //////////////////////////////// -//~ rjf: Conversion Stage Inputs/Outputs +//~ rjf: Export Artifact Flags typedef U32 P2R_ConvertFlags; enum { - P2R_ConvertFlag_Types = (1<<0), - P2R_ConvertFlag_UDTs = (1<<1), + P2R_ConvertFlag_Strings = (1<<0), + P2R_ConvertFlag_IndexRuns = (1<<1), + P2R_ConvertFlag_BinarySections = (1<<2), + P2R_ConvertFlag_Units = (1<<3), + P2R_ConvertFlag_Procedures = (1<<4), + P2R_ConvertFlag_GlobalVariables = (1<<5), + P2R_ConvertFlag_ThreadVariables = (1<<6), + P2R_ConvertFlag_Scopes = (1<<7), + P2R_ConvertFlag_Locals = (1<<8), + P2R_ConvertFlag_Types = (1<<9), + P2R_ConvertFlag_UDTs = (1<<10), + P2R_ConvertFlag_LineInfo = (1<<11), + P2R_ConvertFlag_GlobalVariableNameMap = (1<<12), + P2R_ConvertFlag_ThreadVariableNameMap = (1<<13), + P2R_ConvertFlag_ProcedureNameMap = (1<<14), + P2R_ConvertFlag_TypeNameMap = (1<<15), + P2R_ConvertFlag_LinkNameProcedureNameMap= (1<<16), + P2R_ConvertFlag_NormalSourcePathNameMap = (1<<17), P2R_ConvertFlag_All = 0xffffffff, }; +//////////////////////////////// +//~ rjf: Conversion Stage Inputs/Outputs + typedef struct P2R_User2Convert P2R_User2Convert; struct P2R_User2Convert { @@ -602,4 +621,9 @@ internal TS_TASK_FUNCTION_DEF(p2r_bake_idx_runs_task__entry_point); internal P2R_Bake2Serialize *p2r_bake(Arena *arena, P2R_Convert2Bake *in); +//////////////////////////////// +//~ rjf: Top-Level Compression Entry Point + +internal P2R_Bake2Serialize *p2r_compress(Arena *arena, P2R_Bake2Serialize *in); + #endif // RADDBGI_FROM_PDB_H diff --git a/src/raddbgi_from_pdb/raddbgi_from_pdb_main.c b/src/raddbgi_from_pdb/raddbgi_from_pdb_main.c index bc0ef474..e323bc09 100644 --- a/src/raddbgi_from_pdb/raddbgi_from_pdb_main.c +++ b/src/raddbgi_from_pdb/raddbgi_from_pdb_main.c @@ -17,6 +17,8 @@ //- rjf: [lib] #include "lib_raddbgi_format/raddbgi_format.h" #include "lib_raddbgi_format/raddbgi_format.c" +#include "third_party/rad_lzb_simple/rad_lzb_simple.h" +#include "third_party/rad_lzb_simple/rad_lzb_simple.c" //- rjf: [h] #include "base/base_inc.h" @@ -96,8 +98,15 @@ entry_point(CmdLine *cmdline) bake2srlz = p2r_bake(arena, convert2bake); } + //- rjf: compress + P2R_Bake2Serialize *bake2srlz_compressed = bake2srlz; + if(cmd_line_has_flag(cmdline, str8_lit("compress"))) ProfScope("compress") + { + bake2srlz_compressed = p2r_compress(arena, bake2srlz); + } + //- rjf: serialize - String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(arena, &convert2bake->bake_params, &bake2srlz->sections); + String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(arena, &convert2bake->bake_params, &bake2srlz_compressed->sections); //- rjf: write ProfScope("write") diff --git a/src/scratch/i_hate_c_plus_plus.cpp b/src/scratch/i_hate_c_plus_plus.cpp index 8589c7fa..e0ceee5f 100644 --- a/src/scratch/i_hate_c_plus_plus.cpp +++ b/src/scratch/i_hate_c_plus_plus.cpp @@ -1,30 +1,60 @@ -struct Bar +static int Static = 5; +namespace NS { - int x; - int y; - int z; + static int staticDataInNS = 99; + struct A + { + static int staticData; + int a = 20; + int b = 30; + void Foo() + { + Static += 1; + staticDataInNS += 1; + staticData++; + a++; + b++; + } + }; + int A::staticData = 123; +} + +struct Resource +{ + int resourceType; }; -struct BarContainer +struct Stack { - Bar *bar; - int bar_count; - int bar_cap; + Resource *resource; }; -struct Foo +struct StackNode { - BarContainer bar; - int a; - int b; - int c; + StackNode *next; + Stack v; +}; + +struct Context +{ + StackNode *entry_stack_first; }; int main(void) { - Bar bar[100] = {0}; - Foo foo_ = {bar, 50, sizeof(bar)/sizeof(Bar)}; - Foo &foo = foo_; + Resource r_ = {0}; + Resource *r = &r_; + Stack s = {r}; + StackNode n_ = {0, s}; + StackNode *n = &n_; + Context c_ = {n}; + Context *context = &c_; + + // evaluate `context.entry_stack_first.v.resource.resourceType == 0xd8` + int x = 0; + + NS::A a = {0}; + a.Foo(); return 0; } diff --git a/src/text_cache/text_cache.c b/src/text_cache/text_cache.c index a9a3ea43..18e21dc5 100644 --- a/src/text_cache/text_cache.c +++ b/src/text_cache/text_cache.c @@ -30,9 +30,36 @@ txt_lang_kind_from_extension(String8 extension) { kind = TXT_LangKind_Odin; } + else if(str8_match(extension, str8_lit("jai"), StringMatchFlag_CaseInsensitive)) + { + kind = TXT_LangKind_Jai; + } + else if(str8_match(extension, str8_lit("zig"), StringMatchFlag_CaseInsensitive)) + { + kind = TXT_LangKind_Zig; + } return kind; } +internal String8 +txt_extension_from_lang_kind(TXT_LangKind kind) +{ + String8 result = {0}; + switch(kind) + { + case TXT_LangKind_Null: + case TXT_LangKind_COUNT: + case TXT_LangKind_DisasmX64Intel: + {}break; + case TXT_LangKind_C: {result = str8_lit("c");}break; + case TXT_LangKind_CPlusPlus: {result = str8_lit("cpp");}break; + case TXT_LangKind_Odin: {result = str8_lit("odin");}break; + case TXT_LangKind_Jai: {result = str8_lit("jai");}break; + case TXT_LangKind_Zig: {result = str8_lit("zig");}break; + } + return result; +} + internal TXT_LangKind txt_lang_kind_from_architecture(Architecture arch) { @@ -55,6 +82,8 @@ txt_lex_function_from_lang_kind(TXT_LangKind kind) case TXT_LangKind_C: {fn = txt_token_array_from_string__c_cpp;}break; case TXT_LangKind_CPlusPlus: {fn = txt_token_array_from_string__c_cpp;}break; case TXT_LangKind_Odin: {fn = txt_token_array_from_string__odin;}break; + case TXT_LangKind_Jai: {fn = txt_token_array_from_string__jai;}break; + case TXT_LangKind_Zig: {fn = txt_token_array_from_string__zig;}break; case TXT_LangKind_DisasmX64Intel:{fn = txt_token_array_from_string__disasm_x64_intel;}break; } return fn; @@ -565,6 +594,7 @@ txt_token_array_from_string__odin(Arena *arena, U64 *bytes_processed_counter, St { read_only local_persist String8 odin_keywords[] = { + str8_lit_comp("align_of"), str8_lit_comp("asm"), str8_lit_comp("auto_cast"), str8_lit_comp("bit_set"), @@ -594,6 +624,7 @@ txt_token_array_from_string__odin(Arena *arena, U64 *bytes_processed_counter, St str8_lit_comp("package"), str8_lit_comp("proc"), str8_lit_comp("return"), + str8_lit_comp("size_of"), str8_lit_comp("struct"), str8_lit_comp("switch"), str8_lit_comp("transmute"), @@ -637,6 +668,470 @@ txt_token_array_from_string__odin(Arena *arena, U64 *bytes_processed_counter, St return result; } +internal TXT_TokenArray +txt_token_array_from_string__jai(Arena *arena, U64 *bytes_processed_counter, String8 string) +{ + Temp scratch = scratch_begin(&arena, 1); + + //- rjf: generate token list + TXT_TokenChunkList tokens = {0}; + { + B32 comment_is_single_line = 0; + B32 string_is_char = 0; + TXT_TokenKind active_token_kind = TXT_TokenKind_Null; + U64 active_token_start_idx = 0; + B32 escaped = 0; + B32 next_escaped = 0; + U64 byte_process_start_idx = 0; + for(U64 idx = 0; idx <= string.size;) + { + U8 byte = (idx+0 < string.size) ? (string.str[idx+0]) : 0; + U8 next_byte = (idx+1 < string.size) ? (string.str[idx+1]) : 0; + + // rjf: update counter + if(bytes_processed_counter != 0 && ((idx-byte_process_start_idx) >= 1000 || idx == string.size)) + { + ins_atomic_u64_add_eval(bytes_processed_counter, (idx-byte_process_start_idx)); + byte_process_start_idx = idx; + } + + // rjf: escaping + if(escaped && (byte != '\r' && byte != '\n')) + { + next_escaped = 0; + } + else if(!escaped && byte == '\\') + { + next_escaped = 1; + } + + // rjf: take starter, determine active token kind + if(active_token_kind == TXT_TokenKind_Null) + { + // rjf: use next bytes to start a new token + if(0){} + else if(char_is_space(byte)) { active_token_kind = TXT_TokenKind_Whitespace; } + else if(byte == '_' || + byte == '$' || + char_is_alpha(byte)) { active_token_kind = TXT_TokenKind_Identifier; } + else if(char_is_digit(byte, 10) || + (byte == '.' && + char_is_digit(next_byte, 10))) { active_token_kind = TXT_TokenKind_Numeric; } + else if(byte == '"') { active_token_kind = TXT_TokenKind_String; string_is_char = 0; } + else if(byte == '\'') { active_token_kind = TXT_TokenKind_String; string_is_char = 1; } + else if(byte == '/' && next_byte == '/') { active_token_kind = TXT_TokenKind_Comment; comment_is_single_line = 1; } + else if(byte == '/' && next_byte == '*') { active_token_kind = TXT_TokenKind_Comment; comment_is_single_line = 0; } + else if(byte == '~' || byte == '!' || + byte == '%' || byte == '^' || + byte == '&' || byte == '*' || + byte == '(' || byte == ')' || + byte == '-' || byte == '=' || + byte == '+' || byte == '[' || + byte == ']' || byte == '{' || + byte == '}' || byte == ':' || + byte == ';' || byte == ',' || + byte == '.' || byte == '<' || + byte == '>' || byte == '/' || + byte == '?' || byte == '|') { active_token_kind = TXT_TokenKind_Symbol; } + else if(byte == '#') { active_token_kind = TXT_TokenKind_Meta; } + + // rjf: start new token + if(active_token_kind != TXT_TokenKind_Null) + { + active_token_start_idx = idx; + } + + // rjf: invalid token kind -> emit error + else + { + TXT_Token token = {TXT_TokenKind_Error, r1u64(idx, idx+1)}; + txt_token_chunk_list_push(scratch.arena, &tokens, 4096, &token); + } + } + + // rjf: look for ender + U64 ender_pad = 0; + B32 ender_found = 0; + if(active_token_kind != TXT_TokenKind_Null && idx>active_token_start_idx) + { + if(idx == string.size) + { + ender_pad = 0; + ender_found = 1; + } + else switch(active_token_kind) + { + default:break; + case TXT_TokenKind_Whitespace: + { + ender_found = !char_is_space(byte); + }break; + case TXT_TokenKind_Identifier: + { + ender_found = (!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '_' && byte != '$'); + }break; + case TXT_TokenKind_Numeric: + { + ender_found = (!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '_' && byte != '.' && byte != '\''); + }break; + case TXT_TokenKind_String: + { + ender_found = (!escaped && ((!string_is_char && byte == '"') || (string_is_char && byte == '\''))); + ender_pad += 1; + }break; + case TXT_TokenKind_Symbol: + { + ender_found = (byte != '~' && byte != '!' && + byte != '%' && byte != '^' && + byte != '&' && byte != '*' && + byte != '(' && byte != ')' && + byte != '-' && byte != '=' && + byte != '+' && byte != '[' && + byte != ']' && byte != '{' && + byte != '}' && byte != ':' && + byte != ';' && byte != ',' && + byte != '.' && byte != '<' && + byte != '>' && byte != '/' && + byte != '?' && byte != '|'); + }break; + case TXT_TokenKind_Comment: + { + if(comment_is_single_line) + { + ender_found = (!escaped && (byte == '\r' || byte == '\n')); + } + else + { + ender_found = (active_token_start_idx+1 < idx && byte == '*' && next_byte == '/'); + ender_pad += 2; + } + }break; + case TXT_TokenKind_Meta: + { + ender_found = (!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '_' && byte != '$'); + }break; + } + } + + // rjf: next byte is ender => emit token + if(ender_found) + { + TXT_Token token = {active_token_kind, r1u64(active_token_start_idx, idx+ender_pad)}; + active_token_kind = TXT_TokenKind_Null; + + // rjf: identifier -> keyword in special cases + if(token.kind == TXT_TokenKind_Identifier) + { + read_only local_persist String8 jai_keywords[] = + { + str8_lit_comp("bool"), + str8_lit_comp("true"), + str8_lit_comp("false"), + str8_lit_comp("int"), + str8_lit_comp("s8"), + str8_lit_comp("u8"), + str8_lit_comp("s16"), + str8_lit_comp("u16"), + str8_lit_comp("s32"), + str8_lit_comp("u32"), + str8_lit_comp("s64"), + str8_lit_comp("u64"), + str8_lit_comp("s128"), + str8_lit_comp("u128"), + str8_lit_comp("float"), + str8_lit_comp("float32"), + str8_lit_comp("float64"), + str8_lit_comp("void"), + str8_lit_comp("enum"), + str8_lit_comp("enum_flags"), + str8_lit_comp("size_of"), + str8_lit_comp("string"), + str8_lit_comp("type_of"), + str8_lit_comp("cast"), + str8_lit_comp("if"), + str8_lit_comp("ifs"), + str8_lit_comp("then"), + str8_lit_comp("else"), + str8_lit_comp("case"), + str8_lit_comp("for"), + str8_lit_comp("while"), + str8_lit_comp("break"), + str8_lit_comp("continue"), + str8_lit_comp("remove"), + str8_lit_comp("return"), + str8_lit_comp("inline"), + str8_lit_comp("null"), + str8_lit_comp("defer"), + str8_lit_comp("xx"), + }; + String8 token_string = str8_substr(string, r1u64(active_token_start_idx, idx+ender_pad)); + for(U64 keyword_idx = 0; keyword_idx < ArrayCount(jai_keywords); keyword_idx += 1) + { + if(str8_match(jai_keywords[keyword_idx], token_string, 0)) + { + token.kind = TXT_TokenKind_Keyword; + break; + } + } + } + + // rjf: push + txt_token_chunk_list_push(scratch.arena, &tokens, 4096, &token); + + // rjf: increment by ender padding + idx += ender_pad; + } + + // rjf: advance by 1 byte if we haven't found an ender + if(!ender_found) + { + idx += 1; + } + escaped = next_escaped; + } + } + + //- rjf: token list -> token array + TXT_TokenArray result = txt_token_array_from_chunk_list(arena, &tokens); + scratch_end(scratch); + return result; +} + +internal TXT_TokenArray +txt_token_array_from_string__zig(Arena *arena, U64 *bytes_processed_counter, String8 string) +{ + Temp scratch = scratch_begin(&arena, 1); + + //- rjf: generate token list + TXT_TokenChunkList tokens = {0}; + { + B32 string_is_char = 0; + B32 string_is_line = 0; + TXT_TokenKind active_token_kind = TXT_TokenKind_Null; + U64 active_token_start_idx = 0; + B32 escaped = 0; + B32 next_escaped = 0; + U64 byte_process_start_idx = 0; + for(U64 idx = 0; idx <= string.size;) + { + U8 byte = (idx+0 < string.size) ? (string.str[idx+0]) : 0; + U8 next_byte = (idx+1 < string.size) ? (string.str[idx+1]) : 0; + + // rjf: update counter + if(bytes_processed_counter != 0 && ((idx-byte_process_start_idx) >= 1000 || idx == string.size)) + { + ins_atomic_u64_add_eval(bytes_processed_counter, (idx-byte_process_start_idx)); + byte_process_start_idx = idx; + } + + // rjf: escaping + if(escaped && (byte != '\r' && byte != '\n')) + { + next_escaped = 0; + } + else if(!escaped && byte == '\\') + { + next_escaped = 1; + } + + // rjf: take starter, determine active token kind + if(active_token_kind == TXT_TokenKind_Null) + { + // rjf: use next bytes to start a new token + if(0){} + else if(char_is_space(byte)) { active_token_kind = TXT_TokenKind_Whitespace; } + else if(byte == '_' || + char_is_alpha(byte)) { active_token_kind = TXT_TokenKind_Identifier; } + else if(char_is_digit(byte, 10) || + (byte == '.' && + char_is_digit(next_byte, 10))) { active_token_kind = TXT_TokenKind_Numeric; } + else if(byte == '"') { active_token_kind = TXT_TokenKind_String; string_is_char = 0; } + else if(byte == '\'') { active_token_kind = TXT_TokenKind_String; string_is_char = 1; } + else if(byte == '\\' && + next_byte == '\\') { active_token_kind = TXT_TokenKind_String; string_is_line = 1; } + else if(byte == '/' && next_byte == '/') { active_token_kind = TXT_TokenKind_Comment; } + else if(byte == '~' || byte == '!' || + byte == '%' || byte == '^' || + byte == '&' || byte == '*' || + byte == '(' || byte == ')' || + byte == '-' || byte == '=' || + byte == '+' || byte == '[' || + byte == ']' || byte == '{' || + byte == '}' || byte == ':' || + byte == ';' || byte == ',' || + byte == '.' || byte == '<' || + byte == '>' || byte == '/' || + byte == '?' || byte == '|' || + byte == 'c') { active_token_kind = TXT_TokenKind_Symbol; } + + // rjf: start new token + if(active_token_kind != TXT_TokenKind_Null) + { + active_token_start_idx = idx; + } + + // rjf: invalid token kind -> emit error + else + { + TXT_Token token = {TXT_TokenKind_Error, r1u64(idx, idx+1)}; + txt_token_chunk_list_push(scratch.arena, &tokens, 4096, &token); + } + } + + // rjf: look for ender + U64 ender_pad = 0; + B32 ender_found = 0; + if(active_token_kind != TXT_TokenKind_Null && idx>active_token_start_idx) + { + if(idx == string.size) + { + ender_pad = 0; + ender_found = 1; + } + else switch(active_token_kind) + { + default:break; + case TXT_TokenKind_Whitespace: + { + ender_found = !char_is_space(byte); + }break; + case TXT_TokenKind_Identifier: + { + ender_found = (!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '_' && byte != '$'); + }break; + case TXT_TokenKind_Numeric: + { + ender_found = (!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '_' && byte != '.' && byte != '\''); + }break; + case TXT_TokenKind_String: + { + if (string_is_line) + { + ender_found = (!escaped && (byte == '\r' || byte == '\n')); + } + else + { + ender_found = (!escaped && ((!string_is_char && byte == '"') || (string_is_char && byte == '\''))); + ender_pad += 1; + } + }break; + case TXT_TokenKind_Symbol: + { + ender_found = (byte != '~' && byte != '!' && + byte != '%' && byte != '^' && + byte != '&' && byte != '*' && + byte != '(' && byte != ')' && + byte != '-' && byte != '=' && + byte != '+' && byte != '[' && + byte != ']' && byte != '{' && + byte != '}' && byte != ':' && + byte != ';' && byte != ',' && + byte != '.' && byte != '<' && + byte != '>' && byte != '/' && + byte != '?' && byte != '|' && + byte != 'c'); + }break; + case TXT_TokenKind_Comment: + { + ender_found = (!escaped && (byte == '\r' || byte == '\n')); + }break; + } + } + + // rjf: next byte is ender => emit token + if(ender_found) + { + TXT_Token token = {active_token_kind, r1u64(active_token_start_idx, idx+ender_pad)}; + active_token_kind = TXT_TokenKind_Null; + + // rjf: identifier -> keyword in special cases + if(token.kind == TXT_TokenKind_Identifier) + { + read_only local_persist String8 zig_keywords[] = + { + str8_lit_comp("addrspace"), + str8_lit_comp("align"), + str8_lit_comp("allowzero"), + str8_lit_comp("and"), + str8_lit_comp("anyframe"), + str8_lit_comp("anytype"), + str8_lit_comp("asm"), + str8_lit_comp("async"), + str8_lit_comp("await"), + str8_lit_comp("break"), + str8_lit_comp("callconv"), + str8_lit_comp("catch"), + str8_lit_comp("comptime"), + str8_lit_comp("const"), + str8_lit_comp("continue"), + str8_lit_comp("defer"), + str8_lit_comp("else"), + str8_lit_comp("enum"), + str8_lit_comp("errdefer"), + str8_lit_comp("error"), + str8_lit_comp("export"), + str8_lit_comp("extern"), + str8_lit_comp("fn"), + str8_lit_comp("for"), + str8_lit_comp("if"), + str8_lit_comp("inline"), + str8_lit_comp("noalias"), + str8_lit_comp("nosuspend"), + str8_lit_comp("noinline"), + str8_lit_comp("opaque"), + str8_lit_comp("or"), + str8_lit_comp("orelse"), + str8_lit_comp("packed"), + str8_lit_comp("pub"), + str8_lit_comp("resume"), + str8_lit_comp("return"), + str8_lit_comp("linksection"), + str8_lit_comp("struct"), + str8_lit_comp("suspend"), + str8_lit_comp("switch"), + str8_lit_comp("test"), + str8_lit_comp("threadlocal"), + str8_lit_comp("try"), + str8_lit_comp("union"), + str8_lit_comp("unreachable"), + str8_lit_comp("usingnamespace"), + str8_lit_comp("var"), + str8_lit_comp("volatile"), + str8_lit_comp("while"), + }; + String8 token_string = str8_substr(string, r1u64(active_token_start_idx, idx+ender_pad)); + for(U64 keyword_idx = 0; keyword_idx < ArrayCount(zig_keywords); keyword_idx += 1) + { + if(str8_match(zig_keywords[keyword_idx], token_string, 0)) + { + token.kind = TXT_TokenKind_Keyword; + break; + } + } + } + + // rjf: push + txt_token_chunk_list_push(scratch.arena, &tokens, 4096, &token); + + // rjf: increment by ender padding + idx += ender_pad; + } + + // rjf: advance by 1 byte if we haven't found an ender + if(!ender_found) + { + idx += 1; + } + escaped = next_escaped; + } + } + + //- rjf: token list -> token array + TXT_TokenArray result = txt_token_array_from_chunk_list(arena, &tokens); + scratch_end(scratch); + return result; +} + internal TXT_TokenArray txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed_counter, String8 string) { @@ -651,6 +1146,7 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed B32 escaped = 0; B32 string_is_char = 0; S32 brace_nest = 0; + S32 paren_nest = 0; for(U64 advance = 0; off <= string.size; off += advance) { U8 byte = (off+0 < string.size) ? string.str[off+0] : 0; @@ -673,6 +1169,12 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed active_token_kind = TXT_TokenKind_Whitespace; advance = 1; } + else if(byte == '>' && brace_nest == 0 && paren_nest == 0) + { + active_token_start_off = off; + active_token_kind = TXT_TokenKind_Comment; + advance = 1; + } else if(('a' <= byte && byte <= 'z') || ('A' <= byte && byte <= 'Z') || byte == '_') { active_token_start_off = off; @@ -717,6 +1219,14 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed { brace_nest -= 1; } + if(byte == '(') + { + paren_nest += 1; + } + else if(byte == ')') + { + paren_nest -= 1; + } } else { @@ -792,6 +1302,12 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed ender_found = 1; advance = 0; }break; + case TXT_TokenKind_Comment: + if(byte == '\n') + { + ender_found = 1; + advance = 1; + }break; } if(ender_found != 0) { @@ -799,6 +1315,10 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed { active_token_kind = TXT_TokenKind_Numeric; } + if(paren_nest != 0 && active_token_kind == TXT_TokenKind_Keyword) + { + active_token_kind = TXT_TokenKind_Identifier; + } TXT_Token token = {active_token_kind, r1u64(active_token_start_off, off+advance)}; txt_token_chunk_list_push(arena, &tokens, 1024, &token); active_token_kind = TXT_TokenKind_Null; diff --git a/src/text_cache/text_cache.h b/src/text_cache/text_cache.h index 17b32ea9..529310bb 100644 --- a/src/text_cache/text_cache.h +++ b/src/text_cache/text_cache.h @@ -113,6 +113,8 @@ typedef enum TXT_LangKind TXT_LangKind_C, TXT_LangKind_CPlusPlus, TXT_LangKind_Odin, + TXT_LangKind_Jai, + TXT_LangKind_Zig, TXT_LangKind_DisasmX64Intel, TXT_LangKind_COUNT } @@ -234,6 +236,7 @@ global TXT_Shared *txt_shared = 0; //~ rjf: Basic Helpers internal TXT_LangKind txt_lang_kind_from_extension(String8 extension); +internal String8 txt_extension_from_lang_kind(TXT_LangKind kind); internal TXT_LangKind txt_lang_kind_from_architecture(Architecture arch); internal TXT_LangLexFunctionType *txt_lex_function_from_lang_kind(TXT_LangKind kind); @@ -250,6 +253,8 @@ internal TXT_TokenArray txt_token_array_from_list(Arena *arena, TXT_TokenList *l internal TXT_TokenArray txt_token_array_from_string__c_cpp(Arena *arena, U64 *bytes_processed_counter, String8 string); internal TXT_TokenArray txt_token_array_from_string__odin(Arena *arena, U64 *bytes_processed_counter, String8 string); +internal TXT_TokenArray txt_token_array_from_string__jai(Arena *arena, U64 *bytes_processed_counter, String8 string); +internal TXT_TokenArray txt_token_array_from_string__zig(Arena *arena, U64 *bytes_processed_counter, String8 string); internal TXT_TokenArray txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed_counter, String8 string); //////////////////////////////// diff --git a/src/third_party/rad_lzb_simple/rad_lzb_simple.c b/src/third_party/rad_lzb_simple/rad_lzb_simple.c new file mode 100644 index 00000000..3e6e3516 --- /dev/null +++ b/src/third_party/rad_lzb_simple/rad_lzb_simple.c @@ -0,0 +1,1402 @@ +#include + +//------------------------------------------------- +// UINTr = int the size of a register + +#ifdef __RAD64REGS__ + +#define RAD_UINTr RAD_U64 +#define RAD_SINTr RAD_S64 + +#define readR read64 +#define writeR write64 + +#define rrClzBytesR rrClzBytes64 +#define rrCtzBytesR rrCtzBytes64 + +#else + +#define RAD_UINTr RAD_U32 +#define RAD_SINTr RAD_S32 + +#define readR read32 +#define writeR write32 + +#define rrClzBytesR rrClzBytes32 +#define rrCtzBytesR rrCtzBytes32 + +#endif + +typedef RAD_SINTr SINTr; +typedef RAD_UINTr UINTr; + +#define OOINLINE RADFORCEINLINE + +#define if_unlikely(exp) if ( RAD_UNLIKELY( exp ) ) +#define if_likely( exp) if ( RAD_LIKELY( exp ) ) + +// Raw byte IO + +#if defined(__RADARM__) && !defined(__RAD64__) && defined(__GNUC__) + +// older GCCs don't turn the memcpy variant into loads/stores, but +// they do support this: +typedef union +{ + U16 u16; + U32 u32; + U64 u64; +} __attribute__((packed)) unaligned_type; + +static inline U16 read16(const void *ptr) { return ((const unaligned_type *)ptr)->u16; } +static inline void write16(void *ptr, U16 x) { ((unaligned_type *)ptr)->u16 = x; } + +static inline U32 read32(const void *ptr) { return ((const unaligned_type *)ptr)->u32; } +static inline void write32(void *ptr, U32 x) { ((unaligned_type *)ptr)->u32 = x; } + +static inline U64 read64(const void *ptr) { return ((const unaligned_type *)ptr)->u64; } +static inline void write64(void *ptr, U64 x) { ((unaligned_type *)ptr)->u64 = x; } + +#else + +// most C compilers we target are smart enough to turn this into single loads/stores +static inline U16 read16(const void *ptr) { U16 x; memcpy(&x, ptr, sizeof(x)); return x; } +static inline void write16(void *ptr, U16 x) { memcpy(ptr, &x, sizeof(x)); } + +static inline U32 read32(const void *ptr) { U32 x; memcpy(&x, ptr, sizeof(x)); return x; } +static inline void write32(void *ptr, U32 x) { memcpy(ptr, &x, sizeof(x)); } + +static inline U64 read64(const void *ptr) { U64 x; memcpy(&x, ptr, sizeof(x)); return x; } +static inline void write64(void *ptr, U64 x) { memcpy(ptr, &x, sizeof(x)); } + +#endif + +#define RR_PUT16_LE_UNALIGNED(ptr,val) RR_PUT16_LE(ptr,val) +#define RR_PUT16_LE_UNALIGNED_OFFSET(ptr,val,offset) RR_PUT16_LE_OFFSET(ptr,val,offset) + +//=========================================================================== + +static RADINLINE SINTa rrPtrDiffV(void * end, void *start) { return (SINTa)( ((char *)(end)) - ((char *)(start)) ); } + +// helper function to show I really am intending to put a pointer difference in an int : +static RADINLINE SINTa rrPtrDiff(SINTa val) { return val; } +static RADINLINE S32 rrPtrDiff32(SINTa val) { S32 ret = (S32) val; RR_ASSERT( (SINTa)ret == val ); return ret; } +static RADINLINE SINTr rrPtrDiffR(SINTa val) { SINTr ret = (SINTr) val; RR_ASSERT( (SINTa)ret == val ); return ret; } + +//================================================================= + +#define LZB_LRL_BITS 4 +#define LZB_LRL_ESCAPE 15 + +#define LZB_ML_BITS 4 +#define LZB_MLCONTROL_ESCAPE 15 + +#define LZB_SLIDING_WINDOW_POW2 16 +#define LZB_SLIDING_WINDOW_SIZE (1<>= 6; \ +if ( val < 128 ) *cp++ = (U8) val; \ +else { val -= 128; *cp++ = 128 + (U8) ( val&0x7F); val >>= 7; \ +if ( val < 128 ) *cp++ = (U8) val; \ +else { val -= 128; *cp++ = 128 + (U8) ( val&0x7F); val >>= 7; \ +if ( val < 128 ) *cp++ = (U8) val; \ +else { val -= 128; *cp++ = 128 + (U8) ( val&0x7F); val >>= 7; *cp++ = (U8) val; } } } } \ +} while(0) + +// max bytes consumed: 5 +#define LZB_AddExcessBW(cp,val) do { U32 b = *cp++; \ +if ( b < 192 ) val += b; \ +else { val += 192; val += (b-192); b = *cp++; \ +val += (b<<6); if ( b >= 128 ) { b = *cp++; \ +val += (b<<13); if ( b >= 128 ) { b = *cp++; \ +val += (b<<20); if ( b >= 128 ) { b = *cp++; \ +val += (b<<27); } } } } \ +} while(0) + +#define LZB_PutExcessLRL(cp,val) LZB_PutExcessBW(cp,val) +#define LZB_PutExcessML(cp,val) LZB_PutExcessBW(cp,val) + +#define LZB_AddExcessLRL(cp,val) LZB_AddExcessBW(cp,val) +#define LZB_AddExcessML(cp,val) LZB_AddExcessBW(cp,val) + +//============================================================================= +// match copies : + +// used for LRL : +static OOINLINE void copy_no_overlap_long(U8 * to, const U8 * from, SINTr length) +{ + for(int i=0;i= LZB_MML && ml < LZB_MATCHLEN_ESCAPE ); + + // overlap + // @@ err not awesome + to[0] = from[0]; + to[1] = from[1]; + to[2] = from[2]; + to[3] = from[3]; + to[4] = from[4]; + to[5] = from[5]; + to[6] = from[6]; + to[7] = from[7]; + if ( ml > 8 ) + { + to += 8; from += 8; ml -= 8; + // max of 10 more + while(ml--) + { + *to++ = *from++; + } + } +} + +static OOINLINE void copy_match_memset(U8 * to, int c, SINTr ml) +{ + RR_ASSERT( ml >= 4 ); + U32 four = c * 0x01010101; + U8 * end = to + ml; + write32(to, four); to += 4; + while(to>4); + + // copy 4 literals speculatively : + write32( rp , read32(cp) ); + + //RR_ASSERT( lrl >= 8 || ml_control >= 8 ); + + if ( lrl > 4 ) + { + // if lrl was <= 8 we did it, else need this : + if_unlikely ( lrl > 8 ) + { + if_unlikely ( lrl >= LZB_LRL_ESCAPE ) + { + LZB_AddExcessLRL( cp, lrl ); + + // hide the EOF check here ? + // has to be after the GetExcess + if_unlikely ( rp+lrl >= rpEnd ) + { + RR_ASSERT( rp+lrl == rpEnd ); + + copy_no_overlap_nooverrun(rp,cp,lrl); + + rp += lrl; + cp += lrl; + break; + } + else + { + // total undo of the previous copy + copy_no_overlap_long(rp,cp,lrl); + } + } + else // > 8 but not 0xF + { + // hide the EOF check here ? + if_unlikely ( rp+lrl >= rpEnd ) + { + if ( lrl == 9 ) + { + // may be a false 9 + lrl = rrPtrDiff32( rpEnd - rp ); + } + RR_ASSERT( rp+lrl == rpEnd ); + + copy_no_overlap_nooverrun(rp,cp,lrl); + + rp += lrl; + cp += lrl; + break; + } + else + { + write32( rp+4 , read32(cp+4) ); + // put 8 more : + write64( (rp+8) , read64((cp+8)) ); + } + } + } + else + { + write32( rp+4 , read32(cp+4) ); + } + } + + rp += lrl; + cp += lrl; + + RR_ASSERT( rp+LZB_MML <= rpEnd ); + + UINTr ml = ml_control + LZB_MML; + + // speculatively grab offset but don't advance cp yet + UINTr off = RR_GET16_LE_UNALIGNED(cp); + + if ( ml_control <= 8 ) + { + cp += 2; // consume offset + const U8 * match = rp - off; + + RR_ASSERT( ml <= 12 ); + + write64( rp , read64(match) ); + write32( rp+8 , read32(match+8) ); + + rp += ml; + continue; + } + else + { + + if_likely( ml_control < LZB_MLCONTROL_ESCAPE ) // short match + { + cp += 2; // consume offset + const U8 * match = rp - off; + + RR_ASSERT( off >= 8 || ml <= off ); + + write64( rp , read64(match) ); + write64( rp+8 , read64(match+8) ); + + if ( ml > 16 ) + { + write16( rp+16, read16(match+16) ); + } + } + else + { + // get 1-byte excess code + UINTr excesslow = off&127; + cp++; // consume 1 + + //if ( excess1 >= 128 ) + if ( off & 128 ) + { + ml_control = excesslow >> 3; + ml = ml_control + LZB_MML; + if ( ml_control == 0xF ) + { + // get more ml + LZB_AddExcessML( cp, ml ); + } + + UINTr myoff = off & 7; + + // low offset, can't do 8-byte grabs + if ( myoff == 1 ) + { + int c = rp[-1]; + copy_match_memset(rp,c,ml); + } + else + { + // shit but whatever, very rare + for(UINTr i=0;i>13); + return h; +} + +#define HashMatchFinder_Hash32 hmf_hash4_32 + +//================================================================================= + +#define LZB_Hash4 hmf_hash4_32 + +static RADINLINE U32 LZB_SecondHash4(U32 be4) +{ + const U32 m = 0x5bd1e995; + + U32 h = be4 * m; + h += (h>>11); + + return h; +} + +//============================================= + +static int RADFORCEINLINE GetNumBytesZeroNeverAllR(UINTr x) +{ + RR_ASSERT( x != 0 ); + +#if defined(__RADBIGENDIAN__) + // big endian, so earlier bytes are at the top + int nb = (int)rrClzBytesR(x); +#elif defined(__RADLITTLEENDIAN__) + // little endian, so earlier bytes are at the bottom + int nb = (int)rrCtzBytesR(x); +#else +#error wtf no endian set +#endif + + RR_ASSERT( nb >= 0 && nb < (int)sizeof(UINTr) ); + return nb; +} + +//=============================== + +static RADFORCEINLINE U8 * LZB_Output(U8 * cp, S32 lrl, const U8 * literals, S32 matchlen , S32 mo ) +{ + RR_ASSERT( lrl >= 0 ); + RR_ASSERT( matchlen >= LZB_MML ); + RR_ASSERT( mo > 0 && mo <= LZB_MAX_OFFSET ); + + //rrprintf("[%3d][%3d][%7d]\n",lrl,ml,mo); + + S32 sendml = matchlen - LZB_MML; + + U32 ml_in_control = RR_MIN(sendml,LZB_MLCONTROL_ESCAPE); + + if ( mo >= 8 ) // no overlap + { + if ( lrl < LZB_LRL_ESCAPE ) + { + U32 control = lrl | (ml_in_control<<4); + + *cp++ = (U8) control; + + write64(cp, read64(literals)); + if ( lrl > 8 ) + { + write64(cp+8, read64(literals+8)); + } + cp += lrl; + } + else + { + U32 control = LZB_LRL_ESCAPE | (ml_in_control<<4); + + *cp++ = (U8) control; + + U32 lrl_excess = lrl - LZB_LRL_ESCAPE; + LZB_PutExcessLRL(cp,lrl_excess); + + // @@ ? is this okay for overrun ? + lz_copysteptoend_overrunok(cp,literals,lrl); + } + + if ( ml_in_control < LZB_MLCONTROL_ESCAPE ) + { + RR_ASSERT( (U16)(mo) == mo ); + RR_PUT16_LE_UNALIGNED(cp,(U16)(mo)); + cp += 2; + } + else + { + U32 ml_excess = sendml - LZB_MLCONTROL_ESCAPE; + + // put special first byte, then offset, then remainder + if ( ml_excess < 127 ) + { + *cp++ = (U8)ml_excess; + + RR_ASSERT( (U16)(mo) == mo ); + RR_PUT16_LE_UNALIGNED(cp,(U16)(mo)); + cp += 2; + } + else + { + *cp++ = (U8)127; + + RR_ASSERT( (U16)(mo) == mo ); + RR_PUT16_LE_UNALIGNED(cp,(U16)(mo)); + cp += 2; + + ml_excess -= 127; + LZB_PutExcessML(cp,ml_excess); + } + } + } + else + { + U32 lrl_in_control = RR_MIN(lrl,LZB_LRL_ESCAPE); + + // overlap case + U32 control = (lrl_in_control) | (LZB_MLCONTROL_ESCAPE<<4); + + *cp++ = (U8) control; + + if ( lrl_in_control == LZB_LRL_ESCAPE ) + { + U32 lrl_excess = lrl - LZB_LRL_ESCAPE; + LZB_PutExcessLRL(cp,lrl_excess); + } + + lz_copysteptoend_overrunok(cp,literals,lrl); + //cp += lrl; + + // special excess1 : + UINTr excess1 = 128 + (ml_in_control<<3) + mo; + RR_ASSERT( excess1 < 256 ); + + *cp++ = (U8)excess1; + + if ( ml_in_control == LZB_MLCONTROL_ESCAPE ) + { + U32 ml_excess = sendml - LZB_MLCONTROL_ESCAPE; + LZB_PutExcessML(cp,ml_excess); + } + } + + return cp; +} + +#if LZB_FORCELASTLRL9 + +static RADINLINE U8 * LZB_OutputLast(U8 * cp, S32 lrl, const U8 * literals ) +{ + RR_ASSERT( lrl >= 0 ); + + //U32 ml = 0; + //U32 mo = 0; + + U32 lrl_in_control = RR_MIN(lrl,LZB_LRL_ESCAPE); + +#if LZB_END_WITH_LITERALS + // lrl_in_control must be at least 9 + lrl_in_control = RR_MAX(lrl_in_control,9); +#endif + + U32 control = lrl_in_control; + + *cp++ = (U8) control; + + if ( lrl_in_control == LZB_LRL_ESCAPE ) + { + U32 lrl_excess = lrl - LZB_LRL_ESCAPE; + LZB_PutExcessLRL(cp,lrl_excess); + } + + memmove(cp,literals,lrl); + cp += lrl; + + return cp; +} + +#else + +static RADINLINE U8 * LZB_OutputLast(U8 * cp, S32 lrl, const U8 * literals ) +{ + cp = LZB_Output(cp,lrl,literals,LZB_MML,1); + + // remove the offset we put : + cp -= 2; + + return cp; +} + +#endif + +//=============================================================== + +static void rr_lzb_simple_context_init(rr_lzb_simple_context * ctx) //, const void * base) +{ + RR_ASSERT( ctx->m_tableSizeBits >= 12 && ctx->m_tableSizeBits <= 24 ); + memset(ctx->m_hashTable,0,sizeof(U16)*((SINTa)1<m_tableSizeBits)); +} + +//=============================================================== + +/* +#define FAST_HASH_DEPTH_SHIFT (1) // more depth = more & more compression, +#define DO_FAST_2ND_HASH // rate= 30.69 mb/s , 15451369 <- turning this off is the best way to get more speed and less compression +/*/ +#define FAST_HASH_DEPTH_SHIFT (0) +#define DO_FAST_2ND_HASH +/**/ + +// lzt99, 24700820, 15475520, 16677179 +//encode only : 0.880 seconds, 1.62 b/hc, rate= 28.08 mb/s + +//#define FAST_HASH_DEPTH_SHIFT (1) // more depth = more & more compression, but slower + +#define DO_FAST_UPDATE_MATCH_HASHES 1 // helps compression a lot , like 0.30 +//#define DO_FAST_UPDATE_MATCH_HASHES 2 // helps compression a lot , like 0.30 +#define DO_FAST_LAZY_MATCH // also helps a lot , like 0.15 +#define DO_FAST_HASH_DWORD 1 + +#define FAST_MULTISTEP_LITERALS_SHIFT (5) + + +//----------------------- +// derived : + +/* +#define FAST_HASH_BITS (FAST_HASH_TOTAL_BITS-FAST_HASH_DEPTH_SHIFT) +#define FAST_HASH_SIZE (1< 1 +#define FAST_HASH_INDEX(h,d) ( ((h)< 1 + int hashCycle = 0; +#endif + + U16 * hashTable16 = fh->m_hashTable; + + int hashTableSizeBits = fh->m_tableSizeBits; + U32 hash_table_mask = (U32)((1UL<<(hashTableSizeBits - FAST_HASH_DEPTH_SHIFT)) - 1); + + const U8 * zeroPosPtr = (const U8 *)raw; + + // first byte is always a literal + rp++; + + for(;;) + { + S32 matchOff; + + UINTr failedMatches = (1<= 0 ); + +#ifdef DO_FAST_2ND_HASH + hash2 = ( LZB_SecondHash4(rp32) ) & hash_table_mask; +#endif + +#if FAST_HASH_DEPTH > 1 + for(int d=0;d= 0 ); + + hashrp = rp - matchOff; + + //if ( matchOff <= LZB_MAX_OFFSET ) + RR_ASSERT( matchOff <= LZB_MAX_OFFSET ); + { + const U32 hashrp32 = read32(hashrp); + + if ( rp32 == hashrp32 && matchOff != 0 ) + { + goto found_match; + } + } + } + +#ifdef DO_FAST_2ND_HASH + +#if FAST_HASH_DEPTH > 1 + for(int d=0;d= 0 ); + + hashrp = rp - matchOff; + + RR_ASSERT( matchOff <= LZB_MAX_OFFSET ); + { + const U32 hashrp32 = read32(hashrp); + + if ( rp32 == hashrp32 && matchOff != 0 ) + { + goto found_match; + } + } + } + +#endif + + //--------------------------- + // update hash : + + hashTable16[ FAST_HASH_INDEX(hash,hashCycle) ] = (U16) curpos; + +#ifdef DO_FAST_2ND_HASH + // do NOT step hashCycle ! + //hashCycle = (hashCycle+1)&FAST_HASH_CYCLE_MASK; + hashTable16[ FAST_HASH_INDEX(hash2,hashCycle) ] = (U16) curpos; +#endif + +#if FAST_HASH_DEPTH > 1 + hashCycle = (hashCycle+1)&FAST_HASH_CYCLE_MASK; +#endif + + UINTr stepLiterals = (failedMatches>>FAST_MULTISTEP_LITERALS_SHIFT); + RR_ASSERT( stepLiterals >= 1 ); + + ++failedMatches; + + rp += stepLiterals; + + if ( rp >= rpEndSafe ) + goto done; + + rp32 = read32(rp); + hash = FAST_HASH_FUNC(rp, rp32 ); + + } + + //------------------------------- + found_match: + + // found something + + //------------------------- + // update hash now so lazy can see it : + +#if 1 // pretty important to compression + hashTable16[ FAST_HASH_INDEX(hash,hashCycle) ] = (U16) curpos; + +#ifdef DO_FAST_2ND_HASH + // do NOT step hashCycle ! + //hashCycle = (hashCycle+1)&FAST_HASH_CYCLE_MASK; + hashTable16[ FAST_HASH_INDEX(hash2,hashCycle) ] = (U16) curpos; +#endif + +#if FAST_HASH_DEPTH > 1 + hashCycle = (hashCycle+1)&FAST_HASH_CYCLE_MASK; +#endif +#endif + + //----------------------------------- + + const U8 * match_start = rp; + rp += 4; + + while( rp < rpEndSafe ) + { + UINTr big1 = readR(rp); + UINTr big2 = readR(rp-matchOff); + + if ( big1 == big2 ) + { + rp += RAD_PTRBYTES; + continue; + } + else + { + rp += GetNumBytesZeroNeverAllR(big1^big2); + break; + } + } + rp = RR_MIN(rp,rpMatchEnd); + + //------------------------------- + // rp is now at the *end* of the match + + //------------------------------- + + // check lazy match too +#ifdef DO_FAST_LAZY_MATCH + if (rp< rpEndSafe) + { + const U8 * lazyrp = match_start + 1; + //SINTa lazypos = rrPtrDiff(lazyrp - zeroPosPtr); + SINTa lazypos = curpos + 1; + RR_ASSERT( lazypos == rrPtrDiff(lazyrp - zeroPosPtr) ); + + U32 lazyrp32 = read32(lazyrp); + + const U8 * lazyhashrp; + SINTa lazymatchOff; + + U32 lazyHash = FAST_HASH_FUNC(lazyrp, lazyrp32 ); + +#ifdef DO_FAST_2ND_HASH + U32 lazyhash2 = LZB_SecondHash4(lazyrp32) & hash_table_mask; +#endif + +#if FAST_HASH_DEPTH > 1 + for(int d=0;d= 0 ); + + RR_ASSERT( lazymatchOff <= LZB_MAX_OFFSET ); + { + lazyhashrp = lazyrp - lazymatchOff; + + const U32 hashrp32 = read32(lazyhashrp); + + if ( lazyrp32 == hashrp32 && lazymatchOff != 0 ) + { + goto lazy_found_match; + } + } + } + +#ifdef DO_FAST_2ND_HASH +#if FAST_HASH_DEPTH > 1 + for(int d=0;d= 0 ); + + RR_ASSERT( lazymatchOff <= LZB_MAX_OFFSET ); + { + lazyhashrp = lazyrp - lazymatchOff; + + const U32 hashrp32 = read32(lazyhashrp); + + if ( lazyrp32 == hashrp32 && lazymatchOff != 0 ) + { + goto lazy_found_match; + } + } + } +#endif + + if ( 0 ) + { + lazy_found_match: + + lazyrp += 4; + + while( lazyrp < rpEndSafe ) + { + UINTr big1 = readR(lazyrp); + UINTr big2 = readR(lazyrp-lazymatchOff); + + if ( big1 == big2 ) + { + lazyrp += RAD_PTRBYTES; + continue; + } + else + { + lazyrp += GetNumBytesZeroNeverAllR(big1^big2); + break; + } + } + lazyrp = RR_MIN(lazyrp,rpMatchEnd); + + //S32 lazymatchLen = rrPtrDiff32( lazyrp - (match_start+1) ); + //RR_ASSERT( lazymatchLen >= 4 ); + + if ( lazyrp >= rp+3 ) + { + // yes take the lazy match + + // put a literal : + match_start++; + + // I had a bug where lazypos was set wrong for the hash fill + // it set it to the *end* of the normal match + // and for some reason that helped compression WTF WTF + //SINTa lazypos = rrPtrDiff(rp - zeroPosPtr); // 233647528 + // with correct lazypos : 233651228 + + // really this shouldn't be necessary at all + // because I do an update of hash at all positions in the match including first! +#if 1 // with update disabled - 233690274 + + hashTable16[ FAST_HASH_INDEX(lazyHash,hashCycle) ] = (U16) lazypos; + +#ifdef DO_FAST_2ND_HASH + // do NOT step hashCycle ! + hashTable16[ FAST_HASH_INDEX(lazyhash2,hashCycle) ] = (U16) lazypos; +#endif + +#if FAST_HASH_DEPTH > 1 + hashCycle = (hashCycle+1)&FAST_HASH_CYCLE_MASK; +#endif + +#endif + + // and then drop out and do the lazy match : + //matchLen = lazymatchLen; + matchOff = (S32)lazymatchOff; + rp = lazyrp; + hashrp = lazyhashrp; + } + } + } +#endif + + //--------------------------------------------------- + + // back up start of match that we missed due to stepLiterals ! + // make sure we don't read off the start of the array + + // this costs a little speed and gains a little compression + // 15662162 at 121.58 mb/s + // 15776473 at 127.92 mb/s +#if 1 + /* + lzbf : 24,700,820 ->15,963,503 = 5.170 bpb = 1.547 to 1 + encode : 0.171 seconds, 83.60 b/kc, rate= 144.54 M/s + decode : 0.014 seconds, 1002.64 b/kc, rate= 1733.57 M/s + */ + { + // 144 M/s + // back up start of match that we missed + // make sure we don't read off the start of the array + + const U8 * rpm1 = match_start-1; + if ( rpm1 >= literals_start && hashrp > zeroPosPtr && rpm1[0] == hashrp[-1] ) + { + rpm1--; hashrp-= 2; + + while ( rpm1 >= literals_start && hashrp >= zeroPosPtr && rpm1[0] == *hashrp ) + { + rpm1--; + hashrp--; + } + + match_start = rpm1+1; + //rp = RR_MAX(rp,literals_start); + RR_ASSERT( match_start >= literals_start ); + } + } +#endif + + S32 matchLen = rrPtrDiff32( rp - match_start ); + RR_ASSERT( matchLen >= 4 ); + + //=============================================== + // chose a match + // output LRL (if any) and match + + S32 cur_lrl = rrPtrDiff32(match_start - literals_start); + + // catch expansion while writing : + if_unlikely ( cp+cur_lrl >= compExpandedPtr ) + { + return rawLen+1; + } + + cp = LZB_Output(cp,cur_lrl,literals_start,matchLen,matchOff); + + // skip the match : + literals_start = rp; + + if ( rp >= rpEndSafe ) + break; + + // step & update hashes : + // (I already did cur pos) +#ifdef DO_FAST_UPDATE_MATCH_HASHES + // don't bother if it takes us to the end : + // (this check is not for speed it's to avoid the access violation) + const U8 * ptr = match_start+1; + U16 pos16 = (U16) rrPtrDiff( ptr - zeroPosPtr ); + for(;ptr 0 ); +#endif + + if ( cur_lrl > 0 ) + { + // catch expansion while writing : + if ( cp+cur_lrl >= compExpandedPtr ) + { + return rawLen+1; + } + + cp = LZB_OutputLast(cp,cur_lrl,literals_start); + } + + SINTa compLen = rrPtrDiff( cp - (U8 *)comp ); + + return compLen; +} + +SINTa rr_lzb_simple_encode_fast(rr_lzb_simple_context * fh, + const void * raw, SINTa rawLen, void * comp) +{ + rr_lzb_simple_context_init(fh); //,raw); + + SINTa comp_len = rr_lzb_simple_encode_fast_sub(fh,raw,rawLen,comp); + if ( comp_len >= rawLen ) + { + memcpy(comp,raw,rawLen); + return rawLen; + } + return comp_len; +} + +#undef FAST_HASH_DEPTH_SHIFT + +#undef DO_FAST_UPDATE_MATCH_HASHES +#undef DO_FAST_LAZY_MATCH +#undef DO_FAST_2ND_HASH + +//===================================================== + +#define FAST_HASH_DEPTH_SHIFT (0) + +#undef FAST_MULTISTEP_LITERALS_SHIFT +#define FAST_MULTISTEP_LITERALS_SHIFT (4) + + + +//----------------------- +// derived : + +RR_COMPILER_ASSERT( FAST_HASH_DEPTH_SHIFT == 0 ); + +#undef FAST_HASH_FUNC +//#define FAST_HASH_FUNC(ptr,dword) ( LZB_Hash4(dword) & hash_table_mask ) +#define FAST_HASH_FUNC(ptr,dword) ( (((dword)*2654435761U)>>16) & hash_table_mask ) + + +// @@@@ ???? +#define LZBVF_DO_BACKUP 0 +//#define LZBVF_DO_BACKUP 1 + + +static SINTa rr_lzb_simple_encode_veryfast_sub(rr_lzb_simple_context * fh, + const void * raw, SINTa rawLen, void * comp) +{ + //SIMPLEPROFILE_SCOPE_N(lzbfast_sub,rawLen); + //THREADPROFILEFUNC(); + + U8 * cp = (U8 *)comp; + U8 * compExpandedPtr = cp + rawLen - 8; + + const U8 * rp = (const U8 *)raw; + const U8 * rpEnd = rp+rawLen; + + // we can match up to rpEnd + // but matches can't start past rpEndSafe + const U8 * rpMatchEnd = rpEnd - LZB_END_OF_BLOCK_NO_MATCH_ZONE; + + const U8 * rpEndSafe = rpMatchEnd - LZB_MML; + + if ( rpEndSafe <= raw ) + { + // can't compress + return rawLen+1; + } + + const U8 * literals_start = rp; + + U16 * hashTable16 = fh->m_hashTable; + int hashTableSizeBits = fh->m_tableSizeBits; + U32 hash_table_mask = (U32)((1UL<<(hashTableSizeBits)) - 1); + + const U8 * zeroPosPtr = (const U8 *)raw; + + // first byte is always a literal + rp++; + + for(;;) + { + U32 rp32 = read32(rp); + U32 hash = FAST_HASH_FUNC(rp, rp32 ); + const U8 * hashrp; + S32 matchOff; + UINTr failedMatches; + + // loop while no match found : + + // first loop with step = 1 + // @@ + //int step1count = (1<= 0 ); + + U16 hashpos16 = hashTable16[hash]; + hashTable16[ hash ] = (U16) curpos; + + matchOff = (U16)(curpos - hashpos16); + RR_ASSERT( matchOff >= 0 && matchOff <= LZB_MAX_OFFSET ); + hashrp = rp - matchOff; + + const U32 hashrp32 = read32(hashrp); + if ( rp32 == hashrp32 && matchOff != 0 ) + { + goto found_match; + } + + if ( ++rp >= rpEndSafe ) + goto done; + + rp32 = read32(rp); + hash = FAST_HASH_FUNC(rp, rp32 ); + } + + // step starts at 2 : + failedMatches = (2<= 0 ); + + U16 hashpos16 = hashTable16[hash]; + hashTable16[ hash ] = (U16) curpos; + + matchOff = (U16)(curpos - hashpos16); + RR_ASSERT( matchOff >= 0 && matchOff <= LZB_MAX_OFFSET ); + hashrp = rp - matchOff; + + const U32 hashrp32 = read32(hashrp); + + if ( rp32 == hashrp32 && matchOff != 0 ) + { + goto found_match; + } + + UINTr stepLiterals = (failedMatches>>FAST_MULTISTEP_LITERALS_SHIFT); + RR_ASSERT( stepLiterals >= 1 ); + + ++failedMatches; + + rp += stepLiterals; + + if ( rp >= rpEndSafe ) + goto done; + + rp32 = read32(rp); + hash = FAST_HASH_FUNC(rp, rp32 ); + } + + //------------------------------- + found_match: + + // found something + +#if LZBVF_DO_BACKUP + + // alternative backup using counter : + S32 cur_lrl = rrPtrDiff32(rp - literals_start); + int neg_max_backup = - RR_MIN(cur_lrl , rrPtrDiff32(hashrp - zeroPosPtr) ); + int neg_backup = -1; + if( neg_backup >= neg_max_backup && rp[neg_backup] == hashrp[neg_backup] ) + { + neg_backup--; + while( neg_backup >= neg_max_backup && rp[neg_backup] == hashrp[neg_backup] ) + { + neg_backup--; + } + neg_backup++; + rp += neg_backup; + cur_lrl += neg_backup; + RR_ASSERT( cur_lrl >= 0 ); + RR_ASSERT( cur_lrl == rrPtrDiff32(rp - literals_start) ); + } + +#else + + S32 cur_lrl = rrPtrDiff32(rp - literals_start); + +#endif + + // catch expansion while writing : + if_unlikely ( cp+cur_lrl >= compExpandedPtr ) + { + return rawLen+1; + } + + RR_ASSERT( matchOff >= 1 ); + + //--------------------------------------- + // find rest of match len + // save pointer to start of match + // walk rp ahead to end of match + const U8 * match_start = rp; + rp += 4; + + while( rp < rpEndSafe ) + { + UINTr big1 = readR(rp); + UINTr big2 = readR(rp-matchOff); + + if ( big1 == big2 ) + { + rp += RAD_PTRBYTES; + continue; + } + else + { + rp += GetNumBytesZeroNeverAllR(big1^big2); + break; + } + } + rp = RR_MIN(rp,rpMatchEnd); + S32 matchLen = rrPtrDiff32( rp - match_start ); + + //=============================================== + // chose a match + // output LRL (if any) and match + + cp = LZB_Output(cp,cur_lrl,literals_start,matchLen,matchOff); + + // skip the match : + literals_start = rp; + + if ( rp >= rpEndSafe ) + goto done; + } + + done: + + int cur_lrl = rrPtrDiff32(rpEnd - literals_start); +#if LZB_END_WITH_LITERALS + RR_ASSERT_ALWAYS(cur_lrl > 0 ); +#endif + + if ( cur_lrl > 0 ) + { + // catch expansion while writing : + if ( cp+cur_lrl >= compExpandedPtr ) + { + return rawLen+1; + } + + cp = LZB_OutputLast(cp,cur_lrl,literals_start); + } + + SINTa compLen = rrPtrDiff( cp - (U8 *)comp ); + + return compLen; +} + +SINTa rr_lzb_simple_encode_veryfast(rr_lzb_simple_context * fh, + const void * raw, SINTa rawLen, void * comp) +{ + rr_lzb_simple_context_init(fh); //,raw); + + SINTa comp_len = rr_lzb_simple_encode_veryfast_sub(fh,raw,rawLen,comp); + if ( comp_len >= rawLen ) + { + memcpy(comp,raw,rawLen); + return rawLen; + } + return comp_len; +} + +#undef FAST_HASH_DEPTH_SHIFT + +#undef DO_FAST_UPDATE_MATCH_HASHES +#undef DO_FAST_LAZY_MATCH +#undef DO_FAST_2ND_HASH + +//===================================================== +// vim:noet:sw=4:ts=4 diff --git a/src/third_party/rad_lzb_simple/rad_lzb_simple.h b/src/third_party/rad_lzb_simple/rad_lzb_simple.h new file mode 100644 index 00000000..c1e5e96e --- /dev/null +++ b/src/third_party/rad_lzb_simple/rad_lzb_simple.h @@ -0,0 +1,141 @@ +#ifndef _RAD_LZB_SIMPLE_H_ +#define _RAD_LZB_SIMPLE_H_ + +/*====================================================== + +To encode : + + Set up an rr_lzb_simple_context + + fill out m_tableSizeBits (14-16 is typical) + + allocate m_hashTable + + rr_lzb_simple_context c; + c.m_tableSizeBits = 14; + c.m_hashTable = OODLE_MALLOC_ARRAY(U16,RR_ONE_SA< +typedef uint8_t U8; +typedef uint16_t U16; +typedef uint32_t U32; +typedef uint64_t U64; +typedef int8_t S8; +typedef int16_t S16; +typedef int32_t S32; +typedef int64_t S64; + +typedef S64 SINTa; +typedef U64 RAD_U64; +typedef S64 RAD_S64; +typedef U32 RAD_U32; +typedef S32 RAD_S32; + +#define RADINLINE __inline + +#if defined(_MSC_VER) +# define RADFORCEINLINE __forceinline +#elif defined(__clang__) +# define RADFORCEINLINE __attribute__((always_inline)) +#else +# error need force inline for this compiler +#endif + +#define RR_STRING_JOIN(arg1, arg2) RR_STRING_JOIN_DELAY(arg1, arg2) +#define RR_STRING_JOIN_DELAY(arg1, arg2) RR_STRING_JOIN_IMMEDIATE(arg1, arg2) +#define RR_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2 + +#ifdef _MSC_VER +#define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__COUNTER__) +#else +#define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__LINE__) +#endif + +#define RR_COMPILER_ASSERT(exp) typedef char RR_NUMBERNAME(_dummy_array) [ (exp) ? 1 : -1 ] + +#if defined(__clang__) +# define Expect(expr, val) __builtin_expect((expr), (val)) +#else +# define Expect(expr, val) (expr) +#endif + +#define RAD_LIKELY(expr) Expect(expr,1) +#define RAD_UNLIKELY(expr) Expect(expr,0) + +#define __RADLITTLEENDIAN__ 1 +#define RAD_PTRBYTES 8 +#define RR_MIN(a,b) ( (a) < (b) ? (a) : (b) ) +#define RR_MAX(a,b) ( (a) > (b) ? (a) : (b) ) +#define RR_ASSERT_ALWAYS(c) do{if(!(c)) {__debugbreak();}}while(0) +#define RR_ASSERT(c) RR_ASSERT_ALWAYS(c) + +#define RR_PUT16_LE(ptr,val) *((U16 *)(ptr)) = (U16)(val) +#define RR_GET16_LE_UNALIGNED(ptr) *((const U16 *)(ptr)) + +static RADINLINE U32 +rrCtzBytes32(U32 val) +{ + // Don't get fancy here. Assumes val != 0. + if (val & 0x000000ffu) return 0; + if (val & 0x0000ff00u) return 1; + if (val & 0x00ff0000u) return 2; + return 3; +} + +static RADINLINE U32 +rrCtzBytes64(U64 val) +{ + U32 lo = (U32) val; + return lo ? rrCtzBytes32(lo) : 4 + rrCtzBytes32((U32) (val >> 32)); +} + +//~ + +//--------------------- + +typedef struct rr_lzb_simple_context rr_lzb_simple_context; +struct rr_lzb_simple_context +{ + U16 * m_hashTable; // must be allocated to sizeof(U16)*(1< +#endif // STBI_NO_STDIO + +#define STBI_VERSION 1 + +enum +{ + STBI_default = 0, // only used for desired_channels + + STBI_grey = 1, + STBI_grey_alpha = 2, + STBI_rgb = 3, + STBI_rgb_alpha = 4 +}; + +#include +typedef unsigned char stbi_uc; +typedef unsigned short stbi_us; + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef STBIDEF +#ifdef STB_IMAGE_STATIC +#define STBIDEF static +#else +#define STBIDEF extern +#endif +#endif + + ////////////////////////////////////////////////////////////////////////////// + // + // PRIMARY API - works on images of any type + // + + // + // load image by filename, open file, or memory buffer + // + + typedef struct + { + int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read + void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative + int (*eof) (void *user); // returns nonzero if we are at end of file/data + } stbi_io_callbacks; + + //////////////////////////////////// + // + // 8-bits-per-channel interface + // + + STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels); + +#ifndef STBI_NO_STDIO + STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); + // for stbi_load_from_file, file pointer is left pointing immediately after image +#endif + +#ifndef STBI_NO_GIF + STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp); +#endif + +#ifdef STBI_WINDOWS_UTF8 + STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input); +#endif + + //////////////////////////////////// + // + // 16-bits-per-channel interface + // + + STBIDEF stbi_us *stbi_load_16_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); + +#ifndef STBI_NO_STDIO + STBIDEF stbi_us *stbi_load_16 (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); +#endif + + //////////////////////////////////// + // + // float-per-channel interface + // +#ifndef STBI_NO_LINEAR + STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); + +#ifndef STBI_NO_STDIO + STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); +#endif +#endif + +#ifndef STBI_NO_HDR + STBIDEF void stbi_hdr_to_ldr_gamma(float gamma); + STBIDEF void stbi_hdr_to_ldr_scale(float scale); +#endif // STBI_NO_HDR + +#ifndef STBI_NO_LINEAR + STBIDEF void stbi_ldr_to_hdr_gamma(float gamma); + STBIDEF void stbi_ldr_to_hdr_scale(float scale); +#endif // STBI_NO_LINEAR + + // stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR + STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user); + STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len); +#ifndef STBI_NO_STDIO + STBIDEF int stbi_is_hdr (char const *filename); + STBIDEF int stbi_is_hdr_from_file(FILE *f); +#endif // STBI_NO_STDIO + + + // get a VERY brief reason for failure + // on most compilers (and ALL modern mainstream compilers) this is threadsafe + STBIDEF const char *stbi_failure_reason (void); + + // free the loaded image -- this is just free() + STBIDEF void stbi_image_free (void *retval_from_stbi_load); + + // get image dimensions & components without fully decoding + STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); + STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp); + STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len); + STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user); + +#ifndef STBI_NO_STDIO + STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp); + STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp); + STBIDEF int stbi_is_16_bit (char const *filename); + STBIDEF int stbi_is_16_bit_from_file(FILE *f); +#endif + + + + // for image formats that explicitly notate that they have premultiplied alpha, + // we just return the colors as stored in the file. set this flag to force + // unpremultiplication. results are undefined if the unpremultiply overflow. + STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); + + // indicate whether we should process iphone images back to canonical format, + // or just pass them through "as-is" + STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert); + + // flip the image vertically, so the first pixel in the output array is the bottom left + STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip); + + // as above, but only applies to images loaded on the thread that calls the function + // this function is only available if your compiler supports thread-local variables; + // calling it will fail to link if your compiler doesn't + STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply); + STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert); + STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip); + + // ZLIB client - used by PNG, available for other purposes + + STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); + STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header); + STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen); + STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); + + STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen); + STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); + + +#ifdef __cplusplus +} +#endif + +// +// +//// end header file ///////////////////////////////////////////////////// +#endif // STBI_INCLUDE_STB_IMAGE_H + +#ifdef STB_IMAGE_IMPLEMENTATION + +#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) \ +|| defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \ +|| defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \ +|| defined(STBI_ONLY_ZLIB) +#ifndef STBI_ONLY_JPEG +#define STBI_NO_JPEG +#endif +#ifndef STBI_ONLY_PNG +#define STBI_NO_PNG +#endif +#ifndef STBI_ONLY_BMP +#define STBI_NO_BMP +#endif +#ifndef STBI_ONLY_PSD +#define STBI_NO_PSD +#endif +#ifndef STBI_ONLY_TGA +#define STBI_NO_TGA +#endif +#ifndef STBI_ONLY_GIF +#define STBI_NO_GIF +#endif +#ifndef STBI_ONLY_HDR +#define STBI_NO_HDR +#endif +#ifndef STBI_ONLY_PIC +#define STBI_NO_PIC +#endif +#ifndef STBI_ONLY_PNM +#define STBI_NO_PNM +#endif +#endif + +#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB) +#define STBI_NO_ZLIB +#endif + + +#include +#include // ptrdiff_t on osx +#include +#include +#include + +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +#include // ldexp, pow +#endif + +#ifndef STBI_NO_STDIO +#include +#endif + +#ifndef STBI_ASSERT +#include +#define STBI_ASSERT(x) assert(x) +#endif + +#ifdef __cplusplus +#define STBI_EXTERN extern "C" +#else +#define STBI_EXTERN extern +#endif + + +#ifndef _MSC_VER +#ifdef __cplusplus +#define stbi_inline inline +#else +#define stbi_inline +#endif +#else +#define stbi_inline __forceinline +#endif + +#ifndef STBI_NO_THREAD_LOCALS +#if defined(__cplusplus) && __cplusplus >= 201103L +#define STBI_THREAD_LOCAL thread_local +#elif defined(__GNUC__) && __GNUC__ < 5 +#define STBI_THREAD_LOCAL __thread +#elif defined(_MSC_VER) +#define STBI_THREAD_LOCAL __declspec(thread) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) +#define STBI_THREAD_LOCAL _Thread_local +#endif + +#ifndef STBI_THREAD_LOCAL +#if defined(__GNUC__) +#define STBI_THREAD_LOCAL __thread +#endif +#endif +#endif + +#if defined(_MSC_VER) || defined(__SYMBIAN32__) +typedef unsigned short stbi__uint16; +typedef signed short stbi__int16; +typedef unsigned int stbi__uint32; +typedef signed int stbi__int32; +#else +#include +typedef uint16_t stbi__uint16; +typedef int16_t stbi__int16; +typedef uint32_t stbi__uint32; +typedef int32_t stbi__int32; +#endif + +// should produce compiler error if size is wrong +typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; + +#ifdef _MSC_VER +#define STBI_NOTUSED(v) (void)(v) +#else +#define STBI_NOTUSED(v) (void)sizeof(v) +#endif + +#ifdef _MSC_VER +#define STBI_HAS_LROTL +#endif + +#ifdef STBI_HAS_LROTL +#define stbi_lrot(x,y) _lrotl(x,y) +#else +#define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (-(y) & 31))) +#endif + +#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED)) +// ok +#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED) +// ok +#else +#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)." +#endif + +#ifndef STBI_MALLOC +#define STBI_MALLOC(sz) malloc(sz) +#define STBI_REALLOC(p,newsz) realloc(p,newsz) +#define STBI_FREE(p) free(p) +#endif + +#ifndef STBI_REALLOC_SIZED +#define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz) +#endif + +// x86/x64 detection +#if defined(__x86_64__) || defined(_M_X64) +#define STBI__X64_TARGET +#elif defined(__i386) || defined(_M_IX86) +#define STBI__X86_TARGET +#endif + +#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) +// gcc doesn't support sse2 intrinsics unless you compile with -msse2, +// which in turn means it gets to use SSE2 everywhere. This is unfortunate, +// but previous attempts to provide the SSE2 functions with runtime +// detection caused numerous issues. The way architecture extensions are +// exposed in GCC/Clang is, sadly, not really suited for one-file libs. +// New behavior: if compiled with -msse2, we use SSE2 without any +// detection; if not, we don't use it at all. +#define STBI_NO_SIMD +#endif + +#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD) +// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET +// +// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the +// Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant. +// As a result, enabling SSE2 on 32-bit MinGW is dangerous when not +// simultaneously enabling "-mstackrealign". +// +// See https://github.com/nothings/stb/issues/81 for more information. +// +// So default to no SSE2 on 32-bit MinGW. If you've read this far and added +// -mstackrealign to your build settings, feel free to #define STBI_MINGW_ENABLE_SSE2. +#define STBI_NO_SIMD +#endif + +#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) +#define STBI_SSE2 +#include + +#ifdef _MSC_VER + +#if _MSC_VER >= 1400 // not VC6 +#include // __cpuid +static int stbi__cpuid3(void) +{ + int info[4]; + __cpuid(info,1); + return info[3]; +} +#else +static int stbi__cpuid3(void) +{ + int res; + __asm { + mov eax,1 + cpuid + mov res,edx + } + return res; +} +#endif + +#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name + +#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2) +static int stbi__sse2_available(void) +{ + int info3 = stbi__cpuid3(); + return ((info3 >> 26) & 1) != 0; +} +#endif + +#else // assume GCC-style if not VC++ +#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) + +#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2) +static int stbi__sse2_available(void) +{ + // If we're even attempting to compile this on GCC/Clang, that means + // -msse2 is on, which means the compiler is allowed to use SSE2 + // instructions at will, and so are we. + return 1; +} +#endif + +#endif +#endif + +// ARM NEON +#if defined(STBI_NO_SIMD) && defined(STBI_NEON) +#undef STBI_NEON +#endif + +#ifdef STBI_NEON +#include +#ifdef _MSC_VER +#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name +#else +#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) +#endif +#endif + +#ifndef STBI_SIMD_ALIGN +#define STBI_SIMD_ALIGN(type, name) type name +#endif + +#ifndef STBI_MAX_DIMENSIONS +#define STBI_MAX_DIMENSIONS (1 << 24) +#endif + +/////////////////////////////////////////////// +// +// stbi__context struct and start_xxx functions + +// stbi__context structure is our basic context used by all images, so it +// contains all the IO context, plus some basic image information +typedef struct +{ + stbi__uint32 img_x, img_y; + int img_n, img_out_n; + + stbi_io_callbacks io; + void *io_user_data; + + int read_from_callbacks; + int buflen; + stbi_uc buffer_start[128]; + int callback_already_read; + + stbi_uc *img_buffer, *img_buffer_end; + stbi_uc *img_buffer_original, *img_buffer_original_end; +} stbi__context; + + +static void stbi__refill_buffer(stbi__context *s); + +// initialize a memory-decode context +static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len) +{ + s->io.read = NULL; + s->read_from_callbacks = 0; + s->callback_already_read = 0; + s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer; + s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len; +} + +// initialize a callback-based context +static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user) +{ + s->io = *c; + s->io_user_data = user; + s->buflen = sizeof(s->buffer_start); + s->read_from_callbacks = 1; + s->callback_already_read = 0; + s->img_buffer = s->img_buffer_original = s->buffer_start; + stbi__refill_buffer(s); + s->img_buffer_original_end = s->img_buffer_end; +} + +#ifndef STBI_NO_STDIO + +static int stbi__stdio_read(void *user, char *data, int size) +{ + return (int) fread(data,1,size,(FILE*) user); +} + +static void stbi__stdio_skip(void *user, int n) +{ + int ch; + fseek((FILE*) user, n, SEEK_CUR); + ch = fgetc((FILE*) user); /* have to read a byte to reset feof()'s flag */ + if (ch != EOF) { + ungetc(ch, (FILE *) user); /* push byte back onto stream if valid. */ + } +} + +static int stbi__stdio_eof(void *user) +{ + return feof((FILE*) user) || ferror((FILE *) user); +} + +static stbi_io_callbacks stbi__stdio_callbacks = +{ + stbi__stdio_read, + stbi__stdio_skip, + stbi__stdio_eof, +}; + +static void stbi__start_file(stbi__context *s, FILE *f) +{ + stbi__start_callbacks(s, &stbi__stdio_callbacks, (void *) f); +} + +//static void stop_file(stbi__context *s) { } + +#endif // !STBI_NO_STDIO + +static void stbi__rewind(stbi__context *s) +{ + // conceptually rewind SHOULD rewind to the beginning of the stream, + // but we just rewind to the beginning of the initial buffer, because + // we only use it after doing 'test', which only ever looks at at most 92 bytes + s->img_buffer = s->img_buffer_original; + s->img_buffer_end = s->img_buffer_original_end; +} + +enum +{ + STBI_ORDER_RGB, + STBI_ORDER_BGR +}; + +typedef struct +{ + int bits_per_channel; + int num_channels; + int channel_order; +} stbi__result_info; + +#ifndef STBI_NO_JPEG +static int stbi__jpeg_test(stbi__context *s); +static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PNG +static int stbi__png_test(stbi__context *s); +static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp); +static int stbi__png_is16(stbi__context *s); +#endif + +#ifndef STBI_NO_BMP +static int stbi__bmp_test(stbi__context *s); +static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_TGA +static int stbi__tga_test(stbi__context *s); +static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PSD +static int stbi__psd_test(stbi__context *s); +static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc); +static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp); +static int stbi__psd_is16(stbi__context *s); +#endif + +#ifndef STBI_NO_HDR +static int stbi__hdr_test(stbi__context *s); +static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PIC +static int stbi__pic_test(stbi__context *s); +static void *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_GIF +static int stbi__gif_test(stbi__context *s); +static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp); +static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PNM +static int stbi__pnm_test(stbi__context *s); +static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp); +static int stbi__pnm_is16(stbi__context *s); +#endif + +static +#ifdef STBI_THREAD_LOCAL +STBI_THREAD_LOCAL +#endif +const char *stbi__g_failure_reason; + +STBIDEF const char *stbi_failure_reason(void) +{ + return stbi__g_failure_reason; +} + +#ifndef STBI_NO_FAILURE_STRINGS +static int stbi__err(const char *str) +{ + stbi__g_failure_reason = str; + return 0; +} +#endif + +static void *stbi__malloc(size_t size) +{ + return STBI_MALLOC(size); +} + +// stb_image uses ints pervasively, including for offset calculations. +// therefore the largest decoded image size we can support with the +// current code, even on 64-bit targets, is INT_MAX. this is not a +// significant limitation for the intended use case. +// +// we do, however, need to make sure our size calculations don't +// overflow. hence a few helper functions for size calculations that +// multiply integers together, making sure that they're non-negative +// and no overflow occurs. + +// return 1 if the sum is valid, 0 on overflow. +// negative terms are considered invalid. +static int stbi__addsizes_valid(int a, int b) +{ + if (b < 0) return 0; + // now 0 <= b <= INT_MAX, hence also + // 0 <= INT_MAX - b <= INTMAX. + // And "a + b <= INT_MAX" (which might overflow) is the + // same as a <= INT_MAX - b (no overflow) + return a <= INT_MAX - b; +} + +// returns 1 if the product is valid, 0 on overflow. +// negative factors are considered invalid. +static int stbi__mul2sizes_valid(int a, int b) +{ + if (a < 0 || b < 0) return 0; + if (b == 0) return 1; // mul-by-0 is always safe + // portable way to check for no overflows in a*b + return a <= INT_MAX/b; +} + +#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) +// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow +static int stbi__mad2sizes_valid(int a, int b, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a*b, add); +} +#endif + +// returns 1 if "a*b*c + add" has no negative terms/factors and doesn't overflow +static int stbi__mad3sizes_valid(int a, int b, int c, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && + stbi__addsizes_valid(a*b*c, add); +} + +// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) +static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && + stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add); +} +#endif + +#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) +// mallocs with size overflow checking +static void *stbi__malloc_mad2(int a, int b, int add) +{ + if (!stbi__mad2sizes_valid(a, b, add)) return NULL; + return stbi__malloc(a*b + add); +} +#endif + +static void *stbi__malloc_mad3(int a, int b, int c, int add) +{ + if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL; + return stbi__malloc(a*b*c + add); +} + +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) +static void *stbi__malloc_mad4(int a, int b, int c, int d, int add) +{ + if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL; + return stbi__malloc(a*b*c*d + add); +} +#endif + +// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow. +static int stbi__addints_valid(int a, int b) +{ + if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow + if (a < 0 && b < 0) return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0. + return a <= INT_MAX - b; +} + +// returns 1 if the product of two ints fits in a signed short, 0 on overflow. +static int stbi__mul2shorts_valid(int a, int b) +{ + if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow + if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid + if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN + return a >= SHRT_MIN / b; +} + +// stbi__err - error +// stbi__errpf - error returning pointer to float +// stbi__errpuc - error returning pointer to unsigned char + +#ifdef STBI_NO_FAILURE_STRINGS +#define stbi__err(x,y) 0 +#elif defined(STBI_FAILURE_USERMSG) +#define stbi__err(x,y) stbi__err(y) +#else +#define stbi__err(x,y) stbi__err(x) +#endif + +#define stbi__errpf(x,y) ((float *)(size_t) (stbi__err(x,y)?NULL:NULL)) +#define stbi__errpuc(x,y) ((unsigned char *)(size_t) (stbi__err(x,y)?NULL:NULL)) + +STBIDEF void stbi_image_free(void *retval_from_stbi_load) +{ + STBI_FREE(retval_from_stbi_load); +} + +#ifndef STBI_NO_LINEAR +static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp); +#endif + +#ifndef STBI_NO_HDR +static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp); +#endif + +static int stbi__vertically_flip_on_load_global = 0; + +STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip) +{ + stbi__vertically_flip_on_load_global = flag_true_if_should_flip; +} + +#ifndef STBI_THREAD_LOCAL +#define stbi__vertically_flip_on_load stbi__vertically_flip_on_load_global +#else +static STBI_THREAD_LOCAL int stbi__vertically_flip_on_load_local, stbi__vertically_flip_on_load_set; + +STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip) +{ + stbi__vertically_flip_on_load_local = flag_true_if_should_flip; + stbi__vertically_flip_on_load_set = 1; +} + +#define stbi__vertically_flip_on_load (stbi__vertically_flip_on_load_set \ +? stbi__vertically_flip_on_load_local \ +: stbi__vertically_flip_on_load_global) +#endif // STBI_THREAD_LOCAL + +static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) +{ + memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields + ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed + ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order + ri->num_channels = 0; + + // test the formats with a very explicit header first (at least a FOURCC + // or distinctive magic number first) +#ifndef STBI_NO_PNG + if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp, ri); +#endif +#ifndef STBI_NO_BMP + if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp, ri); +#endif +#ifndef STBI_NO_GIF + if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp, ri); +#endif +#ifndef STBI_NO_PSD + if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp, ri, bpc); +#else + STBI_NOTUSED(bpc); +#endif +#ifndef STBI_NO_PIC + if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp, ri); +#endif + + // then the formats that can end up attempting to load with just 1 or 2 + // bytes matching expectations; these are prone to false positives, so + // try them later +#ifndef STBI_NO_JPEG + if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri); +#endif +#ifndef STBI_NO_PNM + if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp, ri); +#endif + +#ifndef STBI_NO_HDR + if (stbi__hdr_test(s)) { + float *hdr = stbi__hdr_load(s, x,y,comp,req_comp, ri); + return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); + } +#endif + +#ifndef STBI_NO_TGA + // test tga last because it's a crappy test! + if (stbi__tga_test(s)) + return stbi__tga_load(s,x,y,comp,req_comp, ri); +#endif + + return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt"); +} + +static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels) +{ + int i; + int img_len = w * h * channels; + stbi_uc *reduced; + + reduced = (stbi_uc *) stbi__malloc(img_len); + if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); + + for (i = 0; i < img_len; ++i) + reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling + + STBI_FREE(orig); + return reduced; +} + +static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels) +{ + int i; + int img_len = w * h * channels; + stbi__uint16 *enlarged; + + enlarged = (stbi__uint16 *) stbi__malloc(img_len*2); + if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); + + for (i = 0; i < img_len; ++i) + enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff + + STBI_FREE(orig); + return enlarged; +} + +static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel) +{ + int row; + size_t bytes_per_row = (size_t)w * bytes_per_pixel; + stbi_uc temp[2048]; + stbi_uc *bytes = (stbi_uc *)image; + + for (row = 0; row < (h>>1); row++) { + stbi_uc *row0 = bytes + row*bytes_per_row; + stbi_uc *row1 = bytes + (h - row - 1)*bytes_per_row; + // swap row0 with row1 + size_t bytes_left = bytes_per_row; + while (bytes_left) { + size_t bytes_copy = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp); + memcpy(temp, row0, bytes_copy); + memcpy(row0, row1, bytes_copy); + memcpy(row1, temp, bytes_copy); + row0 += bytes_copy; + row1 += bytes_copy; + bytes_left -= bytes_copy; + } + } +} + +#ifndef STBI_NO_GIF +static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel) +{ + int slice; + int slice_size = w * h * bytes_per_pixel; + + stbi_uc *bytes = (stbi_uc *)image; + for (slice = 0; slice < z; ++slice) { + stbi__vertical_flip(bytes, w, h, bytes_per_pixel); + bytes += slice_size; + } +} +#endif + +static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + stbi__result_info ri; + void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8); + + if (result == NULL) + return NULL; + + // it is the responsibility of the loaders to make sure we get either 8 or 16 bit. + STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); + + if (ri.bits_per_channel != 8) { + result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp); + ri.bits_per_channel = 8; + } + + // @TODO: move stbi__convert_format to here + + if (stbi__vertically_flip_on_load) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi_uc)); + } + + return (unsigned char *) result; +} + +static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + stbi__result_info ri; + void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); + + if (result == NULL) + return NULL; + + // it is the responsibility of the loaders to make sure we get either 8 or 16 bit. + STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); + + if (ri.bits_per_channel != 16) { + result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp); + ri.bits_per_channel = 16; + } + + // @TODO: move stbi__convert_format16 to here + // @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision + + if (stbi__vertically_flip_on_load) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi__uint16)); + } + + return (stbi__uint16 *) result; +} + +#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR) +static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp) +{ + if (stbi__vertically_flip_on_load && result != NULL) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(float)); + } +} +#endif + +#ifndef STBI_NO_STDIO + +#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) +STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide); +STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default); +#endif + +#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) +STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) +{ + return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL); +} +#endif + +static FILE *stbi__fopen(char const *filename, char const *mode) +{ + FILE *f; +#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) + wchar_t wMode[64]; + wchar_t wFilename[1024]; + if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename))) + return 0; + + if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode))) + return 0; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + if (0 != _wfopen_s(&f, wFilename, wMode)) + f = 0; +#else + f = _wfopen(wFilename, wMode); +#endif + +#elif defined(_MSC_VER) && _MSC_VER >= 1400 + if (0 != fopen_s(&f, filename, mode)) + f=0; +#else + f = fopen(filename, mode); +#endif + return f; +} + + +STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + unsigned char *result; + if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); + result = stbi_load_from_file(f,x,y,comp,req_comp); + fclose(f); + return result; +} + +STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + unsigned char *result; + stbi__context s; + stbi__start_file(&s,f); + result = stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); + if (result) { + // need to 'unget' all the characters in the IO buffer + fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); + } + return result; +} + +STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + stbi__uint16 *result; + stbi__context s; + stbi__start_file(&s,f); + result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp); + if (result) { + // need to 'unget' all the characters in the IO buffer + fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); + } + return result; +} + +STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + stbi__uint16 *result; + if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file"); + result = stbi_load_from_file_16(f,x,y,comp,req_comp); + fclose(f); + return result; +} + + +#endif //!STBI_NO_STDIO + +STBIDEF stbi_us *stbi_load_16_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); +} + +STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user); + return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); +} + +STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); +} + +STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); +} + +#ifndef STBI_NO_GIF +STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp) +{ + unsigned char *result; + stbi__context s; + stbi__start_mem(&s,buffer,len); + + result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); + if (stbi__vertically_flip_on_load) { + stbi__vertical_flip_slices( result, *x, *y, *z, *comp ); + } + + return result; +} +#endif + +#ifndef STBI_NO_LINEAR +static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + unsigned char *data; +#ifndef STBI_NO_HDR + if (stbi__hdr_test(s)) { + stbi__result_info ri; + float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp, &ri); + if (hdr_data) + stbi__float_postprocess(hdr_data,x,y,comp,req_comp); + return hdr_data; + } +#endif + data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp); + if (data) + return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp); + return stbi__errpf("unknown image type", "Image not of any known type, or corrupt"); +} + +STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} + +STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} + +#ifndef STBI_NO_STDIO +STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + float *result; + FILE *f = stbi__fopen(filename, "rb"); + if (!f) return stbi__errpf("can't fopen", "Unable to open file"); + result = stbi_loadf_from_file(f,x,y,comp,req_comp); + fclose(f); + return result; +} + +STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_file(&s,f); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} +#endif // !STBI_NO_STDIO + +#endif // !STBI_NO_LINEAR + +// these is-hdr-or-not is defined independent of whether STBI_NO_LINEAR is +// defined, for API simplicity; if STBI_NO_LINEAR is defined, it always +// reports false! + +STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len) +{ +#ifndef STBI_NO_HDR + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__hdr_test(&s); +#else + STBI_NOTUSED(buffer); + STBI_NOTUSED(len); + return 0; +#endif +} + +#ifndef STBI_NO_STDIO +STBIDEF int stbi_is_hdr (char const *filename) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result=0; + if (f) { + result = stbi_is_hdr_from_file(f); + fclose(f); + } + return result; +} + +STBIDEF int stbi_is_hdr_from_file(FILE *f) +{ +#ifndef STBI_NO_HDR + long pos = ftell(f); + int res; + stbi__context s; + stbi__start_file(&s,f); + res = stbi__hdr_test(&s); + fseek(f, pos, SEEK_SET); + return res; +#else + STBI_NOTUSED(f); + return 0; +#endif +} +#endif // !STBI_NO_STDIO + +STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user) +{ +#ifndef STBI_NO_HDR + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__hdr_test(&s); +#else + STBI_NOTUSED(clbk); + STBI_NOTUSED(user); + return 0; +#endif +} + +#ifndef STBI_NO_LINEAR +static float stbi__l2h_gamma=2.2f, stbi__l2h_scale=1.0f; + +STBIDEF void stbi_ldr_to_hdr_gamma(float gamma) { stbi__l2h_gamma = gamma; } +STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; } +#endif + +static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f; + +STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1/gamma; } +STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale; } + + +////////////////////////////////////////////////////////////////////////////// +// +// Common code used by all image loaders +// + +enum +{ + STBI__SCAN_load=0, + STBI__SCAN_type, + STBI__SCAN_header +}; + +static void stbi__refill_buffer(stbi__context *s) +{ + int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen); + s->callback_already_read += (int) (s->img_buffer - s->img_buffer_original); + if (n == 0) { + // at end of file, treat same as if from memory, but need to handle case + // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file + s->read_from_callbacks = 0; + s->img_buffer = s->buffer_start; + s->img_buffer_end = s->buffer_start+1; + *s->img_buffer = 0; + } else { + s->img_buffer = s->buffer_start; + s->img_buffer_end = s->buffer_start + n; + } +} + +stbi_inline static stbi_uc stbi__get8(stbi__context *s) +{ + if (s->img_buffer < s->img_buffer_end) + return *s->img_buffer++; + if (s->read_from_callbacks) { + stbi__refill_buffer(s); + return *s->img_buffer++; + } + return 0; +} + +#if defined(STBI_NO_JPEG) && defined(STBI_NO_HDR) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) +// nothing +#else +stbi_inline static int stbi__at_eof(stbi__context *s) +{ + if (s->io.read) { + if (!(s->io.eof)(s->io_user_data)) return 0; + // if feof() is true, check if buffer = end + // special case: we've only got the special 0 character at the end + if (s->read_from_callbacks == 0) return 1; + } + + return s->img_buffer >= s->img_buffer_end; +} +#endif + +#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) +// nothing +#else +static void stbi__skip(stbi__context *s, int n) +{ + if (n == 0) return; // already there! + if (n < 0) { + s->img_buffer = s->img_buffer_end; + return; + } + if (s->io.read) { + int blen = (int) (s->img_buffer_end - s->img_buffer); + if (blen < n) { + s->img_buffer = s->img_buffer_end; + (s->io.skip)(s->io_user_data, n - blen); + return; + } + } + s->img_buffer += n; +} +#endif + +#if defined(STBI_NO_PNG) && defined(STBI_NO_TGA) && defined(STBI_NO_HDR) && defined(STBI_NO_PNM) +// nothing +#else +static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n) +{ + if (s->io.read) { + int blen = (int) (s->img_buffer_end - s->img_buffer); + if (blen < n) { + int res, count; + + memcpy(buffer, s->img_buffer, blen); + + count = (s->io.read)(s->io_user_data, (char*) buffer + blen, n - blen); + res = (count == (n-blen)); + s->img_buffer = s->img_buffer_end; + return res; + } + } + + if (s->img_buffer+n <= s->img_buffer_end) { + memcpy(buffer, s->img_buffer, n); + s->img_buffer += n; + return 1; + } else + return 0; +} +#endif + +#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC) +// nothing +#else +static int stbi__get16be(stbi__context *s) +{ + int z = stbi__get8(s); + return (z << 8) + stbi__get8(s); +} +#endif + +#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC) +// nothing +#else +static stbi__uint32 stbi__get32be(stbi__context *s) +{ + stbi__uint32 z = stbi__get16be(s); + return (z << 16) + stbi__get16be(s); +} +#endif + +#if defined(STBI_NO_BMP) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) +// nothing +#else +static int stbi__get16le(stbi__context *s) +{ + int z = stbi__get8(s); + return z + (stbi__get8(s) << 8); +} +#endif + +#ifndef STBI_NO_BMP +static stbi__uint32 stbi__get32le(stbi__context *s) +{ + stbi__uint32 z = stbi__get16le(s); + z += (stbi__uint32)stbi__get16le(s) << 16; + return z; +} +#endif + +#define STBI__BYTECAST(x) ((stbi_uc) ((x) & 255)) // truncate int to byte without warnings + +#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) +// nothing +#else +////////////////////////////////////////////////////////////////////////////// +// +// generic converter from built-in img_n to req_comp +// individual types do this automatically as much as possible (e.g. jpeg +// does all cases internally since it needs to colorspace convert anyway, +// and it never has alpha, so very few cases ). png can automatically +// interleave an alpha=255 channel, but falls back to this for other cases +// +// assume data buffer is malloced, so malloc a new one and free that one +// only failure mode is malloc failing + +static stbi_uc stbi__compute_y(int r, int g, int b) +{ + return (stbi_uc) (((r*77) + (g*150) + (29*b)) >> 8); +} +#endif + +#if defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM) +// nothing +#else +static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y) +{ + int i,j; + unsigned char *good; + + if (req_comp == img_n) return data; + STBI_ASSERT(req_comp >= 1 && req_comp <= 4); + + good = (unsigned char *) stbi__malloc_mad3(req_comp, x, y, 0); + if (good == NULL) { + STBI_FREE(data); + return stbi__errpuc("outofmem", "Out of memory"); + } + + for (j=0; j < (int) y; ++j) { + unsigned char *src = data + j * x * img_n ; + unsigned char *dest = good + j * x * req_comp; + +#define STBI__COMBO(a,b) ((a)*8+(b)) +#define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) + // convert source image with img_n components to one with req_comp components; + // avoid switch per pixel, so use switch per scanline and massive macros + switch (STBI__COMBO(img_n, req_comp)) { + STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=255; } break; + STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=255; } break; + STBI__CASE(2,1) { dest[0]=src[0]; } break; + STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break; + STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=255; } break; + STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; + STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = 255; } break; + STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; + STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = src[3]; } break; + STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break; + default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return stbi__errpuc("unsupported", "Unsupported format conversion"); + } +#undef STBI__CASE + } + + STBI_FREE(data); + return good; +} +#endif + +#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) +// nothing +#else +static stbi__uint16 stbi__compute_y_16(int r, int g, int b) +{ + return (stbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8); +} +#endif + +#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) +// nothing +#else +static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y) +{ + int i,j; + stbi__uint16 *good; + + if (req_comp == img_n) return data; + STBI_ASSERT(req_comp >= 1 && req_comp <= 4); + + good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2); + if (good == NULL) { + STBI_FREE(data); + return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); + } + + for (j=0; j < (int) y; ++j) { + stbi__uint16 *src = data + j * x * img_n ; + stbi__uint16 *dest = good + j * x * req_comp; + +#define STBI__COMBO(a,b) ((a)*8+(b)) +#define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) + // convert source image with img_n components to one with req_comp components; + // avoid switch per pixel, so use switch per scanline and massive macros + switch (STBI__COMBO(img_n, req_comp)) { + STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff; } break; + STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff; } break; + STBI__CASE(2,1) { dest[0]=src[0]; } break; + STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break; + STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff; } break; + STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; + STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break; + STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; + STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break; + STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break; + default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return (stbi__uint16*) stbi__errpuc("unsupported", "Unsupported format conversion"); + } +#undef STBI__CASE + } + + STBI_FREE(data); + return good; +} +#endif + +#ifndef STBI_NO_LINEAR +static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp) +{ + int i,k,n; + float *output; + if (!data) return NULL; + output = (float *) stbi__malloc_mad4(x, y, comp, sizeof(float), 0); + if (output == NULL) { STBI_FREE(data); return stbi__errpf("outofmem", "Out of memory"); } + // compute number of non-alpha components + if (comp & 1) n = comp; else n = comp-1; + for (i=0; i < x*y; ++i) { + for (k=0; k < n; ++k) { + output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale); + } + } + if (n < comp) { + for (i=0; i < x*y; ++i) { + output[i*comp + n] = data[i*comp + n]/255.0f; + } + } + STBI_FREE(data); + return output; +} +#endif + +#ifndef STBI_NO_HDR +#define stbi__float2int(x) ((int) (x)) +static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp) +{ + int i,k,n; + stbi_uc *output; + if (!data) return NULL; + output = (stbi_uc *) stbi__malloc_mad3(x, y, comp, 0); + if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } + // compute number of non-alpha components + if (comp & 1) n = comp; else n = comp-1; + for (i=0; i < x*y; ++i) { + for (k=0; k < n; ++k) { + float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f; + if (z < 0) z = 0; + if (z > 255) z = 255; + output[i*comp + k] = (stbi_uc) stbi__float2int(z); + } + if (k < comp) { + float z = data[i*comp+k] * 255 + 0.5f; + if (z < 0) z = 0; + if (z > 255) z = 255; + output[i*comp + k] = (stbi_uc) stbi__float2int(z); + } + } + STBI_FREE(data); + return output; +} +#endif + +////////////////////////////////////////////////////////////////////////////// +// +// "baseline" JPEG/JFIF decoder +// +// simple implementation +// - doesn't support delayed output of y-dimension +// - simple interface (only one output format: 8-bit interleaved RGB) +// - doesn't try to recover corrupt jpegs +// - doesn't allow partial loading, loading multiple at once +// - still fast on x86 (copying globals into locals doesn't help x86) +// - allocates lots of intermediate memory (full size of all components) +// - non-interleaved case requires this anyway +// - allows good upsampling (see next) +// high-quality +// - upsampled channels are bilinearly interpolated, even across blocks +// - quality integer IDCT derived from IJG's 'slow' +// performance +// - fast huffman; reasonable integer IDCT +// - some SIMD kernels for common paths on targets with SSE2/NEON +// - uses a lot of intermediate memory, could cache poorly + +#ifndef STBI_NO_JPEG + +// huffman decoding acceleration +#define FAST_BITS 9 // larger handles more cases; smaller stomps less cache + +typedef struct +{ + stbi_uc fast[1 << FAST_BITS]; + // weirdly, repacking this into AoS is a 10% speed loss, instead of a win + stbi__uint16 code[256]; + stbi_uc values[256]; + stbi_uc size[257]; + unsigned int maxcode[18]; + int delta[17]; // old 'firstsymbol' - old 'firstcode' +} stbi__huffman; + +typedef struct +{ + stbi__context *s; + stbi__huffman huff_dc[4]; + stbi__huffman huff_ac[4]; + stbi__uint16 dequant[4][64]; + stbi__int16 fast_ac[4][1 << FAST_BITS]; + + // sizes for components, interleaved MCUs + int img_h_max, img_v_max; + int img_mcu_x, img_mcu_y; + int img_mcu_w, img_mcu_h; + + // definition of jpeg image component + struct + { + int id; + int h,v; + int tq; + int hd,ha; + int dc_pred; + + int x,y,w2,h2; + stbi_uc *data; + void *raw_data, *raw_coeff; + stbi_uc *linebuf; + short *coeff; // progressive only + int coeff_w, coeff_h; // number of 8x8 coefficient blocks + } img_comp[4]; + + stbi__uint32 code_buffer; // jpeg entropy-coded buffer + int code_bits; // number of valid bits + unsigned char marker; // marker seen while filling entropy buffer + int nomore; // flag if we saw a marker so must stop + + int progressive; + int spec_start; + int spec_end; + int succ_high; + int succ_low; + int eob_run; + int jfif; + int app14_color_transform; // Adobe APP14 tag + int rgb; + + int scan_n, order[4]; + int restart_interval, todo; + + // kernels + void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]); + void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step); + stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs); +} stbi__jpeg; + +static int stbi__build_huffman(stbi__huffman *h, int *count) +{ + int i,j,k=0; + unsigned int code; + // build size list for each symbol (from JPEG spec) + for (i=0; i < 16; ++i) { + for (j=0; j < count[i]; ++j) { + h->size[k++] = (stbi_uc) (i+1); + if(k >= 257) return stbi__err("bad size list","Corrupt JPEG"); + } + } + h->size[k] = 0; + + // compute actual symbols (from jpeg spec) + code = 0; + k = 0; + for(j=1; j <= 16; ++j) { + // compute delta to add to code to compute symbol id + h->delta[j] = k - code; + if (h->size[k] == j) { + while (h->size[k] == j) + h->code[k++] = (stbi__uint16) (code++); + if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG"); + } + // compute largest code + 1 for this size, preshifted as needed later + h->maxcode[j] = code << (16-j); + code <<= 1; + } + h->maxcode[j] = 0xffffffff; + + // build non-spec acceleration table; 255 is flag for not-accelerated + memset(h->fast, 255, 1 << FAST_BITS); + for (i=0; i < k; ++i) { + int s = h->size[i]; + if (s <= FAST_BITS) { + int c = h->code[i] << (FAST_BITS-s); + int m = 1 << (FAST_BITS-s); + for (j=0; j < m; ++j) { + h->fast[c+j] = (stbi_uc) i; + } + } + } + return 1; +} + +// build a table that decodes both magnitude and value of small ACs in +// one go. +static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h) +{ + int i; + for (i=0; i < (1 << FAST_BITS); ++i) { + stbi_uc fast = h->fast[i]; + fast_ac[i] = 0; + if (fast < 255) { + int rs = h->values[fast]; + int run = (rs >> 4) & 15; + int magbits = rs & 15; + int len = h->size[fast]; + + if (magbits && len + magbits <= FAST_BITS) { + // magnitude code followed by receive_extend code + int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits); + int m = 1 << (magbits - 1); + if (k < m) k += (~0U << magbits) + 1; + // if the result is small enough, we can fit it in fast_ac table + if (k >= -128 && k <= 127) + fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits)); + } + } + } +} + +static void stbi__grow_buffer_unsafe(stbi__jpeg *j) +{ + do { + unsigned int b = j->nomore ? 0 : stbi__get8(j->s); + if (b == 0xff) { + int c = stbi__get8(j->s); + while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes + if (c != 0) { + j->marker = (unsigned char) c; + j->nomore = 1; + return; + } + } + j->code_buffer |= b << (24 - j->code_bits); + j->code_bits += 8; + } while (j->code_bits <= 24); +} + +// (1 << n) - 1 +static const stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; + +// decode a jpeg huffman value from the bitstream +stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) +{ + unsigned int temp; + int c,k; + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + + // look at the top FAST_BITS and determine what symbol ID it is, + // if the code is <= FAST_BITS + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + k = h->fast[c]; + if (k < 255) { + int s = h->size[k]; + if (s > j->code_bits) + return -1; + j->code_buffer <<= s; + j->code_bits -= s; + return h->values[k]; + } + + // naive test is to shift the code_buffer down so k bits are + // valid, then test against maxcode. To speed this up, we've + // preshifted maxcode left so that it has (16-k) 0s at the + // end; in other words, regardless of the number of bits, it + // wants to be compared against something shifted to have 16; + // that way we don't need to shift inside the loop. + temp = j->code_buffer >> 16; + for (k=FAST_BITS+1 ; ; ++k) + if (temp < h->maxcode[k]) + break; + if (k == 17) { + // error! code not found + j->code_bits -= 16; + return -1; + } + + if (k > j->code_bits) + return -1; + + // convert the huffman code to the symbol id + c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; + if(c < 0 || c >= 256) // symbol id out of bounds! + return -1; + STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]); + + // convert the id to a symbol + j->code_bits -= k; + j->code_buffer <<= k; + return h->values[c]; +} + +// bias[n] = (-1<code_bits < n) stbi__grow_buffer_unsafe(j); + if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing + + sgn = j->code_buffer >> 31; // sign bit always in MSB; 0 if MSB clear (positive), 1 if MSB set (negative) + k = stbi_lrot(j->code_buffer, n); + j->code_buffer = k & ~stbi__bmask[n]; + k &= stbi__bmask[n]; + j->code_bits -= n; + return k + (stbi__jbias[n] & (sgn - 1)); +} + +// get some unsigned bits +stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n) +{ + unsigned int k; + if (j->code_bits < n) stbi__grow_buffer_unsafe(j); + if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing + k = stbi_lrot(j->code_buffer, n); + j->code_buffer = k & ~stbi__bmask[n]; + k &= stbi__bmask[n]; + j->code_bits -= n; + return k; +} + +stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j) +{ + unsigned int k; + if (j->code_bits < 1) stbi__grow_buffer_unsafe(j); + if (j->code_bits < 1) return 0; // ran out of bits from stream, return 0s intead of continuing + k = j->code_buffer; + j->code_buffer <<= 1; + --j->code_bits; + return k & 0x80000000; +} + +// given a value that's at position X in the zigzag stream, +// where does it appear in the 8x8 matrix coded as row-major? +static const stbi_uc stbi__jpeg_dezigzag[64+15] = +{ + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63, + // let corrupt input sample past end + 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63 +}; + +// decode one 64-entry block-- +static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant) +{ + int diff,dc,k; + int t; + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + t = stbi__jpeg_huff_decode(j, hdc); + if (t < 0 || t > 15) return stbi__err("bad huffman code","Corrupt JPEG"); + + // 0 all the ac values now so we can do it 32-bits at a time + memset(data,0,64*sizeof(data[0])); + + diff = t ? stbi__extend_receive(j, t) : 0; + if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta","Corrupt JPEG"); + dc = j->img_comp[b].dc_pred + diff; + j->img_comp[b].dc_pred = dc; + if (!stbi__mul2shorts_valid(dc, dequant[0])) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + data[0] = (short) (dc * dequant[0]); + + // decode AC components, see JPEG spec + k = 1; + do { + unsigned int zig; + int c,r,s; + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + r = fac[c]; + if (r) { // fast-AC path + k += (r >> 4) & 15; // run + s = r & 15; // combined length + if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); + j->code_buffer <<= s; + j->code_bits -= s; + // decode into unzigzag'd location + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) ((r >> 8) * dequant[zig]); + } else { + int rs = stbi__jpeg_huff_decode(j, hac); + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (rs != 0xf0) break; // end block + k += 16; + } else { + k += r; + // decode into unzigzag'd location + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]); + } + } + } while (k < 64); + return 1; +} + +static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) +{ + int diff,dc; + int t; + if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + + if (j->succ_high == 0) { + // first scan for DC coefficient, must be first + memset(data,0,64*sizeof(data[0])); // 0 all the ac values now + t = stbi__jpeg_huff_decode(j, hdc); + if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + diff = t ? stbi__extend_receive(j, t) : 0; + + if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta", "Corrupt JPEG"); + dc = j->img_comp[b].dc_pred + diff; + j->img_comp[b].dc_pred = dc; + if (!stbi__mul2shorts_valid(dc, 1 << j->succ_low)) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + data[0] = (short) (dc * (1 << j->succ_low)); + } else { + // refinement scan for DC coefficient + if (stbi__jpeg_get_bit(j)) + data[0] += (short) (1 << j->succ_low); + } + return 1; +} + +// @OPTIMIZE: store non-zigzagged during the decode passes, +// and only de-zigzag when dequantizing +static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac) +{ + int k; + if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + + if (j->succ_high == 0) { + int shift = j->succ_low; + + if (j->eob_run) { + --j->eob_run; + return 1; + } + + k = j->spec_start; + do { + unsigned int zig; + int c,r,s; + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + r = fac[c]; + if (r) { // fast-AC path + k += (r >> 4) & 15; // run + s = r & 15; // combined length + if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); + j->code_buffer <<= s; + j->code_bits -= s; + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) ((r >> 8) * (1 << shift)); + } else { + int rs = stbi__jpeg_huff_decode(j, hac); + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (r < 15) { + j->eob_run = (1 << r); + if (r) + j->eob_run += stbi__jpeg_get_bits(j, r); + --j->eob_run; + break; + } + k += 16; + } else { + k += r; + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) (stbi__extend_receive(j,s) * (1 << shift)); + } + } + } while (k <= j->spec_end); + } else { + // refinement scan for these AC coefficients + + short bit = (short) (1 << j->succ_low); + + if (j->eob_run) { + --j->eob_run; + for (k = j->spec_start; k <= j->spec_end; ++k) { + short *p = &data[stbi__jpeg_dezigzag[k]]; + if (*p != 0) + if (stbi__jpeg_get_bit(j)) + if ((*p & bit)==0) { + if (*p > 0) + *p += bit; + else + *p -= bit; + } + } + } else { + k = j->spec_start; + do { + int r,s; + int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (r < 15) { + j->eob_run = (1 << r) - 1; + if (r) + j->eob_run += stbi__jpeg_get_bits(j, r); + r = 64; // force end of block + } else { + // r=15 s=0 should write 16 0s, so we just do + // a run of 15 0s and then write s (which is 0), + // so we don't have to do anything special here + } + } else { + if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG"); + // sign bit + if (stbi__jpeg_get_bit(j)) + s = bit; + else + s = -bit; + } + + // advance by r + while (k <= j->spec_end) { + short *p = &data[stbi__jpeg_dezigzag[k++]]; + if (*p != 0) { + if (stbi__jpeg_get_bit(j)) + if ((*p & bit)==0) { + if (*p > 0) + *p += bit; + else + *p -= bit; + } + } else { + if (r == 0) { + *p = (short) s; + break; + } + --r; + } + } + } while (k <= j->spec_end); + } + } + return 1; +} + +// take a -128..127 value and stbi__clamp it and convert to 0..255 +stbi_inline static stbi_uc stbi__clamp(int x) +{ + // trick to use a single test to catch both cases + if ((unsigned int) x > 255) { + if (x < 0) return 0; + if (x > 255) return 255; + } + return (stbi_uc) x; +} + +#define stbi__f2f(x) ((int) (((x) * 4096 + 0.5))) +#define stbi__fsh(x) ((x) * 4096) + +// derived from jidctint -- DCT_ISLOW +#define STBI__IDCT_1D(s0,s1,s2,s3,s4,s5,s6,s7) \ +int t0,t1,t2,t3,p1,p2,p3,p4,p5,x0,x1,x2,x3; \ +p2 = s2; \ +p3 = s6; \ +p1 = (p2+p3) * stbi__f2f(0.5411961f); \ +t2 = p1 + p3*stbi__f2f(-1.847759065f); \ +t3 = p1 + p2*stbi__f2f( 0.765366865f); \ +p2 = s0; \ +p3 = s4; \ +t0 = stbi__fsh(p2+p3); \ +t1 = stbi__fsh(p2-p3); \ +x0 = t0+t3; \ +x3 = t0-t3; \ +x1 = t1+t2; \ +x2 = t1-t2; \ +t0 = s7; \ +t1 = s5; \ +t2 = s3; \ +t3 = s1; \ +p3 = t0+t2; \ +p4 = t1+t3; \ +p1 = t0+t3; \ +p2 = t1+t2; \ +p5 = (p3+p4)*stbi__f2f( 1.175875602f); \ +t0 = t0*stbi__f2f( 0.298631336f); \ +t1 = t1*stbi__f2f( 2.053119869f); \ +t2 = t2*stbi__f2f( 3.072711026f); \ +t3 = t3*stbi__f2f( 1.501321110f); \ +p1 = p5 + p1*stbi__f2f(-0.899976223f); \ +p2 = p5 + p2*stbi__f2f(-2.562915447f); \ +p3 = p3*stbi__f2f(-1.961570560f); \ +p4 = p4*stbi__f2f(-0.390180644f); \ +t3 += p1+p4; \ +t2 += p2+p3; \ +t1 += p2+p4; \ +t0 += p1+p3; + +static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64]) +{ + int i,val[64],*v=val; + stbi_uc *o; + short *d = data; + + // columns + for (i=0; i < 8; ++i,++d, ++v) { + // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing + if (d[ 8]==0 && d[16]==0 && d[24]==0 && d[32]==0 + && d[40]==0 && d[48]==0 && d[56]==0) { + // no shortcut 0 seconds + // (1|2|3|4|5|6|7)==0 0 seconds + // all separate -0.047 seconds + // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds + int dcterm = d[0]*4; + v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm; + } else { + STBI__IDCT_1D(d[ 0],d[ 8],d[16],d[24],d[32],d[40],d[48],d[56]) + // constants scaled things up by 1<<12; let's bring them back + // down, but keep 2 extra bits of precision + x0 += 512; x1 += 512; x2 += 512; x3 += 512; + v[ 0] = (x0+t3) >> 10; + v[56] = (x0-t3) >> 10; + v[ 8] = (x1+t2) >> 10; + v[48] = (x1-t2) >> 10; + v[16] = (x2+t1) >> 10; + v[40] = (x2-t1) >> 10; + v[24] = (x3+t0) >> 10; + v[32] = (x3-t0) >> 10; + } + } + + for (i=0, v=val, o=out; i < 8; ++i,v+=8,o+=out_stride) { + // no fast case since the first 1D IDCT spread components out + STBI__IDCT_1D(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]) + // constants scaled things up by 1<<12, plus we had 1<<2 from first + // loop, plus horizontal and vertical each scale by sqrt(8) so together + // we've got an extra 1<<3, so 1<<17 total we need to remove. + // so we want to round that, which means adding 0.5 * 1<<17, + // aka 65536. Also, we'll end up with -128 to 127 that we want + // to encode as 0..255 by adding 128, so we'll add that before the shift + x0 += 65536 + (128<<17); + x1 += 65536 + (128<<17); + x2 += 65536 + (128<<17); + x3 += 65536 + (128<<17); + // tried computing the shifts into temps, or'ing the temps to see + // if any were out of range, but that was slower + o[0] = stbi__clamp((x0+t3) >> 17); + o[7] = stbi__clamp((x0-t3) >> 17); + o[1] = stbi__clamp((x1+t2) >> 17); + o[6] = stbi__clamp((x1-t2) >> 17); + o[2] = stbi__clamp((x2+t1) >> 17); + o[5] = stbi__clamp((x2-t1) >> 17); + o[3] = stbi__clamp((x3+t0) >> 17); + o[4] = stbi__clamp((x3-t0) >> 17); + } +} + +#ifdef STBI_SSE2 +// sse2 integer IDCT. not the fastest possible implementation but it +// produces bit-identical results to the generic C version so it's +// fully "transparent". +static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) +{ + // This is constructed to match our regular (generic) integer IDCT exactly. + __m128i row0, row1, row2, row3, row4, row5, row6, row7; + __m128i tmp; + + // dot product constant: even elems=x, odd elems=y +#define dct_const(x,y) _mm_setr_epi16((x),(y),(x),(y),(x),(y),(x),(y)) + + // out(0) = c0[even]*x + c0[odd]*y (c0, x, y 16-bit, out 32-bit) + // out(1) = c1[even]*x + c1[odd]*y +#define dct_rot(out0,out1, x,y,c0,c1) \ +__m128i c0##lo = _mm_unpacklo_epi16((x),(y)); \ +__m128i c0##hi = _mm_unpackhi_epi16((x),(y)); \ +__m128i out0##_l = _mm_madd_epi16(c0##lo, c0); \ +__m128i out0##_h = _mm_madd_epi16(c0##hi, c0); \ +__m128i out1##_l = _mm_madd_epi16(c0##lo, c1); \ +__m128i out1##_h = _mm_madd_epi16(c0##hi, c1) + + // out = in << 12 (in 16-bit, out 32-bit) +#define dct_widen(out, in) \ +__m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \ +__m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4) + + // wide add +#define dct_wadd(out, a, b) \ +__m128i out##_l = _mm_add_epi32(a##_l, b##_l); \ +__m128i out##_h = _mm_add_epi32(a##_h, b##_h) + + // wide sub +#define dct_wsub(out, a, b) \ +__m128i out##_l = _mm_sub_epi32(a##_l, b##_l); \ +__m128i out##_h = _mm_sub_epi32(a##_h, b##_h) + + // butterfly a/b, add bias, then shift by "s" and pack +#define dct_bfly32o(out0, out1, a,b,bias,s) \ +{ \ +__m128i abiased_l = _mm_add_epi32(a##_l, bias); \ +__m128i abiased_h = _mm_add_epi32(a##_h, bias); \ +dct_wadd(sum, abiased, b); \ +dct_wsub(dif, abiased, b); \ +out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), _mm_srai_epi32(sum_h, s)); \ +out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \ +} + + // 8-bit interleave step (for transposes) +#define dct_interleave8(a, b) \ +tmp = a; \ +a = _mm_unpacklo_epi8(a, b); \ +b = _mm_unpackhi_epi8(tmp, b) + + // 16-bit interleave step (for transposes) +#define dct_interleave16(a, b) \ +tmp = a; \ +a = _mm_unpacklo_epi16(a, b); \ +b = _mm_unpackhi_epi16(tmp, b) + +#define dct_pass(bias,shift) \ +{ \ +/* even part */ \ +dct_rot(t2e,t3e, row2,row6, rot0_0,rot0_1); \ +__m128i sum04 = _mm_add_epi16(row0, row4); \ +__m128i dif04 = _mm_sub_epi16(row0, row4); \ +dct_widen(t0e, sum04); \ +dct_widen(t1e, dif04); \ +dct_wadd(x0, t0e, t3e); \ +dct_wsub(x3, t0e, t3e); \ +dct_wadd(x1, t1e, t2e); \ +dct_wsub(x2, t1e, t2e); \ +/* odd part */ \ +dct_rot(y0o,y2o, row7,row3, rot2_0,rot2_1); \ +dct_rot(y1o,y3o, row5,row1, rot3_0,rot3_1); \ +__m128i sum17 = _mm_add_epi16(row1, row7); \ +__m128i sum35 = _mm_add_epi16(row3, row5); \ +dct_rot(y4o,y5o, sum17,sum35, rot1_0,rot1_1); \ +dct_wadd(x4, y0o, y4o); \ +dct_wadd(x5, y1o, y5o); \ +dct_wadd(x6, y2o, y5o); \ +dct_wadd(x7, y3o, y4o); \ +dct_bfly32o(row0,row7, x0,x7,bias,shift); \ +dct_bfly32o(row1,row6, x1,x6,bias,shift); \ +dct_bfly32o(row2,row5, x2,x5,bias,shift); \ +dct_bfly32o(row3,row4, x3,x4,bias,shift); \ +} + + __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); + __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f( 0.765366865f), stbi__f2f(0.5411961f)); + __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f)); + __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f)); + __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f( 0.298631336f), stbi__f2f(-1.961570560f)); + __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f( 3.072711026f)); + __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f( 2.053119869f), stbi__f2f(-0.390180644f)); + __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f( 1.501321110f)); + + // rounding biases in column/row passes, see stbi__idct_block for explanation. + __m128i bias_0 = _mm_set1_epi32(512); + __m128i bias_1 = _mm_set1_epi32(65536 + (128<<17)); + + // load + row0 = _mm_load_si128((const __m128i *) (data + 0*8)); + row1 = _mm_load_si128((const __m128i *) (data + 1*8)); + row2 = _mm_load_si128((const __m128i *) (data + 2*8)); + row3 = _mm_load_si128((const __m128i *) (data + 3*8)); + row4 = _mm_load_si128((const __m128i *) (data + 4*8)); + row5 = _mm_load_si128((const __m128i *) (data + 5*8)); + row6 = _mm_load_si128((const __m128i *) (data + 6*8)); + row7 = _mm_load_si128((const __m128i *) (data + 7*8)); + + // column pass + dct_pass(bias_0, 10); + + { + // 16bit 8x8 transpose pass 1 + dct_interleave16(row0, row4); + dct_interleave16(row1, row5); + dct_interleave16(row2, row6); + dct_interleave16(row3, row7); + + // transpose pass 2 + dct_interleave16(row0, row2); + dct_interleave16(row1, row3); + dct_interleave16(row4, row6); + dct_interleave16(row5, row7); + + // transpose pass 3 + dct_interleave16(row0, row1); + dct_interleave16(row2, row3); + dct_interleave16(row4, row5); + dct_interleave16(row6, row7); + } + + // row pass + dct_pass(bias_1, 17); + + { + // pack + __m128i p0 = _mm_packus_epi16(row0, row1); // a0a1a2a3...a7b0b1b2b3...b7 + __m128i p1 = _mm_packus_epi16(row2, row3); + __m128i p2 = _mm_packus_epi16(row4, row5); + __m128i p3 = _mm_packus_epi16(row6, row7); + + // 8bit 8x8 transpose pass 1 + dct_interleave8(p0, p2); // a0e0a1e1... + dct_interleave8(p1, p3); // c0g0c1g1... + + // transpose pass 2 + dct_interleave8(p0, p1); // a0c0e0g0... + dct_interleave8(p2, p3); // b0d0f0h0... + + // transpose pass 3 + dct_interleave8(p0, p2); // a0b0c0d0... + dct_interleave8(p1, p3); // a4b4c4d4... + + // store + _mm_storel_epi64((__m128i *) out, p0); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p0, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p2); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p2, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p1); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p1, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p3); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p3, 0x4e)); + } + +#undef dct_const +#undef dct_rot +#undef dct_widen +#undef dct_wadd +#undef dct_wsub +#undef dct_bfly32o +#undef dct_interleave8 +#undef dct_interleave16 +#undef dct_pass +} + +#endif // STBI_SSE2 + +#ifdef STBI_NEON + +// NEON integer IDCT. should produce bit-identical +// results to the generic C version. +static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) +{ + int16x8_t row0, row1, row2, row3, row4, row5, row6, row7; + + int16x4_t rot0_0 = vdup_n_s16(stbi__f2f(0.5411961f)); + int16x4_t rot0_1 = vdup_n_s16(stbi__f2f(-1.847759065f)); + int16x4_t rot0_2 = vdup_n_s16(stbi__f2f( 0.765366865f)); + int16x4_t rot1_0 = vdup_n_s16(stbi__f2f( 1.175875602f)); + int16x4_t rot1_1 = vdup_n_s16(stbi__f2f(-0.899976223f)); + int16x4_t rot1_2 = vdup_n_s16(stbi__f2f(-2.562915447f)); + int16x4_t rot2_0 = vdup_n_s16(stbi__f2f(-1.961570560f)); + int16x4_t rot2_1 = vdup_n_s16(stbi__f2f(-0.390180644f)); + int16x4_t rot3_0 = vdup_n_s16(stbi__f2f( 0.298631336f)); + int16x4_t rot3_1 = vdup_n_s16(stbi__f2f( 2.053119869f)); + int16x4_t rot3_2 = vdup_n_s16(stbi__f2f( 3.072711026f)); + int16x4_t rot3_3 = vdup_n_s16(stbi__f2f( 1.501321110f)); + +#define dct_long_mul(out, inq, coeff) \ +int32x4_t out##_l = vmull_s16(vget_low_s16(inq), coeff); \ +int32x4_t out##_h = vmull_s16(vget_high_s16(inq), coeff) + +#define dct_long_mac(out, acc, inq, coeff) \ +int32x4_t out##_l = vmlal_s16(acc##_l, vget_low_s16(inq), coeff); \ +int32x4_t out##_h = vmlal_s16(acc##_h, vget_high_s16(inq), coeff) + +#define dct_widen(out, inq) \ +int32x4_t out##_l = vshll_n_s16(vget_low_s16(inq), 12); \ +int32x4_t out##_h = vshll_n_s16(vget_high_s16(inq), 12) + + // wide add +#define dct_wadd(out, a, b) \ +int32x4_t out##_l = vaddq_s32(a##_l, b##_l); \ +int32x4_t out##_h = vaddq_s32(a##_h, b##_h) + + // wide sub +#define dct_wsub(out, a, b) \ +int32x4_t out##_l = vsubq_s32(a##_l, b##_l); \ +int32x4_t out##_h = vsubq_s32(a##_h, b##_h) + + // butterfly a/b, then shift using "shiftop" by "s" and pack +#define dct_bfly32o(out0,out1, a,b,shiftop,s) \ +{ \ +dct_wadd(sum, a, b); \ +dct_wsub(dif, a, b); \ +out0 = vcombine_s16(shiftop(sum_l, s), shiftop(sum_h, s)); \ +out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \ +} + +#define dct_pass(shiftop, shift) \ +{ \ +/* even part */ \ +int16x8_t sum26 = vaddq_s16(row2, row6); \ +dct_long_mul(p1e, sum26, rot0_0); \ +dct_long_mac(t2e, p1e, row6, rot0_1); \ +dct_long_mac(t3e, p1e, row2, rot0_2); \ +int16x8_t sum04 = vaddq_s16(row0, row4); \ +int16x8_t dif04 = vsubq_s16(row0, row4); \ +dct_widen(t0e, sum04); \ +dct_widen(t1e, dif04); \ +dct_wadd(x0, t0e, t3e); \ +dct_wsub(x3, t0e, t3e); \ +dct_wadd(x1, t1e, t2e); \ +dct_wsub(x2, t1e, t2e); \ +/* odd part */ \ +int16x8_t sum15 = vaddq_s16(row1, row5); \ +int16x8_t sum17 = vaddq_s16(row1, row7); \ +int16x8_t sum35 = vaddq_s16(row3, row5); \ +int16x8_t sum37 = vaddq_s16(row3, row7); \ +int16x8_t sumodd = vaddq_s16(sum17, sum35); \ +dct_long_mul(p5o, sumodd, rot1_0); \ +dct_long_mac(p1o, p5o, sum17, rot1_1); \ +dct_long_mac(p2o, p5o, sum35, rot1_2); \ +dct_long_mul(p3o, sum37, rot2_0); \ +dct_long_mul(p4o, sum15, rot2_1); \ +dct_wadd(sump13o, p1o, p3o); \ +dct_wadd(sump24o, p2o, p4o); \ +dct_wadd(sump23o, p2o, p3o); \ +dct_wadd(sump14o, p1o, p4o); \ +dct_long_mac(x4, sump13o, row7, rot3_0); \ +dct_long_mac(x5, sump24o, row5, rot3_1); \ +dct_long_mac(x6, sump23o, row3, rot3_2); \ +dct_long_mac(x7, sump14o, row1, rot3_3); \ +dct_bfly32o(row0,row7, x0,x7,shiftop,shift); \ +dct_bfly32o(row1,row6, x1,x6,shiftop,shift); \ +dct_bfly32o(row2,row5, x2,x5,shiftop,shift); \ +dct_bfly32o(row3,row4, x3,x4,shiftop,shift); \ +} + + // load + row0 = vld1q_s16(data + 0*8); + row1 = vld1q_s16(data + 1*8); + row2 = vld1q_s16(data + 2*8); + row3 = vld1q_s16(data + 3*8); + row4 = vld1q_s16(data + 4*8); + row5 = vld1q_s16(data + 5*8); + row6 = vld1q_s16(data + 6*8); + row7 = vld1q_s16(data + 7*8); + + // add DC bias + row0 = vaddq_s16(row0, vsetq_lane_s16(1024, vdupq_n_s16(0), 0)); + + // column pass + dct_pass(vrshrn_n_s32, 10); + + // 16bit 8x8 transpose + { + // these three map to a single VTRN.16, VTRN.32, and VSWP, respectively. + // whether compilers actually get this is another story, sadly. +#define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; } +#define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); } +#define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); } + + // pass 1 + dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6 + dct_trn16(row2, row3); + dct_trn16(row4, row5); + dct_trn16(row6, row7); + + // pass 2 + dct_trn32(row0, row2); // a0b0c0d0a4b4c4d4 + dct_trn32(row1, row3); + dct_trn32(row4, row6); + dct_trn32(row5, row7); + + // pass 3 + dct_trn64(row0, row4); // a0b0c0d0e0f0g0h0 + dct_trn64(row1, row5); + dct_trn64(row2, row6); + dct_trn64(row3, row7); + +#undef dct_trn16 +#undef dct_trn32 +#undef dct_trn64 + } + + // row pass + // vrshrn_n_s32 only supports shifts up to 16, we need + // 17. so do a non-rounding shift of 16 first then follow + // up with a rounding shift by 1. + dct_pass(vshrn_n_s32, 16); + + { + // pack and round + uint8x8_t p0 = vqrshrun_n_s16(row0, 1); + uint8x8_t p1 = vqrshrun_n_s16(row1, 1); + uint8x8_t p2 = vqrshrun_n_s16(row2, 1); + uint8x8_t p3 = vqrshrun_n_s16(row3, 1); + uint8x8_t p4 = vqrshrun_n_s16(row4, 1); + uint8x8_t p5 = vqrshrun_n_s16(row5, 1); + uint8x8_t p6 = vqrshrun_n_s16(row6, 1); + uint8x8_t p7 = vqrshrun_n_s16(row7, 1); + + // again, these can translate into one instruction, but often don't. +#define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; } +#define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); } +#define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); } + + // sadly can't use interleaved stores here since we only write + // 8 bytes to each scan line! + + // 8x8 8-bit transpose pass 1 + dct_trn8_8(p0, p1); + dct_trn8_8(p2, p3); + dct_trn8_8(p4, p5); + dct_trn8_8(p6, p7); + + // pass 2 + dct_trn8_16(p0, p2); + dct_trn8_16(p1, p3); + dct_trn8_16(p4, p6); + dct_trn8_16(p5, p7); + + // pass 3 + dct_trn8_32(p0, p4); + dct_trn8_32(p1, p5); + dct_trn8_32(p2, p6); + dct_trn8_32(p3, p7); + + // store + vst1_u8(out, p0); out += out_stride; + vst1_u8(out, p1); out += out_stride; + vst1_u8(out, p2); out += out_stride; + vst1_u8(out, p3); out += out_stride; + vst1_u8(out, p4); out += out_stride; + vst1_u8(out, p5); out += out_stride; + vst1_u8(out, p6); out += out_stride; + vst1_u8(out, p7); + +#undef dct_trn8_8 +#undef dct_trn8_16 +#undef dct_trn8_32 + } + +#undef dct_long_mul +#undef dct_long_mac +#undef dct_widen +#undef dct_wadd +#undef dct_wsub +#undef dct_bfly32o +#undef dct_pass +} + +#endif // STBI_NEON + +#define STBI__MARKER_none 0xff +// if there's a pending marker from the entropy stream, return that +// otherwise, fetch from the stream and get a marker. if there's no +// marker, return 0xff, which is never a valid marker value +static stbi_uc stbi__get_marker(stbi__jpeg *j) +{ + stbi_uc x; + if (j->marker != STBI__MARKER_none) { x = j->marker; j->marker = STBI__MARKER_none; return x; } + x = stbi__get8(j->s); + if (x != 0xff) return STBI__MARKER_none; + while (x == 0xff) + x = stbi__get8(j->s); // consume repeated 0xff fill bytes + return x; +} + +// in each scan, we'll have scan_n components, and the order +// of the components is specified by order[] +#define STBI__RESTART(x) ((x) >= 0xd0 && (x) <= 0xd7) + +// after a restart interval, stbi__jpeg_reset the entropy decoder and +// the dc prediction +static void stbi__jpeg_reset(stbi__jpeg *j) +{ + j->code_bits = 0; + j->code_buffer = 0; + j->nomore = 0; + j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0; + j->marker = STBI__MARKER_none; + j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff; + j->eob_run = 0; + // no more than 1<<31 MCUs if no restart_interal? that's plenty safe, + // since we don't even allow 1<<30 pixels +} + +static int stbi__parse_entropy_coded_data(stbi__jpeg *z) +{ + stbi__jpeg_reset(z); + if (!z->progressive) { + if (z->scan_n == 1) { + int i,j; + STBI_SIMD_ALIGN(short, data[64]); + int n = z->order[0]; + // non-interleaved data, we just need to process one block at a time, + // in trivial scanline order + // number of blocks to do just depends on how many actual "pixels" this + // component has, independent of interleaved MCU blocking and such + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); + // every data block is an MCU, so countdown the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + // if it's NOT a restart, then just bail, so we get corrupt data + // rather than no data + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } else { // interleaved + int i,j,k,x,y; + STBI_SIMD_ALIGN(short, data[64]); + for (j=0; j < z->img_mcu_y; ++j) { + for (i=0; i < z->img_mcu_x; ++i) { + // scan an interleaved mcu... process scan_n components in order + for (k=0; k < z->scan_n; ++k) { + int n = z->order[k]; + // scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (y=0; y < z->img_comp[n].v; ++y) { + for (x=0; x < z->img_comp[n].h; ++x) { + int x2 = (i*z->img_comp[n].h + x)*8; + int y2 = (j*z->img_comp[n].v + y)*8; + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data); + } + } + } + // after all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } + } else { + if (z->scan_n == 1) { + int i,j; + int n = z->order[0]; + // non-interleaved data, we just need to process one block at a time, + // in trivial scanline order + // number of blocks to do just depends on how many actual "pixels" this + // component has, independent of interleaved MCU blocking and such + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); + if (z->spec_start == 0) { + if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) + return 0; + } else { + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], z->fast_ac[ha])) + return 0; + } + // every data block is an MCU, so countdown the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } else { // interleaved + int i,j,k,x,y; + for (j=0; j < z->img_mcu_y; ++j) { + for (i=0; i < z->img_mcu_x; ++i) { + // scan an interleaved mcu... process scan_n components in order + for (k=0; k < z->scan_n; ++k) { + int n = z->order[k]; + // scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (y=0; y < z->img_comp[n].v; ++y) { + for (x=0; x < z->img_comp[n].h; ++x) { + int x2 = (i*z->img_comp[n].h + x); + int y2 = (j*z->img_comp[n].v + y); + short *data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w); + if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) + return 0; + } + } + } + // after all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } + } +} + +static void stbi__jpeg_dequantize(short *data, stbi__uint16 *dequant) +{ + int i; + for (i=0; i < 64; ++i) + data[i] *= dequant[i]; +} + +static void stbi__jpeg_finish(stbi__jpeg *z) +{ + if (z->progressive) { + // dequantize and idct the data + int i,j,n; + for (n=0; n < z->s->img_n; ++n) { + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); + stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); + } + } + } + } +} + +static int stbi__process_marker(stbi__jpeg *z, int m) +{ + int L; + switch (m) { + case STBI__MARKER_none: // no marker found + return stbi__err("expected marker","Corrupt JPEG"); + + case 0xDD: // DRI - specify restart interval + if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len","Corrupt JPEG"); + z->restart_interval = stbi__get16be(z->s); + return 1; + + case 0xDB: // DQT - define quantization table + L = stbi__get16be(z->s)-2; + while (L > 0) { + int q = stbi__get8(z->s); + int p = q >> 4, sixteen = (p != 0); + int t = q & 15,i; + if (p != 0 && p != 1) return stbi__err("bad DQT type","Corrupt JPEG"); + if (t > 3) return stbi__err("bad DQT table","Corrupt JPEG"); + + for (i=0; i < 64; ++i) + z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s)); + L -= (sixteen ? 129 : 65); + } + return L==0; + + case 0xC4: // DHT - define huffman table + L = stbi__get16be(z->s)-2; + while (L > 0) { + stbi_uc *v; + int sizes[16],i,n=0; + int q = stbi__get8(z->s); + int tc = q >> 4; + int th = q & 15; + if (tc > 1 || th > 3) return stbi__err("bad DHT header","Corrupt JPEG"); + for (i=0; i < 16; ++i) { + sizes[i] = stbi__get8(z->s); + n += sizes[i]; + } + if(n > 256) return stbi__err("bad DHT header","Corrupt JPEG"); // Loop over i < n would write past end of values! + L -= 17; + if (tc == 0) { + if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0; + v = z->huff_dc[th].values; + } else { + if (!stbi__build_huffman(z->huff_ac+th, sizes)) return 0; + v = z->huff_ac[th].values; + } + for (i=0; i < n; ++i) + v[i] = stbi__get8(z->s); + if (tc != 0) + stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th); + L -= n; + } + return L==0; + } + + // check for comment block or APP blocks + if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) { + L = stbi__get16be(z->s); + if (L < 2) { + if (m == 0xFE) + return stbi__err("bad COM len","Corrupt JPEG"); + else + return stbi__err("bad APP len","Corrupt JPEG"); + } + L -= 2; + + if (m == 0xE0 && L >= 5) { // JFIF APP0 segment + static const unsigned char tag[5] = {'J','F','I','F','\0'}; + int ok = 1; + int i; + for (i=0; i < 5; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 5; + if (ok) + z->jfif = 1; + } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment + static const unsigned char tag[6] = {'A','d','o','b','e','\0'}; + int ok = 1; + int i; + for (i=0; i < 6; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 6; + if (ok) { + stbi__get8(z->s); // version + stbi__get16be(z->s); // flags0 + stbi__get16be(z->s); // flags1 + z->app14_color_transform = stbi__get8(z->s); // color transform + L -= 6; + } + } + + stbi__skip(z->s, L); + return 1; + } + + return stbi__err("unknown marker","Corrupt JPEG"); +} + +// after we see SOS +static int stbi__process_scan_header(stbi__jpeg *z) +{ + int i; + int Ls = stbi__get16be(z->s); + z->scan_n = stbi__get8(z->s); + if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG"); + if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG"); + for (i=0; i < z->scan_n; ++i) { + int id = stbi__get8(z->s), which; + int q = stbi__get8(z->s); + for (which = 0; which < z->s->img_n; ++which) + if (z->img_comp[which].id == id) + break; + if (which == z->s->img_n) return 0; // no match + z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG"); + z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG"); + z->order[i] = which; + } + + { + int aa; + z->spec_start = stbi__get8(z->s); + z->spec_end = stbi__get8(z->s); // should be 63, but might be 0 + aa = stbi__get8(z->s); + z->succ_high = (aa >> 4); + z->succ_low = (aa & 15); + if (z->progressive) { + if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13) + return stbi__err("bad SOS", "Corrupt JPEG"); + } else { + if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG"); + if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG"); + z->spec_end = 63; + } + } + + return 1; +} + +static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why) +{ + int i; + for (i=0; i < ncomp; ++i) { + if (z->img_comp[i].raw_data) { + STBI_FREE(z->img_comp[i].raw_data); + z->img_comp[i].raw_data = NULL; + z->img_comp[i].data = NULL; + } + if (z->img_comp[i].raw_coeff) { + STBI_FREE(z->img_comp[i].raw_coeff); + z->img_comp[i].raw_coeff = 0; + z->img_comp[i].coeff = 0; + } + if (z->img_comp[i].linebuf) { + STBI_FREE(z->img_comp[i].linebuf); + z->img_comp[i].linebuf = NULL; + } + } + return why; +} + +static int stbi__process_frame_header(stbi__jpeg *z, int scan) +{ + stbi__context *s = z->s; + int Lf,p,i,q, h_max=1,v_max=1,c; + Lf = stbi__get16be(s); if (Lf < 11) return stbi__err("bad SOF len","Corrupt JPEG"); // JPEG + p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline + s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG + s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width","Corrupt JPEG"); // JPEG requires + if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + c = stbi__get8(s); + if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count","Corrupt JPEG"); + s->img_n = c; + for (i=0; i < c; ++i) { + z->img_comp[i].data = NULL; + z->img_comp[i].linebuf = NULL; + } + + if (Lf != 8+3*s->img_n) return stbi__err("bad SOF len","Corrupt JPEG"); + + z->rgb = 0; + for (i=0; i < s->img_n; ++i) { + static const unsigned char rgb[3] = { 'R', 'G', 'B' }; + z->img_comp[i].id = stbi__get8(s); + if (s->img_n == 3 && z->img_comp[i].id == rgb[i]) + ++z->rgb; + q = stbi__get8(s); + z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H","Corrupt JPEG"); + z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V","Corrupt JPEG"); + z->img_comp[i].tq = stbi__get8(s); if (z->img_comp[i].tq > 3) return stbi__err("bad TQ","Corrupt JPEG"); + } + + if (scan != STBI__SCAN_load) return 1; + + if (!stbi__mad3sizes_valid(s->img_x, s->img_y, s->img_n, 0)) return stbi__err("too large", "Image too large to decode"); + + for (i=0; i < s->img_n; ++i) { + if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h; + if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v; + } + + // check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios + // and I've never seen a non-corrupted JPEG file actually use them + for (i=0; i < s->img_n; ++i) { + if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H","Corrupt JPEG"); + if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V","Corrupt JPEG"); + } + + // compute interleaved mcu info + z->img_h_max = h_max; + z->img_v_max = v_max; + z->img_mcu_w = h_max * 8; + z->img_mcu_h = v_max * 8; + // these sizes can't be more than 17 bits + z->img_mcu_x = (s->img_x + z->img_mcu_w-1) / z->img_mcu_w; + z->img_mcu_y = (s->img_y + z->img_mcu_h-1) / z->img_mcu_h; + + for (i=0; i < s->img_n; ++i) { + // number of effective pixels (e.g. for non-interleaved MCU) + z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max-1) / h_max; + z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max-1) / v_max; + // to simplify generation, we'll allocate enough memory to decode + // the bogus oversized data from using interleaved MCUs and their + // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't + // discard the extra data until colorspace conversion + // + // img_mcu_x, img_mcu_y: <=17 bits; comp[i].h and .v are <=4 (checked earlier) + // so these muls can't overflow with 32-bit ints (which we require) + z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8; + z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8; + z->img_comp[i].coeff = 0; + z->img_comp[i].raw_coeff = 0; + z->img_comp[i].linebuf = NULL; + z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15); + if (z->img_comp[i].raw_data == NULL) + return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); + // align blocks for idct using mmx/sse + z->img_comp[i].data = (stbi_uc*) (((size_t) z->img_comp[i].raw_data + 15) & ~15); + if (z->progressive) { + // w2, h2 are multiples of 8 (see above) + z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8; + z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8; + z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15); + if (z->img_comp[i].raw_coeff == NULL) + return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); + z->img_comp[i].coeff = (short*) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); + } + } + + return 1; +} + +// use comparisons since in some cases we handle more than one case (e.g. SOF) +#define stbi__DNL(x) ((x) == 0xdc) +#define stbi__SOI(x) ((x) == 0xd8) +#define stbi__EOI(x) ((x) == 0xd9) +#define stbi__SOF(x) ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2) +#define stbi__SOS(x) ((x) == 0xda) + +#define stbi__SOF_progressive(x) ((x) == 0xc2) + +static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) +{ + int m; + z->jfif = 0; + z->app14_color_transform = -1; // valid values are 0,1,2 + z->marker = STBI__MARKER_none; // initialize cached marker to empty + m = stbi__get_marker(z); + if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG"); + if (scan == STBI__SCAN_type) return 1; + m = stbi__get_marker(z); + while (!stbi__SOF(m)) { + if (!stbi__process_marker(z,m)) return 0; + m = stbi__get_marker(z); + while (m == STBI__MARKER_none) { + // some files have extra padding after their blocks, so ok, we'll scan + if (stbi__at_eof(z->s)) return stbi__err("no SOF", "Corrupt JPEG"); + m = stbi__get_marker(z); + } + } + z->progressive = stbi__SOF_progressive(m); + if (!stbi__process_frame_header(z, scan)) return 0; + return 1; +} + +static stbi_uc stbi__skip_jpeg_junk_at_end(stbi__jpeg *j) +{ + // some JPEGs have junk at end, skip over it but if we find what looks + // like a valid marker, resume there + while (!stbi__at_eof(j->s)) { + stbi_uc x = stbi__get8(j->s); + while (x == 0xff) { // might be a marker + if (stbi__at_eof(j->s)) return STBI__MARKER_none; + x = stbi__get8(j->s); + if (x != 0x00 && x != 0xff) { + // not a stuffed zero or lead-in to another marker, looks + // like an actual marker, return it + return x; + } + // stuffed zero has x=0 now which ends the loop, meaning we go + // back to regular scan loop. + // repeated 0xff keeps trying to read the next byte of the marker. + } + } + return STBI__MARKER_none; +} + +// decode image to YCbCr format +static int stbi__decode_jpeg_image(stbi__jpeg *j) +{ + int m; + for (m = 0; m < 4; m++) { + j->img_comp[m].raw_data = NULL; + j->img_comp[m].raw_coeff = NULL; + } + j->restart_interval = 0; + if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0; + m = stbi__get_marker(j); + while (!stbi__EOI(m)) { + if (stbi__SOS(m)) { + if (!stbi__process_scan_header(j)) return 0; + if (!stbi__parse_entropy_coded_data(j)) return 0; + if (j->marker == STBI__MARKER_none ) { + j->marker = stbi__skip_jpeg_junk_at_end(j); + // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0 + } + m = stbi__get_marker(j); + if (STBI__RESTART(m)) + m = stbi__get_marker(j); + } else if (stbi__DNL(m)) { + int Ld = stbi__get16be(j->s); + stbi__uint32 NL = stbi__get16be(j->s); + if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG"); + if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG"); + m = stbi__get_marker(j); + } else { + if (!stbi__process_marker(j, m)) return 1; + m = stbi__get_marker(j); + } + } + if (j->progressive) + stbi__jpeg_finish(j); + return 1; +} + +// static jfif-centered resampling (across block boundaries) + +typedef stbi_uc *(*resample_row_func)(stbi_uc *out, stbi_uc *in0, stbi_uc *in1, + int w, int hs); + +#define stbi__div4(x) ((stbi_uc) ((x) >> 2)) + +static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + STBI_NOTUSED(out); + STBI_NOTUSED(in_far); + STBI_NOTUSED(w); + STBI_NOTUSED(hs); + return in_near; +} + +static stbi_uc* stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate two samples vertically for every one in input + int i; + STBI_NOTUSED(hs); + for (i=0; i < w; ++i) + out[i] = stbi__div4(3*in_near[i] + in_far[i] + 2); + return out; +} + +static stbi_uc* stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate two samples horizontally for every one in input + int i; + stbi_uc *input = in_near; + + if (w == 1) { + // if only one sample, can't do any interpolation + out[0] = out[1] = input[0]; + return out; + } + + out[0] = input[0]; + out[1] = stbi__div4(input[0]*3 + input[1] + 2); + for (i=1; i < w-1; ++i) { + int n = 3*input[i]+2; + out[i*2+0] = stbi__div4(n+input[i-1]); + out[i*2+1] = stbi__div4(n+input[i+1]); + } + out[i*2+0] = stbi__div4(input[w-2]*3 + input[w-1] + 2); + out[i*2+1] = input[w-1]; + + STBI_NOTUSED(in_far); + STBI_NOTUSED(hs); + + return out; +} + +#define stbi__div16(x) ((stbi_uc) ((x) >> 4)) + +static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate 2x2 samples for every one in input + int i,t0,t1; + if (w == 1) { + out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); + return out; + } + + t1 = 3*in_near[0] + in_far[0]; + out[0] = stbi__div4(t1+2); + for (i=1; i < w; ++i) { + t0 = t1; + t1 = 3*in_near[i]+in_far[i]; + out[i*2-1] = stbi__div16(3*t0 + t1 + 8); + out[i*2 ] = stbi__div16(3*t1 + t0 + 8); + } + out[w*2-1] = stbi__div4(t1+2); + + STBI_NOTUSED(hs); + + return out; +} + +#if defined(STBI_SSE2) || defined(STBI_NEON) +static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate 2x2 samples for every one in input + int i=0,t0,t1; + + if (w == 1) { + out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); + return out; + } + + t1 = 3*in_near[0] + in_far[0]; + // process groups of 8 pixels for as long as we can. + // note we can't handle the last pixel in a row in this loop + // because we need to handle the filter boundary conditions. + for (; i < ((w-1) & ~7); i += 8) { +#if defined(STBI_SSE2) + // load and perform the vertical filtering pass + // this uses 3*x + y = 4*x + (y - x) + __m128i zero = _mm_setzero_si128(); + __m128i farb = _mm_loadl_epi64((__m128i *) (in_far + i)); + __m128i nearb = _mm_loadl_epi64((__m128i *) (in_near + i)); + __m128i farw = _mm_unpacklo_epi8(farb, zero); + __m128i nearw = _mm_unpacklo_epi8(nearb, zero); + __m128i diff = _mm_sub_epi16(farw, nearw); + __m128i nears = _mm_slli_epi16(nearw, 2); + __m128i curr = _mm_add_epi16(nears, diff); // current row + + // horizontal filter works the same based on shifted vers of current + // row. "prev" is current row shifted right by 1 pixel; we need to + // insert the previous pixel value (from t1). + // "next" is current row shifted left by 1 pixel, with first pixel + // of next block of 8 pixels added in. + __m128i prv0 = _mm_slli_si128(curr, 2); + __m128i nxt0 = _mm_srli_si128(curr, 2); + __m128i prev = _mm_insert_epi16(prv0, t1, 0); + __m128i next = _mm_insert_epi16(nxt0, 3*in_near[i+8] + in_far[i+8], 7); + + // horizontal filter, polyphase implementation since it's convenient: + // even pixels = 3*cur + prev = cur*4 + (prev - cur) + // odd pixels = 3*cur + next = cur*4 + (next - cur) + // note the shared term. + __m128i bias = _mm_set1_epi16(8); + __m128i curs = _mm_slli_epi16(curr, 2); + __m128i prvd = _mm_sub_epi16(prev, curr); + __m128i nxtd = _mm_sub_epi16(next, curr); + __m128i curb = _mm_add_epi16(curs, bias); + __m128i even = _mm_add_epi16(prvd, curb); + __m128i odd = _mm_add_epi16(nxtd, curb); + + // interleave even and odd pixels, then undo scaling. + __m128i int0 = _mm_unpacklo_epi16(even, odd); + __m128i int1 = _mm_unpackhi_epi16(even, odd); + __m128i de0 = _mm_srli_epi16(int0, 4); + __m128i de1 = _mm_srli_epi16(int1, 4); + + // pack and write output + __m128i outv = _mm_packus_epi16(de0, de1); + _mm_storeu_si128((__m128i *) (out + i*2), outv); +#elif defined(STBI_NEON) + // load and perform the vertical filtering pass + // this uses 3*x + y = 4*x + (y - x) + uint8x8_t farb = vld1_u8(in_far + i); + uint8x8_t nearb = vld1_u8(in_near + i); + int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(farb, nearb)); + int16x8_t nears = vreinterpretq_s16_u16(vshll_n_u8(nearb, 2)); + int16x8_t curr = vaddq_s16(nears, diff); // current row + + // horizontal filter works the same based on shifted vers of current + // row. "prev" is current row shifted right by 1 pixel; we need to + // insert the previous pixel value (from t1). + // "next" is current row shifted left by 1 pixel, with first pixel + // of next block of 8 pixels added in. + int16x8_t prv0 = vextq_s16(curr, curr, 7); + int16x8_t nxt0 = vextq_s16(curr, curr, 1); + int16x8_t prev = vsetq_lane_s16(t1, prv0, 0); + int16x8_t next = vsetq_lane_s16(3*in_near[i+8] + in_far[i+8], nxt0, 7); + + // horizontal filter, polyphase implementation since it's convenient: + // even pixels = 3*cur + prev = cur*4 + (prev - cur) + // odd pixels = 3*cur + next = cur*4 + (next - cur) + // note the shared term. + int16x8_t curs = vshlq_n_s16(curr, 2); + int16x8_t prvd = vsubq_s16(prev, curr); + int16x8_t nxtd = vsubq_s16(next, curr); + int16x8_t even = vaddq_s16(curs, prvd); + int16x8_t odd = vaddq_s16(curs, nxtd); + + // undo scaling and round, then store with even/odd phases interleaved + uint8x8x2_t o; + o.val[0] = vqrshrun_n_s16(even, 4); + o.val[1] = vqrshrun_n_s16(odd, 4); + vst2_u8(out + i*2, o); +#endif + + // "previous" value for next iter + t1 = 3*in_near[i+7] + in_far[i+7]; + } + + t0 = t1; + t1 = 3*in_near[i] + in_far[i]; + out[i*2] = stbi__div16(3*t1 + t0 + 8); + + for (++i; i < w; ++i) { + t0 = t1; + t1 = 3*in_near[i]+in_far[i]; + out[i*2-1] = stbi__div16(3*t0 + t1 + 8); + out[i*2 ] = stbi__div16(3*t1 + t0 + 8); + } + out[w*2-1] = stbi__div4(t1+2); + + STBI_NOTUSED(hs); + + return out; +} +#endif + +static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // resample with nearest-neighbor + int i,j; + STBI_NOTUSED(in_far); + for (i=0; i < w; ++i) + for (j=0; j < hs; ++j) + out[i*hs+j] = in_near[i]; + return out; +} + +// this is a reduced-precision calculation of YCbCr-to-RGB introduced +// to make sure the code produces the same results in both SIMD and scalar +#define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8) +static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step) +{ + int i; + for (i=0; i < count; ++i) { + int y_fixed = (y[i] << 20) + (1<<19); // rounding + int r,g,b; + int cr = pcr[i] - 128; + int cb = pcb[i] - 128; + r = y_fixed + cr* stbi__float2fixed(1.40200f); + g = y_fixed + (cr*-stbi__float2fixed(0.71414f)) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); + b = y_fixed + cb* stbi__float2fixed(1.77200f); + r >>= 20; + g >>= 20; + b >>= 20; + if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } + if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } + if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } + out[0] = (stbi_uc)r; + out[1] = (stbi_uc)g; + out[2] = (stbi_uc)b; + out[3] = 255; + out += step; + } +} + +#if defined(STBI_SSE2) || defined(STBI_NEON) +static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc const *pcb, stbi_uc const *pcr, int count, int step) +{ + int i = 0; + +#ifdef STBI_SSE2 + // step == 3 is pretty ugly on the final interleave, and i'm not convinced + // it's useful in practice (you wouldn't use it for textures, for example). + // so just accelerate step == 4 case. + if (step == 4) { + // this is a fairly straightforward implementation and not super-optimized. + __m128i signflip = _mm_set1_epi8(-0x80); + __m128i cr_const0 = _mm_set1_epi16( (short) ( 1.40200f*4096.0f+0.5f)); + __m128i cr_const1 = _mm_set1_epi16( - (short) ( 0.71414f*4096.0f+0.5f)); + __m128i cb_const0 = _mm_set1_epi16( - (short) ( 0.34414f*4096.0f+0.5f)); + __m128i cb_const1 = _mm_set1_epi16( (short) ( 1.77200f*4096.0f+0.5f)); + __m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128); + __m128i xw = _mm_set1_epi16(255); // alpha channel + + for (; i+7 < count; i += 8) { + // load + __m128i y_bytes = _mm_loadl_epi64((__m128i *) (y+i)); + __m128i cr_bytes = _mm_loadl_epi64((__m128i *) (pcr+i)); + __m128i cb_bytes = _mm_loadl_epi64((__m128i *) (pcb+i)); + __m128i cr_biased = _mm_xor_si128(cr_bytes, signflip); // -128 + __m128i cb_biased = _mm_xor_si128(cb_bytes, signflip); // -128 + + // unpack to short (and left-shift cr, cb by 8) + __m128i yw = _mm_unpacklo_epi8(y_bias, y_bytes); + __m128i crw = _mm_unpacklo_epi8(_mm_setzero_si128(), cr_biased); + __m128i cbw = _mm_unpacklo_epi8(_mm_setzero_si128(), cb_biased); + + // color transform + __m128i yws = _mm_srli_epi16(yw, 4); + __m128i cr0 = _mm_mulhi_epi16(cr_const0, crw); + __m128i cb0 = _mm_mulhi_epi16(cb_const0, cbw); + __m128i cb1 = _mm_mulhi_epi16(cbw, cb_const1); + __m128i cr1 = _mm_mulhi_epi16(crw, cr_const1); + __m128i rws = _mm_add_epi16(cr0, yws); + __m128i gwt = _mm_add_epi16(cb0, yws); + __m128i bws = _mm_add_epi16(yws, cb1); + __m128i gws = _mm_add_epi16(gwt, cr1); + + // descale + __m128i rw = _mm_srai_epi16(rws, 4); + __m128i bw = _mm_srai_epi16(bws, 4); + __m128i gw = _mm_srai_epi16(gws, 4); + + // back to byte, set up for transpose + __m128i brb = _mm_packus_epi16(rw, bw); + __m128i gxb = _mm_packus_epi16(gw, xw); + + // transpose to interleave channels + __m128i t0 = _mm_unpacklo_epi8(brb, gxb); + __m128i t1 = _mm_unpackhi_epi8(brb, gxb); + __m128i o0 = _mm_unpacklo_epi16(t0, t1); + __m128i o1 = _mm_unpackhi_epi16(t0, t1); + + // store + _mm_storeu_si128((__m128i *) (out + 0), o0); + _mm_storeu_si128((__m128i *) (out + 16), o1); + out += 32; + } + } +#endif + +#ifdef STBI_NEON + // in this version, step=3 support would be easy to add. but is there demand? + if (step == 4) { + // this is a fairly straightforward implementation and not super-optimized. + uint8x8_t signflip = vdup_n_u8(0x80); + int16x8_t cr_const0 = vdupq_n_s16( (short) ( 1.40200f*4096.0f+0.5f)); + int16x8_t cr_const1 = vdupq_n_s16( - (short) ( 0.71414f*4096.0f+0.5f)); + int16x8_t cb_const0 = vdupq_n_s16( - (short) ( 0.34414f*4096.0f+0.5f)); + int16x8_t cb_const1 = vdupq_n_s16( (short) ( 1.77200f*4096.0f+0.5f)); + + for (; i+7 < count; i += 8) { + // load + uint8x8_t y_bytes = vld1_u8(y + i); + uint8x8_t cr_bytes = vld1_u8(pcr + i); + uint8x8_t cb_bytes = vld1_u8(pcb + i); + int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip)); + int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip)); + + // expand to s16 + int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4)); + int16x8_t crw = vshll_n_s8(cr_biased, 7); + int16x8_t cbw = vshll_n_s8(cb_biased, 7); + + // color transform + int16x8_t cr0 = vqdmulhq_s16(crw, cr_const0); + int16x8_t cb0 = vqdmulhq_s16(cbw, cb_const0); + int16x8_t cr1 = vqdmulhq_s16(crw, cr_const1); + int16x8_t cb1 = vqdmulhq_s16(cbw, cb_const1); + int16x8_t rws = vaddq_s16(yws, cr0); + int16x8_t gws = vaddq_s16(vaddq_s16(yws, cb0), cr1); + int16x8_t bws = vaddq_s16(yws, cb1); + + // undo scaling, round, convert to byte + uint8x8x4_t o; + o.val[0] = vqrshrun_n_s16(rws, 4); + o.val[1] = vqrshrun_n_s16(gws, 4); + o.val[2] = vqrshrun_n_s16(bws, 4); + o.val[3] = vdup_n_u8(255); + + // store, interleaving r/g/b/a + vst4_u8(out, o); + out += 8*4; + } + } +#endif + + for (; i < count; ++i) { + int y_fixed = (y[i] << 20) + (1<<19); // rounding + int r,g,b; + int cr = pcr[i] - 128; + int cb = pcb[i] - 128; + r = y_fixed + cr* stbi__float2fixed(1.40200f); + g = y_fixed + cr*-stbi__float2fixed(0.71414f) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); + b = y_fixed + cb* stbi__float2fixed(1.77200f); + r >>= 20; + g >>= 20; + b >>= 20; + if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } + if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } + if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } + out[0] = (stbi_uc)r; + out[1] = (stbi_uc)g; + out[2] = (stbi_uc)b; + out[3] = 255; + out += step; + } +} +#endif + +// set up the kernels +static void stbi__setup_jpeg(stbi__jpeg *j) +{ + j->idct_block_kernel = stbi__idct_block; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_row; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2; + +#ifdef STBI_SSE2 + if (stbi__sse2_available()) { + j->idct_block_kernel = stbi__idct_simd; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; + } +#endif + +#ifdef STBI_NEON + j->idct_block_kernel = stbi__idct_simd; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; +#endif +} + +// clean up the temporary component buffers +static void stbi__cleanup_jpeg(stbi__jpeg *j) +{ + stbi__free_jpeg_components(j, j->s->img_n, 0); +} + +typedef struct +{ + resample_row_func resample; + stbi_uc *line0,*line1; + int hs,vs; // expansion factor in each axis + int w_lores; // horizontal pixels pre-expansion + int ystep; // how far through vertical expansion we are + int ypos; // which pre-expansion row we're on +} stbi__resample; + +// fast 0..255 * 0..255 => 0..255 rounded multiplication +static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) +{ + unsigned int t = x*y + 128; + return (stbi_uc) ((t + (t >>8)) >> 8); +} + +static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) +{ + int n, decode_n, is_rgb; + z->s->img_n = 0; // make stbi__cleanup_jpeg safe + + // validate req_comp + if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); + + // load a jpeg image from whichever source, but leave in YCbCr format + if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; } + + // determine actual number of components to generate + n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1; + + is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif)); + + if (z->s->img_n == 3 && n < 3 && !is_rgb) + decode_n = 1; + else + decode_n = z->s->img_n; + + // nothing to do if no components requested; check this now to avoid + // accessing uninitialized coutput[0] later + if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; } + + // resample and color-convert + { + int k; + unsigned int i,j; + stbi_uc *output; + stbi_uc *coutput[4] = { NULL, NULL, NULL, NULL }; + + stbi__resample res_comp[4]; + + for (k=0; k < decode_n; ++k) { + stbi__resample *r = &res_comp[k]; + + // allocate line buffer big enough for upsampling off the edges + // with upsample factor of 4 + z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3); + if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } + + r->hs = z->img_h_max / z->img_comp[k].h; + r->vs = z->img_v_max / z->img_comp[k].v; + r->ystep = r->vs >> 1; + r->w_lores = (z->s->img_x + r->hs-1) / r->hs; + r->ypos = 0; + r->line0 = r->line1 = z->img_comp[k].data; + + if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1; + else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2; + else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2; + else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel; + else r->resample = stbi__resample_row_generic; + } + + // can't error after this so, this is safe + output = (stbi_uc *) stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1); + if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } + + // now go ahead and resample + for (j=0; j < z->s->img_y; ++j) { + stbi_uc *out = output + n * z->s->img_x * j; + for (k=0; k < decode_n; ++k) { + stbi__resample *r = &res_comp[k]; + int y_bot = r->ystep >= (r->vs >> 1); + coutput[k] = r->resample(z->img_comp[k].linebuf, + y_bot ? r->line1 : r->line0, + y_bot ? r->line0 : r->line1, + r->w_lores, r->hs); + if (++r->ystep >= r->vs) { + r->ystep = 0; + r->line0 = r->line1; + if (++r->ypos < z->img_comp[k].y) + r->line1 += z->img_comp[k].w2; + } + } + if (n >= 3) { + stbi_uc *y = coutput[0]; + if (z->s->img_n == 3) { + if (is_rgb) { + for (i=0; i < z->s->img_x; ++i) { + out[0] = y[i]; + out[1] = coutput[1][i]; + out[2] = coutput[2][i]; + out[3] = 255; + out += n; + } + } else { + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + } + } else if (z->s->img_n == 4) { + if (z->app14_color_transform == 0) { // CMYK + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + out[0] = stbi__blinn_8x8(coutput[0][i], m); + out[1] = stbi__blinn_8x8(coutput[1][i], m); + out[2] = stbi__blinn_8x8(coutput[2][i], m); + out[3] = 255; + out += n; + } + } else if (z->app14_color_transform == 2) { // YCCK + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + out[0] = stbi__blinn_8x8(255 - out[0], m); + out[1] = stbi__blinn_8x8(255 - out[1], m); + out[2] = stbi__blinn_8x8(255 - out[2], m); + out += n; + } + } else { // YCbCr + alpha? Ignore the fourth channel for now + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + } + } else + for (i=0; i < z->s->img_x; ++i) { + out[0] = out[1] = out[2] = y[i]; + out[3] = 255; // not used if n==3 + out += n; + } + } else { + if (is_rgb) { + if (n == 1) + for (i=0; i < z->s->img_x; ++i) + *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); + else { + for (i=0; i < z->s->img_x; ++i, out += 2) { + out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); + out[1] = 255; + } + } + } else if (z->s->img_n == 4 && z->app14_color_transform == 0) { + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + stbi_uc r = stbi__blinn_8x8(coutput[0][i], m); + stbi_uc g = stbi__blinn_8x8(coutput[1][i], m); + stbi_uc b = stbi__blinn_8x8(coutput[2][i], m); + out[0] = stbi__compute_y(r, g, b); + out[1] = 255; + out += n; + } + } else if (z->s->img_n == 4 && z->app14_color_transform == 2) { + for (i=0; i < z->s->img_x; ++i) { + out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]); + out[1] = 255; + out += n; + } + } else { + stbi_uc *y = coutput[0]; + if (n == 1) + for (i=0; i < z->s->img_x; ++i) out[i] = y[i]; + else + for (i=0; i < z->s->img_x; ++i) { *out++ = y[i]; *out++ = 255; } + } + } + } + stbi__cleanup_jpeg(z); + *out_x = z->s->img_x; + *out_y = z->s->img_y; + if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output + return output; + } +} + +static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + unsigned char* result; + stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg)); + if (!j) return stbi__errpuc("outofmem", "Out of memory"); + memset(j, 0, sizeof(stbi__jpeg)); + STBI_NOTUSED(ri); + j->s = s; + stbi__setup_jpeg(j); + result = load_jpeg_image(j, x,y,comp,req_comp); + STBI_FREE(j); + return result; +} + +static int stbi__jpeg_test(stbi__context *s) +{ + int r; + stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg)); + if (!j) return stbi__err("outofmem", "Out of memory"); + memset(j, 0, sizeof(stbi__jpeg)); + j->s = s; + stbi__setup_jpeg(j); + r = stbi__decode_jpeg_header(j, STBI__SCAN_type); + stbi__rewind(s); + STBI_FREE(j); + return r; +} + +static int stbi__jpeg_info_raw(stbi__jpeg *j, int *x, int *y, int *comp) +{ + if (!stbi__decode_jpeg_header(j, STBI__SCAN_header)) { + stbi__rewind( j->s ); + return 0; + } + if (x) *x = j->s->img_x; + if (y) *y = j->s->img_y; + if (comp) *comp = j->s->img_n >= 3 ? 3 : 1; + return 1; +} + +static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp) +{ + int result; + stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg))); + if (!j) return stbi__err("outofmem", "Out of memory"); + memset(j, 0, sizeof(stbi__jpeg)); + j->s = s; + result = stbi__jpeg_info_raw(j, x, y, comp); + STBI_FREE(j); + return result; +} +#endif + +// public domain zlib decode v0.2 Sean Barrett 2006-11-18 +// simple implementation +// - all input must be provided in an upfront buffer +// - all output is written to a single output buffer (can malloc/realloc) +// performance +// - fast huffman + +#ifndef STBI_NO_ZLIB + +// fast-way is faster to check than jpeg huffman, but slow way is slower +#define STBI__ZFAST_BITS 9 // accelerate all cases in default tables +#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1) +#define STBI__ZNSYMS 288 // number of symbols in literal/length alphabet + +// zlib-style huffman encoding +// (jpegs packs from left, zlib from right, so can't share code) +typedef struct +{ + stbi__uint16 fast[1 << STBI__ZFAST_BITS]; + stbi__uint16 firstcode[16]; + int maxcode[17]; + stbi__uint16 firstsymbol[16]; + stbi_uc size[STBI__ZNSYMS]; + stbi__uint16 value[STBI__ZNSYMS]; +} stbi__zhuffman; + +stbi_inline static int stbi__bitreverse16(int n) +{ + n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); + n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); + n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); + n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); + return n; +} + +stbi_inline static int stbi__bit_reverse(int v, int bits) +{ + STBI_ASSERT(bits <= 16); + // to bit reverse n bits, reverse 16 and shift + // e.g. 11 bits, bit reverse and shift away 5 + return stbi__bitreverse16(v) >> (16-bits); +} + +static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num) +{ + int i,k=0; + int code, next_code[16], sizes[17]; + + // DEFLATE spec for generating codes + memset(sizes, 0, sizeof(sizes)); + memset(z->fast, 0, sizeof(z->fast)); + for (i=0; i < num; ++i) + ++sizes[sizelist[i]]; + sizes[0] = 0; + for (i=1; i < 16; ++i) + if (sizes[i] > (1 << i)) + return stbi__err("bad sizes", "Corrupt PNG"); + code = 0; + for (i=1; i < 16; ++i) { + next_code[i] = code; + z->firstcode[i] = (stbi__uint16) code; + z->firstsymbol[i] = (stbi__uint16) k; + code = (code + sizes[i]); + if (sizes[i]) + if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG"); + z->maxcode[i] = code << (16-i); // preshift for inner loop + code <<= 1; + k += sizes[i]; + } + z->maxcode[16] = 0x10000; // sentinel + for (i=0; i < num; ++i) { + int s = sizelist[i]; + if (s) { + int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s]; + stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i); + z->size [c] = (stbi_uc ) s; + z->value[c] = (stbi__uint16) i; + if (s <= STBI__ZFAST_BITS) { + int j = stbi__bit_reverse(next_code[s],s); + while (j < (1 << STBI__ZFAST_BITS)) { + z->fast[j] = fastv; + j += (1 << s); + } + } + ++next_code[s]; + } + } + return 1; +} + +// zlib-from-memory implementation for PNG reading +// because PNG allows splitting the zlib stream arbitrarily, +// and it's annoying structurally to have PNG call ZLIB call PNG, +// we require PNG read all the IDATs and combine them into a single +// memory buffer + +typedef struct +{ + stbi_uc *zbuffer, *zbuffer_end; + int num_bits; + int hit_zeof_once; + stbi__uint32 code_buffer; + + char *zout; + char *zout_start; + char *zout_end; + int z_expandable; + + stbi__zhuffman z_length, z_distance; +} stbi__zbuf; + +stbi_inline static int stbi__zeof(stbi__zbuf *z) +{ + return (z->zbuffer >= z->zbuffer_end); +} + +stbi_inline static stbi_uc stbi__zget8(stbi__zbuf *z) +{ + return stbi__zeof(z) ? 0 : *z->zbuffer++; +} + +static void stbi__fill_bits(stbi__zbuf *z) +{ + do { + if (z->code_buffer >= (1U << z->num_bits)) { + z->zbuffer = z->zbuffer_end; /* treat this as EOF so we fail. */ + return; + } + z->code_buffer |= (unsigned int) stbi__zget8(z) << z->num_bits; + z->num_bits += 8; + } while (z->num_bits <= 24); +} + +stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n) +{ + unsigned int k; + if (z->num_bits < n) stbi__fill_bits(z); + k = z->code_buffer & ((1 << n) - 1); + z->code_buffer >>= n; + z->num_bits -= n; + return k; +} + +static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) +{ + int b,s,k; + // not resolved by fast table, so compute it the slow way + // use jpeg approach, which requires MSbits at top + k = stbi__bit_reverse(a->code_buffer, 16); + for (s=STBI__ZFAST_BITS+1; ; ++s) + if (k < z->maxcode[s]) + break; + if (s >= 16) return -1; // invalid code! + // code size is s, so: + b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; + if (b >= STBI__ZNSYMS) return -1; // some data was corrupt somewhere! + if (z->size[b] != s) return -1; // was originally an assert, but report failure instead. + a->code_buffer >>= s; + a->num_bits -= s; + return z->value[b]; +} + +stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) +{ + int b,s; + if (a->num_bits < 16) { + if (stbi__zeof(a)) { + if (!a->hit_zeof_once) { + // This is the first time we hit eof, insert 16 extra padding btis + // to allow us to keep going; if we actually consume any of them + // though, that is invalid data. This is caught later. + a->hit_zeof_once = 1; + a->num_bits += 16; // add 16 implicit zero bits + } else { + // We already inserted our extra 16 padding bits and are again + // out, this stream is actually prematurely terminated. + return -1; + } + } else { + stbi__fill_bits(a); + } + } + b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; + if (b) { + s = b >> 9; + a->code_buffer >>= s; + a->num_bits -= s; + return b & 511; + } + return stbi__zhuffman_decode_slowpath(a, z); +} + +static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes +{ + char *q; + unsigned int cur, limit, old_limit; + z->zout = zout; + if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG"); + cur = (unsigned int) (z->zout - z->zout_start); + limit = old_limit = (unsigned) (z->zout_end - z->zout_start); + if (UINT_MAX - cur < (unsigned) n) return stbi__err("outofmem", "Out of memory"); + while (cur + n > limit) { + if(limit > UINT_MAX / 2) return stbi__err("outofmem", "Out of memory"); + limit *= 2; + } + q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); + STBI_NOTUSED(old_limit); + if (q == NULL) return stbi__err("outofmem", "Out of memory"); + z->zout_start = q; + z->zout = q + cur; + z->zout_end = q + limit; + return 1; +} + +static const int stbi__zlength_base[31] = { + 3,4,5,6,7,8,9,10,11,13, + 15,17,19,23,27,31,35,43,51,59, + 67,83,99,115,131,163,195,227,258,0,0 }; + +static const int stbi__zlength_extra[31]= +{ 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; + +static const int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, + 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; + +static const int stbi__zdist_extra[32] = +{ 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +static int stbi__parse_huffman_block(stbi__zbuf *a) +{ + char *zout = a->zout; + for(;;) { + int z = stbi__zhuffman_decode(a, &a->z_length); + if (z < 256) { + if (z < 0) return stbi__err("bad huffman code","Corrupt PNG"); // error in huffman codes + if (zout >= a->zout_end) { + if (!stbi__zexpand(a, zout, 1)) return 0; + zout = a->zout; + } + *zout++ = (char) z; + } else { + stbi_uc *p; + int len,dist; + if (z == 256) { + a->zout = zout; + if (a->hit_zeof_once && a->num_bits < 16) { + // The first time we hit zeof, we inserted 16 extra zero bits into our bit + // buffer so the decoder can just do its speculative decoding. But if we + // actually consumed any of those bits (which is the case when num_bits < 16), + // the stream actually read past the end so it is malformed. + return stbi__err("unexpected end","Corrupt PNG"); + } + return 1; + } + if (z >= 286) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data + z -= 257; + len = stbi__zlength_base[z]; + if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); + z = stbi__zhuffman_decode(a, &a->z_distance); + if (z < 0 || z >= 30) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data + dist = stbi__zdist_base[z]; + if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); + if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG"); + if (len > a->zout_end - zout) { + if (!stbi__zexpand(a, zout, len)) return 0; + zout = a->zout; + } + p = (stbi_uc *) (zout - dist); + if (dist == 1) { // run of one byte; common in images. + stbi_uc v = *p; + if (len) { do *zout++ = v; while (--len); } + } else { + if (len) { do *zout++ = *p++; while (--len); } + } + } + } +} + +static int stbi__compute_huffman_codes(stbi__zbuf *a) +{ + static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; + stbi__zhuffman z_codelength; + stbi_uc lencodes[286+32+137];//padding for maximum single op + stbi_uc codelength_sizes[19]; + int i,n; + + int hlit = stbi__zreceive(a,5) + 257; + int hdist = stbi__zreceive(a,5) + 1; + int hclen = stbi__zreceive(a,4) + 4; + int ntot = hlit + hdist; + + memset(codelength_sizes, 0, sizeof(codelength_sizes)); + for (i=0; i < hclen; ++i) { + int s = stbi__zreceive(a,3); + codelength_sizes[length_dezigzag[i]] = (stbi_uc) s; + } + if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; + + n = 0; + while (n < ntot) { + int c = stbi__zhuffman_decode(a, &z_codelength); + if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG"); + if (c < 16) + lencodes[n++] = (stbi_uc) c; + else { + stbi_uc fill = 0; + if (c == 16) { + c = stbi__zreceive(a,2)+3; + if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG"); + fill = lencodes[n-1]; + } else if (c == 17) { + c = stbi__zreceive(a,3)+3; + } else if (c == 18) { + c = stbi__zreceive(a,7)+11; + } else { + return stbi__err("bad codelengths", "Corrupt PNG"); + } + if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG"); + memset(lencodes+n, fill, c); + n += c; + } + } + if (n != ntot) return stbi__err("bad codelengths","Corrupt PNG"); + if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0; + if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0; + return 1; +} + +static int stbi__parse_uncompressed_block(stbi__zbuf *a) +{ + stbi_uc header[4]; + int len,nlen,k; + if (a->num_bits & 7) + stbi__zreceive(a, a->num_bits & 7); // discard + // drain the bit-packed data into header + k = 0; + while (a->num_bits > 0) { + header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check + a->code_buffer >>= 8; + a->num_bits -= 8; + } + if (a->num_bits < 0) return stbi__err("zlib corrupt","Corrupt PNG"); + // now fill header the normal way + while (k < 4) + header[k++] = stbi__zget8(a); + len = header[1] * 256 + header[0]; + nlen = header[3] * 256 + header[2]; + if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt","Corrupt PNG"); + if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer","Corrupt PNG"); + if (a->zout + len > a->zout_end) + if (!stbi__zexpand(a, a->zout, len)) return 0; + memcpy(a->zout, a->zbuffer, len); + a->zbuffer += len; + a->zout += len; + return 1; +} + +static int stbi__parse_zlib_header(stbi__zbuf *a) +{ + int cmf = stbi__zget8(a); + int cm = cmf & 15; + /* int cinfo = cmf >> 4; */ + int flg = stbi__zget8(a); + if (stbi__zeof(a)) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec + if ((cmf*256+flg) % 31 != 0) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec + if (flg & 32) return stbi__err("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png + if (cm != 8) return stbi__err("bad compression","Corrupt PNG"); // DEFLATE required for png + // window = 1 << (8 + cinfo)... but who cares, we fully buffer output + return 1; +} + +static const stbi_uc stbi__zdefault_length[STBI__ZNSYMS] = +{ + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8 +}; +static const stbi_uc stbi__zdefault_distance[32] = +{ + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 +}; +/* +Init algorithm: +{ + int i; // use <= to match clearly with spec + for (i=0; i <= 143; ++i) stbi__zdefault_length[i] = 8; + for ( ; i <= 255; ++i) stbi__zdefault_length[i] = 9; + for ( ; i <= 279; ++i) stbi__zdefault_length[i] = 7; + for ( ; i <= 287; ++i) stbi__zdefault_length[i] = 8; + + for (i=0; i <= 31; ++i) stbi__zdefault_distance[i] = 5; +} +*/ + +static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) +{ + int final, type; + if (parse_header) + if (!stbi__parse_zlib_header(a)) return 0; + a->num_bits = 0; + a->code_buffer = 0; + a->hit_zeof_once = 0; + do { + final = stbi__zreceive(a,1); + type = stbi__zreceive(a,2); + if (type == 0) { + if (!stbi__parse_uncompressed_block(a)) return 0; + } else if (type == 3) { + return 0; + } else { + if (type == 1) { + // use fixed code lengths + if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , STBI__ZNSYMS)) return 0; + if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; + } else { + if (!stbi__compute_huffman_codes(a)) return 0; + } + if (!stbi__parse_huffman_block(a)) return 0; + } + } while (!final); + return 1; +} + +static int stbi__do_zlib(stbi__zbuf *a, char *obuf, int olen, int exp, int parse_header) +{ + a->zout_start = obuf; + a->zout = obuf; + a->zout_end = obuf + olen; + a->z_expandable = exp; + + return stbi__parse_zlib(a, parse_header); +} + +STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(initial_size); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer + len; + if (stbi__do_zlib(&a, p, initial_size, 1, 1)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen) +{ + return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); +} + +STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(initial_size); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer + len; + if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen) +{ + stbi__zbuf a; + a.zbuffer = (stbi_uc *) ibuffer; + a.zbuffer_end = (stbi_uc *) ibuffer + ilen; + if (stbi__do_zlib(&a, obuffer, olen, 0, 1)) + return (int) (a.zout - a.zout_start); + else + return -1; +} + +STBIDEF char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(16384); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer+len; + if (stbi__do_zlib(&a, p, 16384, 1, 0)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen) +{ + stbi__zbuf a; + a.zbuffer = (stbi_uc *) ibuffer; + a.zbuffer_end = (stbi_uc *) ibuffer + ilen; + if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) + return (int) (a.zout - a.zout_start); + else + return -1; +} +#endif + +// public domain "baseline" PNG decoder v0.10 Sean Barrett 2006-11-18 +// simple implementation +// - only 8-bit samples +// - no CRC checking +// - allocates lots of intermediate memory +// - avoids problem of streaming data between subsystems +// - avoids explicit window management +// performance +// - uses stb_zlib, a PD zlib implementation with fast huffman decoding + +#ifndef STBI_NO_PNG +typedef struct +{ + stbi__uint32 length; + stbi__uint32 type; +} stbi__pngchunk; + +static stbi__pngchunk stbi__get_chunk_header(stbi__context *s) +{ + stbi__pngchunk c; + c.length = stbi__get32be(s); + c.type = stbi__get32be(s); + return c; +} + +static int stbi__check_png_header(stbi__context *s) +{ + static const stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 }; + int i; + for (i=0; i < 8; ++i) + if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG"); + return 1; +} + +typedef struct +{ + stbi__context *s; + stbi_uc *idata, *expanded, *out; + int depth; +} stbi__png; + + +enum { + STBI__F_none=0, + STBI__F_sub=1, + STBI__F_up=2, + STBI__F_avg=3, + STBI__F_paeth=4, + // synthetic filter used for first scanline to avoid needing a dummy row of 0s + STBI__F_avg_first +}; + +static stbi_uc first_row_filter[5] = +{ + STBI__F_none, + STBI__F_sub, + STBI__F_none, + STBI__F_avg_first, + STBI__F_sub // Paeth with b=c=0 turns out to be equivalent to sub +}; + +static int stbi__paeth(int a, int b, int c) +{ + // This formulation looks very different from the reference in the PNG spec, but is + // actually equivalent and has favorable data dependencies and admits straightforward + // generation of branch-free code, which helps performance significantly. + int thresh = c*3 - (a + b); + int lo = a < b ? a : b; + int hi = a < b ? b : a; + int t0 = (hi <= thresh) ? lo : c; + int t1 = (thresh <= lo) ? hi : t0; + return t1; +} + +static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 }; + +// adds an extra all-255 alpha channel +// dest == src is legal +// img_n must be 1 or 3 +static void stbi__create_png_alpha_expand8(stbi_uc *dest, stbi_uc *src, stbi__uint32 x, int img_n) +{ + int i; + // must process data backwards since we allow dest==src + if (img_n == 1) { + for (i=x-1; i >= 0; --i) { + dest[i*2+1] = 255; + dest[i*2+0] = src[i]; + } + } else { + STBI_ASSERT(img_n == 3); + for (i=x-1; i >= 0; --i) { + dest[i*4+3] = 255; + dest[i*4+2] = src[i*3+2]; + dest[i*4+1] = src[i*3+1]; + dest[i*4+0] = src[i*3+0]; + } + } +} + +// create the png data from post-deflated data +static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) +{ + int bytes = (depth == 16 ? 2 : 1); + stbi__context *s = a->s; + stbi__uint32 i,j,stride = x*out_n*bytes; + stbi__uint32 img_len, img_width_bytes; + stbi_uc *filter_buf; + int all_ok = 1; + int k; + int img_n = s->img_n; // copy it into a local for later + + int output_bytes = out_n*bytes; + int filter_bytes = img_n*bytes; + int width = x; + + STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1); + a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into + if (!a->out) return stbi__err("outofmem", "Out of memory"); + + // note: error exits here don't need to clean up a->out individually, + // stbi__do_png always does on error. + if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG"); + img_width_bytes = (((img_n * x * depth) + 7) >> 3); + if (!stbi__mad2sizes_valid(img_width_bytes, y, img_width_bytes)) return stbi__err("too large", "Corrupt PNG"); + img_len = (img_width_bytes + 1) * y; + + // we used to check for exact match between raw_len and img_len on non-interlaced PNGs, + // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros), + // so just check for raw_len < img_len always. + if (raw_len < img_len) return stbi__err("not enough pixels","Corrupt PNG"); + + // Allocate two scan lines worth of filter workspace buffer. + filter_buf = (stbi_uc *) stbi__malloc_mad2(img_width_bytes, 2, 0); + if (!filter_buf) return stbi__err("outofmem", "Out of memory"); + + // Filtering for low-bit-depth images + if (depth < 8) { + filter_bytes = 1; + width = img_width_bytes; + } + + for (j=0; j < y; ++j) { + // cur/prior filter buffers alternate + stbi_uc *cur = filter_buf + (j & 1)*img_width_bytes; + stbi_uc *prior = filter_buf + (~j & 1)*img_width_bytes; + stbi_uc *dest = a->out + stride*j; + int nk = width * filter_bytes; + int filter = *raw++; + + // check filter type + if (filter > 4) { + all_ok = stbi__err("invalid filter","Corrupt PNG"); + break; + } + + // if first row, use special filter that doesn't sample previous row + if (j == 0) filter = first_row_filter[filter]; + + // perform actual filtering + switch (filter) { + case STBI__F_none: + memcpy(cur, raw, nk); + break; + case STBI__F_sub: + memcpy(cur, raw, filter_bytes); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); + break; + case STBI__F_up: + for (k = 0; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + prior[k]); + break; + case STBI__F_avg: + for (k = 0; k < filter_bytes; ++k) + cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); + break; + case STBI__F_paeth: + for (k = 0; k < filter_bytes; ++k) + cur[k] = STBI__BYTECAST(raw[k] + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0) + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes], prior[k], prior[k-filter_bytes])); + break; + case STBI__F_avg_first: + memcpy(cur, raw, filter_bytes); + for (k = filter_bytes; k < nk; ++k) + cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); + break; + } + + raw += nk; + + // expand decoded bits in cur to dest, also adding an extra alpha channel if desired + if (depth < 8) { + stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range + stbi_uc *in = cur; + stbi_uc *out = dest; + stbi_uc inb = 0; + stbi__uint32 nsmp = x*img_n; + + // expand bits to bytes first + if (depth == 4) { + for (i=0; i < nsmp; ++i) { + if ((i & 1) == 0) inb = *in++; + *out++ = scale * (inb >> 4); + inb <<= 4; + } + } else if (depth == 2) { + for (i=0; i < nsmp; ++i) { + if ((i & 3) == 0) inb = *in++; + *out++ = scale * (inb >> 6); + inb <<= 2; + } + } else { + STBI_ASSERT(depth == 1); + for (i=0; i < nsmp; ++i) { + if ((i & 7) == 0) inb = *in++; + *out++ = scale * (inb >> 7); + inb <<= 1; + } + } + + // insert alpha=255 values if desired + if (img_n != out_n) + stbi__create_png_alpha_expand8(dest, dest, x, img_n); + } else if (depth == 8) { + if (img_n == out_n) + memcpy(dest, cur, x*img_n); + else + stbi__create_png_alpha_expand8(dest, cur, x, img_n); + } else if (depth == 16) { + // convert the image data from big-endian to platform-native + stbi__uint16 *dest16 = (stbi__uint16*)dest; + stbi__uint32 nsmp = x*img_n; + + if (img_n == out_n) { + for (i = 0; i < nsmp; ++i, ++dest16, cur += 2) + *dest16 = (cur[0] << 8) | cur[1]; + } else { + STBI_ASSERT(img_n+1 == out_n); + if (img_n == 1) { + for (i = 0; i < x; ++i, dest16 += 2, cur += 2) { + dest16[0] = (cur[0] << 8) | cur[1]; + dest16[1] = 0xffff; + } + } else { + STBI_ASSERT(img_n == 3); + for (i = 0; i < x; ++i, dest16 += 4, cur += 6) { + dest16[0] = (cur[0] << 8) | cur[1]; + dest16[1] = (cur[2] << 8) | cur[3]; + dest16[2] = (cur[4] << 8) | cur[5]; + dest16[3] = 0xffff; + } + } + } + } + } + + STBI_FREE(filter_buf); + if (!all_ok) return 0; + + return 1; +} + +static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) +{ + int bytes = (depth == 16 ? 2 : 1); + int out_bytes = out_n * bytes; + stbi_uc *final; + int p; + if (!interlaced) + return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); + + // de-interlacing + final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); + if (!final) return stbi__err("outofmem", "Out of memory"); + for (p=0; p < 7; ++p) { + int xorig[] = { 0,4,0,2,0,1,0 }; + int yorig[] = { 0,0,4,0,2,0,1 }; + int xspc[] = { 8,8,4,4,2,2,1 }; + int yspc[] = { 8,8,8,4,4,2,2 }; + int i,j,x,y; + // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 + x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p]; + y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p]; + if (x && y) { + stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; + if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) { + STBI_FREE(final); + return 0; + } + for (j=0; j < y; ++j) { + for (i=0; i < x; ++i) { + int out_y = j*yspc[p]+yorig[p]; + int out_x = i*xspc[p]+xorig[p]; + memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes, + a->out + (j*x+i)*out_bytes, out_bytes); + } + } + STBI_FREE(a->out); + image_data += img_len; + image_data_len -= img_len; + } + } + a->out = final; + + return 1; +} + +static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi_uc *p = z->out; + + // compute color-based transparency, assuming we've + // already got 255 as the alpha value in the output + STBI_ASSERT(out_n == 2 || out_n == 4); + + if (out_n == 2) { + for (i=0; i < pixel_count; ++i) { + p[1] = (p[0] == tc[0] ? 0 : 255); + p += 2; + } + } else { + for (i=0; i < pixel_count; ++i) { + if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) + p[3] = 0; + p += 4; + } + } + return 1; +} + +static int stbi__compute_transparency16(stbi__png *z, stbi__uint16 tc[3], int out_n) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi__uint16 *p = (stbi__uint16*) z->out; + + // compute color-based transparency, assuming we've + // already got 65535 as the alpha value in the output + STBI_ASSERT(out_n == 2 || out_n == 4); + + if (out_n == 2) { + for (i = 0; i < pixel_count; ++i) { + p[1] = (p[0] == tc[0] ? 0 : 65535); + p += 2; + } + } else { + for (i = 0; i < pixel_count; ++i) { + if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) + p[3] = 0; + p += 4; + } + } + return 1; +} + +static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n) +{ + stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; + stbi_uc *p, *temp_out, *orig = a->out; + + p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0); + if (p == NULL) return stbi__err("outofmem", "Out of memory"); + + // between here and free(out) below, exitting would leak + temp_out = p; + + if (pal_img_n == 3) { + for (i=0; i < pixel_count; ++i) { + int n = orig[i]*4; + p[0] = palette[n ]; + p[1] = palette[n+1]; + p[2] = palette[n+2]; + p += 3; + } + } else { + for (i=0; i < pixel_count; ++i) { + int n = orig[i]*4; + p[0] = palette[n ]; + p[1] = palette[n+1]; + p[2] = palette[n+2]; + p[3] = palette[n+3]; + p += 4; + } + } + STBI_FREE(a->out); + a->out = temp_out; + + STBI_NOTUSED(len); + + return 1; +} + +static int stbi__unpremultiply_on_load_global = 0; +static int stbi__de_iphone_flag_global = 0; + +STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) +{ + stbi__unpremultiply_on_load_global = flag_true_if_should_unpremultiply; +} + +STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert) +{ + stbi__de_iphone_flag_global = flag_true_if_should_convert; +} + +#ifndef STBI_THREAD_LOCAL +#define stbi__unpremultiply_on_load stbi__unpremultiply_on_load_global +#define stbi__de_iphone_flag stbi__de_iphone_flag_global +#else +static STBI_THREAD_LOCAL int stbi__unpremultiply_on_load_local, stbi__unpremultiply_on_load_set; +static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local, stbi__de_iphone_flag_set; + +STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply) +{ + stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply; + stbi__unpremultiply_on_load_set = 1; +} + +STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert) +{ + stbi__de_iphone_flag_local = flag_true_if_should_convert; + stbi__de_iphone_flag_set = 1; +} + +#define stbi__unpremultiply_on_load (stbi__unpremultiply_on_load_set \ +? stbi__unpremultiply_on_load_local \ +: stbi__unpremultiply_on_load_global) +#define stbi__de_iphone_flag (stbi__de_iphone_flag_set \ +? stbi__de_iphone_flag_local \ +: stbi__de_iphone_flag_global) +#endif // STBI_THREAD_LOCAL + +static void stbi__de_iphone(stbi__png *z) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi_uc *p = z->out; + + if (s->img_out_n == 3) { // convert bgr to rgb + for (i=0; i < pixel_count; ++i) { + stbi_uc t = p[0]; + p[0] = p[2]; + p[2] = t; + p += 3; + } + } else { + STBI_ASSERT(s->img_out_n == 4); + if (stbi__unpremultiply_on_load) { + // convert bgr to rgb and unpremultiply + for (i=0; i < pixel_count; ++i) { + stbi_uc a = p[3]; + stbi_uc t = p[0]; + if (a) { + stbi_uc half = a / 2; + p[0] = (p[2] * 255 + half) / a; + p[1] = (p[1] * 255 + half) / a; + p[2] = ( t * 255 + half) / a; + } else { + p[0] = p[2]; + p[2] = t; + } + p += 4; + } + } else { + // convert bgr to rgb + for (i=0; i < pixel_count; ++i) { + stbi_uc t = p[0]; + p[0] = p[2]; + p[2] = t; + p += 4; + } + } + } +} + +#define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d)) + +static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) +{ + stbi_uc palette[1024], pal_img_n=0; + stbi_uc has_trans=0, tc[3]={0}; + stbi__uint16 tc16[3]; + stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0; + int first=1,k,interlace=0, color=0, is_iphone=0; + stbi__context *s = z->s; + + z->expanded = NULL; + z->idata = NULL; + z->out = NULL; + + if (!stbi__check_png_header(s)) return 0; + + if (scan == STBI__SCAN_type) return 1; + + for (;;) { + stbi__pngchunk c = stbi__get_chunk_header(s); + switch (c.type) { + case STBI__PNG_TYPE('C','g','B','I'): + is_iphone = 1; + stbi__skip(s, c.length); + break; + case STBI__PNG_TYPE('I','H','D','R'): { + int comp,filter; + if (!first) return stbi__err("multiple IHDR","Corrupt PNG"); + first = 0; + if (c.length != 13) return stbi__err("bad IHDR len","Corrupt PNG"); + s->img_x = stbi__get32be(s); + s->img_y = stbi__get32be(s); + if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return stbi__err("1/2/4/8/16-bit only","PNG not supported: 1/2/4/8/16-bit only"); + color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype","Corrupt PNG"); + if (color == 3 && z->depth == 16) return stbi__err("bad ctype","Corrupt PNG"); + if (color == 3) pal_img_n = 3; else if (color & 1) return stbi__err("bad ctype","Corrupt PNG"); + comp = stbi__get8(s); if (comp) return stbi__err("bad comp method","Corrupt PNG"); + filter= stbi__get8(s); if (filter) return stbi__err("bad filter method","Corrupt PNG"); + interlace = stbi__get8(s); if (interlace>1) return stbi__err("bad interlace method","Corrupt PNG"); + if (!s->img_x || !s->img_y) return stbi__err("0-pixel image","Corrupt PNG"); + if (!pal_img_n) { + s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); + if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode"); + } else { + // if paletted, then pal_n is our final components, and + // img_n is # components to decompress/filter. + s->img_n = 1; + if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large","Corrupt PNG"); + } + // even with SCAN_header, have to scan to see if we have a tRNS + break; + } + + case STBI__PNG_TYPE('P','L','T','E'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (c.length > 256*3) return stbi__err("invalid PLTE","Corrupt PNG"); + pal_len = c.length / 3; + if (pal_len * 3 != c.length) return stbi__err("invalid PLTE","Corrupt PNG"); + for (i=0; i < pal_len; ++i) { + palette[i*4+0] = stbi__get8(s); + palette[i*4+1] = stbi__get8(s); + palette[i*4+2] = stbi__get8(s); + palette[i*4+3] = 255; + } + break; + } + + case STBI__PNG_TYPE('t','R','N','S'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (z->idata) return stbi__err("tRNS after IDAT","Corrupt PNG"); + if (pal_img_n) { + if (scan == STBI__SCAN_header) { s->img_n = 4; return 1; } + if (pal_len == 0) return stbi__err("tRNS before PLTE","Corrupt PNG"); + if (c.length > pal_len) return stbi__err("bad tRNS len","Corrupt PNG"); + pal_img_n = 4; + for (i=0; i < c.length; ++i) + palette[i*4+3] = stbi__get8(s); + } else { + if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG"); + if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG"); + has_trans = 1; + // non-paletted with tRNS = constant alpha. if header-scanning, we can stop now. + if (scan == STBI__SCAN_header) { ++s->img_n; return 1; } + if (z->depth == 16) { + for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is + } else { + for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger + } + } + break; + } + + case STBI__PNG_TYPE('I','D','A','T'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG"); + if (scan == STBI__SCAN_header) { + // header scan definitely stops at first IDAT + if (pal_img_n) + s->img_n = pal_img_n; + return 1; + } + if (c.length > (1u << 30)) return stbi__err("IDAT size limit", "IDAT section larger than 2^30 bytes"); + if ((int)(ioff + c.length) < (int)ioff) return 0; + if (ioff + c.length > idata_limit) { + stbi__uint32 idata_limit_old = idata_limit; + stbi_uc *p; + if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; + while (ioff + c.length > idata_limit) + idata_limit *= 2; + STBI_NOTUSED(idata_limit_old); + p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); + z->idata = p; + } + if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG"); + ioff += c.length; + break; + } + + case STBI__PNG_TYPE('I','E','N','D'): { + stbi__uint32 raw_len, bpl; + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (scan != STBI__SCAN_load) return 1; + if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG"); + // initial guess for decoded data size to avoid unnecessary reallocs + bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component + raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; + z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone); + if (z->expanded == NULL) return 0; // zlib should set error + STBI_FREE(z->idata); z->idata = NULL; + if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) + s->img_out_n = s->img_n+1; + else + s->img_out_n = s->img_n; + if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; + if (has_trans) { + if (z->depth == 16) { + if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; + } else { + if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0; + } + } + if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2) + stbi__de_iphone(z); + if (pal_img_n) { + // pal_img_n == 3 or 4 + s->img_n = pal_img_n; // record the actual colors we had + s->img_out_n = pal_img_n; + if (req_comp >= 3) s->img_out_n = req_comp; + if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) + return 0; + } else if (has_trans) { + // non-paletted image with tRNS -> source image has (constant) alpha + ++s->img_n; + } + STBI_FREE(z->expanded); z->expanded = NULL; + // end of PNG chunk, read and skip CRC + stbi__get32be(s); + return 1; + } + + default: + // if critical, fail + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if ((c.type & (1 << 29)) == 0) { +#ifndef STBI_NO_FAILURE_STRINGS + // not threadsafe + static char invalid_chunk[] = "XXXX PNG chunk not known"; + invalid_chunk[0] = STBI__BYTECAST(c.type >> 24); + invalid_chunk[1] = STBI__BYTECAST(c.type >> 16); + invalid_chunk[2] = STBI__BYTECAST(c.type >> 8); + invalid_chunk[3] = STBI__BYTECAST(c.type >> 0); +#endif + return stbi__err(invalid_chunk, "PNG not supported: unknown PNG chunk type"); + } + stbi__skip(s, c.length); + break; + } + // end of PNG chunk, read and skip CRC + stbi__get32be(s); + } +} + +static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, stbi__result_info *ri) +{ + void *result=NULL; + if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); + if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { + if (p->depth <= 8) + ri->bits_per_channel = 8; + else if (p->depth == 16) + ri->bits_per_channel = 16; + else + return stbi__errpuc("bad bits_per_channel", "PNG not supported: unsupported color depth"); + result = p->out; + p->out = NULL; + if (req_comp && req_comp != p->s->img_out_n) { + if (ri->bits_per_channel == 8) + result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); + else + result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); + p->s->img_out_n = req_comp; + if (result == NULL) return result; + } + *x = p->s->img_x; + *y = p->s->img_y; + if (n) *n = p->s->img_n; + } + STBI_FREE(p->out); p->out = NULL; + STBI_FREE(p->expanded); p->expanded = NULL; + STBI_FREE(p->idata); p->idata = NULL; + + return result; +} + +static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi__png p; + p.s = s; + return stbi__do_png(&p, x,y,comp,req_comp, ri); +} + +static int stbi__png_test(stbi__context *s) +{ + int r; + r = stbi__check_png_header(s); + stbi__rewind(s); + return r; +} + +static int stbi__png_info_raw(stbi__png *p, int *x, int *y, int *comp) +{ + if (!stbi__parse_png_file(p, STBI__SCAN_header, 0)) { + stbi__rewind( p->s ); + return 0; + } + if (x) *x = p->s->img_x; + if (y) *y = p->s->img_y; + if (comp) *comp = p->s->img_n; + return 1; +} + +static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp) +{ + stbi__png p; + p.s = s; + return stbi__png_info_raw(&p, x, y, comp); +} + +static int stbi__png_is16(stbi__context *s) +{ + stbi__png p; + p.s = s; + if (!stbi__png_info_raw(&p, NULL, NULL, NULL)) + return 0; + if (p.depth != 16) { + stbi__rewind(p.s); + return 0; + } + return 1; +} +#endif + +// Microsoft/Windows BMP image + +#ifndef STBI_NO_BMP +static int stbi__bmp_test_raw(stbi__context *s) +{ + int r; + int sz; + if (stbi__get8(s) != 'B') return 0; + if (stbi__get8(s) != 'M') return 0; + stbi__get32le(s); // discard filesize + stbi__get16le(s); // discard reserved + stbi__get16le(s); // discard reserved + stbi__get32le(s); // discard data offset + sz = stbi__get32le(s); + r = (sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124); + return r; +} + +static int stbi__bmp_test(stbi__context *s) +{ + int r = stbi__bmp_test_raw(s); + stbi__rewind(s); + return r; +} + + +// returns 0..31 for the highest set bit +static int stbi__high_bit(unsigned int z) +{ + int n=0; + if (z == 0) return -1; + if (z >= 0x10000) { n += 16; z >>= 16; } + if (z >= 0x00100) { n += 8; z >>= 8; } + if (z >= 0x00010) { n += 4; z >>= 4; } + if (z >= 0x00004) { n += 2; z >>= 2; } + if (z >= 0x00002) { n += 1;/* >>= 1;*/ } + return n; +} + +static int stbi__bitcount(unsigned int a) +{ + a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 + a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4 + a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits + a = (a + (a >> 8)); // max 16 per 8 bits + a = (a + (a >> 16)); // max 32 per 8 bits + return a & 0xff; +} + +// extract an arbitrarily-aligned N-bit value (N=bits) +// from v, and then make it 8-bits long and fractionally +// extend it to full full range. +static int stbi__shiftsigned(unsigned int v, int shift, int bits) +{ + static unsigned int mul_table[9] = { + 0, + 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/, + 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/, + }; + static unsigned int shift_table[9] = { + 0, 0,0,1,0,2,4,6,0, + }; + if (shift < 0) + v <<= -shift; + else + v >>= shift; + STBI_ASSERT(v < 256); + v >>= (8-bits); + STBI_ASSERT(bits >= 0 && bits <= 8); + return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits]; +} + +typedef struct +{ + int bpp, offset, hsz; + unsigned int mr,mg,mb,ma, all_a; + int extra_read; +} stbi__bmp_data; + +static int stbi__bmp_set_mask_defaults(stbi__bmp_data *info, int compress) +{ + // BI_BITFIELDS specifies masks explicitly, don't override + if (compress == 3) + return 1; + + if (compress == 0) { + if (info->bpp == 16) { + info->mr = 31u << 10; + info->mg = 31u << 5; + info->mb = 31u << 0; + } else if (info->bpp == 32) { + info->mr = 0xffu << 16; + info->mg = 0xffu << 8; + info->mb = 0xffu << 0; + info->ma = 0xffu << 24; + info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0 + } else { + // otherwise, use defaults, which is all-0 + info->mr = info->mg = info->mb = info->ma = 0; + } + return 1; + } + return 0; // error +} + +static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info) +{ + int hsz; + if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP"); + stbi__get32le(s); // discard filesize + stbi__get16le(s); // discard reserved + stbi__get16le(s); // discard reserved + info->offset = stbi__get32le(s); + info->hsz = hsz = stbi__get32le(s); + info->mr = info->mg = info->mb = info->ma = 0; + info->extra_read = 14; + + if (info->offset < 0) return stbi__errpuc("bad BMP", "bad BMP"); + + if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown"); + if (hsz == 12) { + s->img_x = stbi__get16le(s); + s->img_y = stbi__get16le(s); + } else { + s->img_x = stbi__get32le(s); + s->img_y = stbi__get32le(s); + } + if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP"); + info->bpp = stbi__get16le(s); + if (hsz != 12) { + int compress = stbi__get32le(s); + if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE"); + if (compress >= 4) return stbi__errpuc("BMP JPEG/PNG", "BMP type not supported: unsupported compression"); // this includes PNG/JPEG modes + if (compress == 3 && info->bpp != 16 && info->bpp != 32) return stbi__errpuc("bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel + stbi__get32le(s); // discard sizeof + stbi__get32le(s); // discard hres + stbi__get32le(s); // discard vres + stbi__get32le(s); // discard colorsused + stbi__get32le(s); // discard max important + if (hsz == 40 || hsz == 56) { + if (hsz == 56) { + stbi__get32le(s); + stbi__get32le(s); + stbi__get32le(s); + stbi__get32le(s); + } + if (info->bpp == 16 || info->bpp == 32) { + if (compress == 0) { + stbi__bmp_set_mask_defaults(info, compress); + } else if (compress == 3) { + info->mr = stbi__get32le(s); + info->mg = stbi__get32le(s); + info->mb = stbi__get32le(s); + info->extra_read += 12; + // not documented, but generated by photoshop and handled by mspaint + if (info->mr == info->mg && info->mg == info->mb) { + // ?!?!? + return stbi__errpuc("bad BMP", "bad BMP"); + } + } else + return stbi__errpuc("bad BMP", "bad BMP"); + } + } else { + // V4/V5 header + int i; + if (hsz != 108 && hsz != 124) + return stbi__errpuc("bad BMP", "bad BMP"); + info->mr = stbi__get32le(s); + info->mg = stbi__get32le(s); + info->mb = stbi__get32le(s); + info->ma = stbi__get32le(s); + if (compress != 3) // override mr/mg/mb unless in BI_BITFIELDS mode, as per docs + stbi__bmp_set_mask_defaults(info, compress); + stbi__get32le(s); // discard color space + for (i=0; i < 12; ++i) + stbi__get32le(s); // discard color space parameters + if (hsz == 124) { + stbi__get32le(s); // discard rendering intent + stbi__get32le(s); // discard offset of profile data + stbi__get32le(s); // discard size of profile data + stbi__get32le(s); // discard reserved + } + } + } + return (void *) 1; +} + + +static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *out; + unsigned int mr=0,mg=0,mb=0,ma=0, all_a; + stbi_uc pal[256][4]; + int psize=0,i,j,width; + int flip_vertically, pad, target; + stbi__bmp_data info; + STBI_NOTUSED(ri); + + info.all_a = 255; + if (stbi__bmp_parse_header(s, &info) == NULL) + return NULL; // error code already set + + flip_vertically = ((int) s->img_y) > 0; + s->img_y = abs((int) s->img_y); + + if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + + mr = info.mr; + mg = info.mg; + mb = info.mb; + ma = info.ma; + all_a = info.all_a; + + if (info.hsz == 12) { + if (info.bpp < 24) + psize = (info.offset - info.extra_read - 24) / 3; + } else { + if (info.bpp < 16) + psize = (info.offset - info.extra_read - info.hsz) >> 2; + } + if (psize == 0) { + // accept some number of extra bytes after the header, but if the offset points either to before + // the header ends or implies a large amount of extra data, reject the file as malformed + int bytes_read_so_far = s->callback_already_read + (int)(s->img_buffer - s->img_buffer_original); + int header_limit = 1024; // max we actually read is below 256 bytes currently. + int extra_data_limit = 256*4; // what ordinarily goes here is a palette; 256 entries*4 bytes is its max size. + if (bytes_read_so_far <= 0 || bytes_read_so_far > header_limit) { + return stbi__errpuc("bad header", "Corrupt BMP"); + } + // we established that bytes_read_so_far is positive and sensible. + // the first half of this test rejects offsets that are either too small positives, or + // negative, and guarantees that info.offset >= bytes_read_so_far > 0. this in turn + // ensures the number computed in the second half of the test can't overflow. + if (info.offset < bytes_read_so_far || info.offset - bytes_read_so_far > extra_data_limit) { + return stbi__errpuc("bad offset", "Corrupt BMP"); + } else { + stbi__skip(s, info.offset - bytes_read_so_far); + } + } + + if (info.bpp == 24 && ma == 0xff000000) + s->img_n = 3; + else + s->img_n = ma ? 4 : 3; + if (req_comp && req_comp >= 3) // we can directly decode 3 or 4 + target = req_comp; + else + target = s->img_n; // if they want monochrome, we'll post-convert + + // sanity-check size + if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0)) + return stbi__errpuc("too large", "Corrupt BMP"); + + out = (stbi_uc *) stbi__malloc_mad3(target, s->img_x, s->img_y, 0); + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + if (info.bpp < 16) { + int z=0; + if (psize == 0 || psize > 256) { STBI_FREE(out); return stbi__errpuc("invalid", "Corrupt BMP"); } + for (i=0; i < psize; ++i) { + pal[i][2] = stbi__get8(s); + pal[i][1] = stbi__get8(s); + pal[i][0] = stbi__get8(s); + if (info.hsz != 12) stbi__get8(s); + pal[i][3] = 255; + } + stbi__skip(s, info.offset - info.extra_read - info.hsz - psize * (info.hsz == 12 ? 3 : 4)); + if (info.bpp == 1) width = (s->img_x + 7) >> 3; + else if (info.bpp == 4) width = (s->img_x + 1) >> 1; + else if (info.bpp == 8) width = s->img_x; + else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); } + pad = (-width)&3; + if (info.bpp == 1) { + for (j=0; j < (int) s->img_y; ++j) { + int bit_offset = 7, v = stbi__get8(s); + for (i=0; i < (int) s->img_x; ++i) { + int color = (v>>bit_offset)&0x1; + out[z++] = pal[color][0]; + out[z++] = pal[color][1]; + out[z++] = pal[color][2]; + if (target == 4) out[z++] = 255; + if (i+1 == (int) s->img_x) break; + if((--bit_offset) < 0) { + bit_offset = 7; + v = stbi__get8(s); + } + } + stbi__skip(s, pad); + } + } else { + for (j=0; j < (int) s->img_y; ++j) { + for (i=0; i < (int) s->img_x; i += 2) { + int v=stbi__get8(s),v2=0; + if (info.bpp == 4) { + v2 = v & 15; + v >>= 4; + } + out[z++] = pal[v][0]; + out[z++] = pal[v][1]; + out[z++] = pal[v][2]; + if (target == 4) out[z++] = 255; + if (i+1 == (int) s->img_x) break; + v = (info.bpp == 8) ? stbi__get8(s) : v2; + out[z++] = pal[v][0]; + out[z++] = pal[v][1]; + out[z++] = pal[v][2]; + if (target == 4) out[z++] = 255; + } + stbi__skip(s, pad); + } + } + } else { + int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0; + int z = 0; + int easy=0; + stbi__skip(s, info.offset - info.extra_read - info.hsz); + if (info.bpp == 24) width = 3 * s->img_x; + else if (info.bpp == 16) width = 2*s->img_x; + else /* bpp = 32 and pad = 0 */ width=0; + pad = (-width) & 3; + if (info.bpp == 24) { + easy = 1; + } else if (info.bpp == 32) { + if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000) + easy = 2; + } + if (!easy) { + if (!mr || !mg || !mb) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } + // right shift amt to put high bit in position #7 + rshift = stbi__high_bit(mr)-7; rcount = stbi__bitcount(mr); + gshift = stbi__high_bit(mg)-7; gcount = stbi__bitcount(mg); + bshift = stbi__high_bit(mb)-7; bcount = stbi__bitcount(mb); + ashift = stbi__high_bit(ma)-7; acount = stbi__bitcount(ma); + if (rcount > 8 || gcount > 8 || bcount > 8 || acount > 8) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } + } + for (j=0; j < (int) s->img_y; ++j) { + if (easy) { + for (i=0; i < (int) s->img_x; ++i) { + unsigned char a; + out[z+2] = stbi__get8(s); + out[z+1] = stbi__get8(s); + out[z+0] = stbi__get8(s); + z += 3; + a = (easy == 2 ? stbi__get8(s) : 255); + all_a |= a; + if (target == 4) out[z++] = a; + } + } else { + int bpp = info.bpp; + for (i=0; i < (int) s->img_x; ++i) { + stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s)); + unsigned int a; + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount)); + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount)); + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount)); + a = (ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255); + all_a |= a; + if (target == 4) out[z++] = STBI__BYTECAST(a); + } + } + stbi__skip(s, pad); + } + } + + // if alpha channel is all 0s, replace with all 255s + if (target == 4 && all_a == 0) + for (i=4*s->img_x*s->img_y-1; i >= 0; i -= 4) + out[i] = 255; + + if (flip_vertically) { + stbi_uc t; + for (j=0; j < (int) s->img_y>>1; ++j) { + stbi_uc *p1 = out + j *s->img_x*target; + stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target; + for (i=0; i < (int) s->img_x*target; ++i) { + t = p1[i]; p1[i] = p2[i]; p2[i] = t; + } + } + } + + if (req_comp && req_comp != target) { + out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y); + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + + *x = s->img_x; + *y = s->img_y; + if (comp) *comp = s->img_n; + return out; +} +#endif + +// Targa Truevision - TGA +// by Jonathan Dummer +#ifndef STBI_NO_TGA +// returns STBI_rgb or whatever, 0 on error +static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int* is_rgb16) +{ + // only RGB or RGBA (incl. 16bit) or grey allowed + if (is_rgb16) *is_rgb16 = 0; + switch(bits_per_pixel) { + case 8: return STBI_grey; + case 16: if(is_grey) return STBI_grey_alpha; + // fallthrough + case 15: if(is_rgb16) *is_rgb16 = 1; + return STBI_rgb; + case 24: // fallthrough + case 32: return bits_per_pixel/8; + default: return 0; + } +} + +static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp) +{ + int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp; + int sz, tga_colormap_type; + stbi__get8(s); // discard Offset + tga_colormap_type = stbi__get8(s); // colormap type + if( tga_colormap_type > 1 ) { + stbi__rewind(s); + return 0; // only RGB or indexed allowed + } + tga_image_type = stbi__get8(s); // image type + if ( tga_colormap_type == 1 ) { // colormapped (paletted) image + if (tga_image_type != 1 && tga_image_type != 9) { + stbi__rewind(s); + return 0; + } + stbi__skip(s,4); // skip index of first colormap entry and number of entries + sz = stbi__get8(s); // check bits per palette color entry + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) { + stbi__rewind(s); + return 0; + } + stbi__skip(s,4); // skip image x and y origin + tga_colormap_bpp = sz; + } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE + if ( (tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11) ) { + stbi__rewind(s); + return 0; // only RGB or grey allowed, +/- RLE + } + stbi__skip(s,9); // skip colormap specification and image x/y origin + tga_colormap_bpp = 0; + } + tga_w = stbi__get16le(s); + if( tga_w < 1 ) { + stbi__rewind(s); + return 0; // test width + } + tga_h = stbi__get16le(s); + if( tga_h < 1 ) { + stbi__rewind(s); + return 0; // test height + } + tga_bits_per_pixel = stbi__get8(s); // bits per pixel + stbi__get8(s); // ignore alpha bits + if (tga_colormap_bpp != 0) { + if((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) { + // when using a colormap, tga_bits_per_pixel is the size of the indexes + // I don't think anything but 8 or 16bit indexes makes sense + stbi__rewind(s); + return 0; + } + tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL); + } else { + tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL); + } + if(!tga_comp) { + stbi__rewind(s); + return 0; + } + if (x) *x = tga_w; + if (y) *y = tga_h; + if (comp) *comp = tga_comp; + return 1; // seems to have passed everything +} + +static int stbi__tga_test(stbi__context *s) +{ + int res = 0; + int sz, tga_color_type; + stbi__get8(s); // discard Offset + tga_color_type = stbi__get8(s); // color type + if ( tga_color_type > 1 ) goto errorEnd; // only RGB or indexed allowed + sz = stbi__get8(s); // image type + if ( tga_color_type == 1 ) { // colormapped (paletted) image + if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9 + stbi__skip(s,4); // skip index of first colormap entry and number of entries + sz = stbi__get8(s); // check bits per palette color entry + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; + stbi__skip(s,4); // skip image x and y origin + } else { // "normal" image w/o colormap + if ( (sz != 2) && (sz != 3) && (sz != 10) && (sz != 11) ) goto errorEnd; // only RGB or grey allowed, +/- RLE + stbi__skip(s,9); // skip colormap specification and image x/y origin + } + if ( stbi__get16le(s) < 1 ) goto errorEnd; // test width + if ( stbi__get16le(s) < 1 ) goto errorEnd; // test height + sz = stbi__get8(s); // bits per pixel + if ( (tga_color_type == 1) && (sz != 8) && (sz != 16) ) goto errorEnd; // for colormapped images, bpp is size of an index + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; + + res = 1; // if we got this far, everything's good and we can return 1 instead of 0 + + errorEnd: + stbi__rewind(s); + return res; +} + +// read 16bit value and convert to 24bit RGB +static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) +{ + stbi__uint16 px = (stbi__uint16)stbi__get16le(s); + stbi__uint16 fiveBitMask = 31; + // we have 3 channels with 5bits each + int r = (px >> 10) & fiveBitMask; + int g = (px >> 5) & fiveBitMask; + int b = px & fiveBitMask; + // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later + out[0] = (stbi_uc)((r * 255)/31); + out[1] = (stbi_uc)((g * 255)/31); + out[2] = (stbi_uc)((b * 255)/31); + + // some people claim that the most significant bit might be used for alpha + // (possibly if an alpha-bit is set in the "image descriptor byte") + // but that only made 16bit test images completely translucent.. + // so let's treat all 15 and 16bit TGAs as RGB with no alpha. +} + +static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + // read in the TGA header stuff + int tga_offset = stbi__get8(s); + int tga_indexed = stbi__get8(s); + int tga_image_type = stbi__get8(s); + int tga_is_RLE = 0; + int tga_palette_start = stbi__get16le(s); + int tga_palette_len = stbi__get16le(s); + int tga_palette_bits = stbi__get8(s); + int tga_x_origin = stbi__get16le(s); + int tga_y_origin = stbi__get16le(s); + int tga_width = stbi__get16le(s); + int tga_height = stbi__get16le(s); + int tga_bits_per_pixel = stbi__get8(s); + int tga_comp, tga_rgb16=0; + int tga_inverted = stbi__get8(s); + // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?) + // image data + unsigned char *tga_data; + unsigned char *tga_palette = NULL; + int i, j; + unsigned char raw_data[4] = {0}; + int RLE_count = 0; + int RLE_repeating = 0; + int read_next_pixel = 1; + STBI_NOTUSED(ri); + STBI_NOTUSED(tga_x_origin); // @TODO + STBI_NOTUSED(tga_y_origin); // @TODO + + if (tga_height > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + if (tga_width > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + + // do a tiny bit of precessing + if ( tga_image_type >= 8 ) + { + tga_image_type -= 8; + tga_is_RLE = 1; + } + tga_inverted = 1 - ((tga_inverted >> 5) & 1); + + // If I'm paletted, then I'll use the number of bits from the palette + if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); + else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16); + + if(!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency + return stbi__errpuc("bad format", "Can't find out TGA pixelformat"); + + // tga info + *x = tga_width; + *y = tga_height; + if (comp) *comp = tga_comp; + + if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0)) + return stbi__errpuc("too large", "Corrupt TGA"); + + tga_data = (unsigned char*)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0); + if (!tga_data) return stbi__errpuc("outofmem", "Out of memory"); + + // skip to the data's starting position (offset usually = 0) + stbi__skip(s, tga_offset ); + + if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) { + for (i=0; i < tga_height; ++i) { + int row = tga_inverted ? tga_height -i - 1 : i; + stbi_uc *tga_row = tga_data + row*tga_width*tga_comp; + stbi__getn(s, tga_row, tga_width * tga_comp); + } + } else { + // do I need to load a palette? + if ( tga_indexed) + { + if (tga_palette_len == 0) { /* you have to have at least one entry! */ + STBI_FREE(tga_data); + return stbi__errpuc("bad palette", "Corrupt TGA"); + } + + // any data to skip? (offset usually = 0) + stbi__skip(s, tga_palette_start ); + // load the palette + tga_palette = (unsigned char*)stbi__malloc_mad2(tga_palette_len, tga_comp, 0); + if (!tga_palette) { + STBI_FREE(tga_data); + return stbi__errpuc("outofmem", "Out of memory"); + } + if (tga_rgb16) { + stbi_uc *pal_entry = tga_palette; + STBI_ASSERT(tga_comp == STBI_rgb); + for (i=0; i < tga_palette_len; ++i) { + stbi__tga_read_rgb16(s, pal_entry); + pal_entry += tga_comp; + } + } else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp)) { + STBI_FREE(tga_data); + STBI_FREE(tga_palette); + return stbi__errpuc("bad palette", "Corrupt TGA"); + } + } + // load the data + for (i=0; i < tga_width * tga_height; ++i) + { + // if I'm in RLE mode, do I need to get a RLE stbi__pngchunk? + if ( tga_is_RLE ) + { + if ( RLE_count == 0 ) + { + // yep, get the next byte as a RLE command + int RLE_cmd = stbi__get8(s); + RLE_count = 1 + (RLE_cmd & 127); + RLE_repeating = RLE_cmd >> 7; + read_next_pixel = 1; + } else if ( !RLE_repeating ) + { + read_next_pixel = 1; + } + } else + { + read_next_pixel = 1; + } + // OK, if I need to read a pixel, do it now + if ( read_next_pixel ) + { + // load however much data we did have + if ( tga_indexed ) + { + // read in index, then perform the lookup + int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s); + if ( pal_idx >= tga_palette_len ) { + // invalid index + pal_idx = 0; + } + pal_idx *= tga_comp; + for (j = 0; j < tga_comp; ++j) { + raw_data[j] = tga_palette[pal_idx+j]; + } + } else if(tga_rgb16) { + STBI_ASSERT(tga_comp == STBI_rgb); + stbi__tga_read_rgb16(s, raw_data); + } else { + // read in the data raw + for (j = 0; j < tga_comp; ++j) { + raw_data[j] = stbi__get8(s); + } + } + // clear the reading flag for the next pixel + read_next_pixel = 0; + } // end of reading a pixel + + // copy data + for (j = 0; j < tga_comp; ++j) + tga_data[i*tga_comp+j] = raw_data[j]; + + // in case we're in RLE mode, keep counting down + --RLE_count; + } + // do I need to invert the image? + if ( tga_inverted ) + { + for (j = 0; j*2 < tga_height; ++j) + { + int index1 = j * tga_width * tga_comp; + int index2 = (tga_height - 1 - j) * tga_width * tga_comp; + for (i = tga_width * tga_comp; i > 0; --i) + { + unsigned char temp = tga_data[index1]; + tga_data[index1] = tga_data[index2]; + tga_data[index2] = temp; + ++index1; + ++index2; + } + } + } + // clear my palette, if I had one + if ( tga_palette != NULL ) + { + STBI_FREE( tga_palette ); + } + } + + // swap RGB - if the source data was RGB16, it already is in the right order + if (tga_comp >= 3 && !tga_rgb16) + { + unsigned char* tga_pixel = tga_data; + for (i=0; i < tga_width * tga_height; ++i) + { + unsigned char temp = tga_pixel[0]; + tga_pixel[0] = tga_pixel[2]; + tga_pixel[2] = temp; + tga_pixel += tga_comp; + } + } + + // convert to target component count + if (req_comp && req_comp != tga_comp) + tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height); + + // the things I do to get rid of an error message, and yet keep + // Microsoft's C compilers happy... [8^( + tga_palette_start = tga_palette_len = tga_palette_bits = + tga_x_origin = tga_y_origin = 0; + STBI_NOTUSED(tga_palette_start); + // OK, done + return tga_data; +} +#endif + +// ************************************************************************************************* +// Photoshop PSD loader -- PD by Thatcher Ulrich, integration by Nicolas Schulz, tweaked by STB + +#ifndef STBI_NO_PSD +static int stbi__psd_test(stbi__context *s) +{ + int r = (stbi__get32be(s) == 0x38425053); + stbi__rewind(s); + return r; +} + +static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) +{ + int count, nleft, len; + + count = 0; + while ((nleft = pixelCount - count) > 0) { + len = stbi__get8(s); + if (len == 128) { + // No-op. + } else if (len < 128) { + // Copy next len+1 bytes literally. + len++; + if (len > nleft) return 0; // corrupt data + count += len; + while (len) { + *p = stbi__get8(s); + p += 4; + len--; + } + } else if (len > 128) { + stbi_uc val; + // Next -len+1 bytes in the dest are replicated from next source byte. + // (Interpret len as a negative 8-bit int.) + len = 257 - len; + if (len > nleft) return 0; // corrupt data + val = stbi__get8(s); + count += len; + while (len) { + *p = val; + p += 4; + len--; + } + } + } + + return 1; +} + +static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) +{ + int pixelCount; + int channelCount, compression; + int channel, i; + int bitdepth; + int w,h; + stbi_uc *out; + STBI_NOTUSED(ri); + + // Check identifier + if (stbi__get32be(s) != 0x38425053) // "8BPS" + return stbi__errpuc("not PSD", "Corrupt PSD image"); + + // Check file type version. + if (stbi__get16be(s) != 1) + return stbi__errpuc("wrong version", "Unsupported version of PSD image"); + + // Skip 6 reserved bytes. + stbi__skip(s, 6 ); + + // Read the number of channels (R, G, B, A, etc). + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) + return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image"); + + // Read the rows and columns of the image. + h = stbi__get32be(s); + w = stbi__get32be(s); + + if (h > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + if (w > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + + // Make sure the depth is 8 bits. + bitdepth = stbi__get16be(s); + if (bitdepth != 8 && bitdepth != 16) + return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit"); + + // Make sure the color mode is RGB. + // Valid options are: + // 0: Bitmap + // 1: Grayscale + // 2: Indexed color + // 3: RGB color + // 4: CMYK color + // 7: Multichannel + // 8: Duotone + // 9: Lab color + if (stbi__get16be(s) != 3) + return stbi__errpuc("wrong color format", "PSD is not in RGB color format"); + + // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.) + stbi__skip(s,stbi__get32be(s) ); + + // Skip the image resources. (resolution, pen tool paths, etc) + stbi__skip(s, stbi__get32be(s) ); + + // Skip the reserved data. + stbi__skip(s, stbi__get32be(s) ); + + // Find out if the data is compressed. + // Known values: + // 0: no compression + // 1: RLE compressed + compression = stbi__get16be(s); + if (compression > 1) + return stbi__errpuc("bad compression", "PSD has an unknown compression format"); + + // Check size + if (!stbi__mad3sizes_valid(4, w, h, 0)) + return stbi__errpuc("too large", "Corrupt PSD"); + + // Create the destination image. + + if (!compression && bitdepth == 16 && bpc == 16) { + out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0); + ri->bits_per_channel = 16; + } else + out = (stbi_uc *) stbi__malloc(4 * w*h); + + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + pixelCount = w*h; + + // Initialize the data to zero. + //memset( out, 0, pixelCount * 4 ); + + // Finally, the image data. + if (compression) { + // RLE as used by .PSD and .TIFF + // Loop until you get the number of unpacked bytes you are expecting: + // Read the next source byte into n. + // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally. + // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times. + // Else if n is 128, noop. + // Endloop + + // The RLE-compressed data is preceded by a 2-byte data count for each row in the data, + // which we're going to just skip. + stbi__skip(s, h * channelCount * 2 ); + + // Read the RLE data by channel. + for (channel = 0; channel < 4; channel++) { + stbi_uc *p; + + p = out+channel; + if (channel >= channelCount) { + // Fill this channel with default data. + for (i = 0; i < pixelCount; i++, p += 4) + *p = (channel == 3 ? 255 : 0); + } else { + // Read the RLE data. + if (!stbi__psd_decode_rle(s, p, pixelCount)) { + STBI_FREE(out); + return stbi__errpuc("corrupt", "bad RLE data"); + } + } + } + + } else { + // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...) + // where each channel consists of an 8-bit (or 16-bit) value for each pixel in the image. + + // Read the data by channel. + for (channel = 0; channel < 4; channel++) { + if (channel >= channelCount) { + // Fill this channel with default data. + if (bitdepth == 16 && bpc == 16) { + stbi__uint16 *q = ((stbi__uint16 *) out) + channel; + stbi__uint16 val = channel == 3 ? 65535 : 0; + for (i = 0; i < pixelCount; i++, q += 4) + *q = val; + } else { + stbi_uc *p = out+channel; + stbi_uc val = channel == 3 ? 255 : 0; + for (i = 0; i < pixelCount; i++, p += 4) + *p = val; + } + } else { + if (ri->bits_per_channel == 16) { // output bpc + stbi__uint16 *q = ((stbi__uint16 *) out) + channel; + for (i = 0; i < pixelCount; i++, q += 4) + *q = (stbi__uint16) stbi__get16be(s); + } else { + stbi_uc *p = out+channel; + if (bitdepth == 16) { // input bpc + for (i = 0; i < pixelCount; i++, p += 4) + *p = (stbi_uc) (stbi__get16be(s) >> 8); + } else { + for (i = 0; i < pixelCount; i++, p += 4) + *p = stbi__get8(s); + } + } + } + } + } + + // remove weird white matte from PSD + if (channelCount >= 4) { + if (ri->bits_per_channel == 16) { + for (i=0; i < w*h; ++i) { + stbi__uint16 *pixel = (stbi__uint16 *) out + 4*i; + if (pixel[3] != 0 && pixel[3] != 65535) { + float a = pixel[3] / 65535.0f; + float ra = 1.0f / a; + float inv_a = 65535.0f * (1 - ra); + pixel[0] = (stbi__uint16) (pixel[0]*ra + inv_a); + pixel[1] = (stbi__uint16) (pixel[1]*ra + inv_a); + pixel[2] = (stbi__uint16) (pixel[2]*ra + inv_a); + } + } + } else { + for (i=0; i < w*h; ++i) { + unsigned char *pixel = out + 4*i; + if (pixel[3] != 0 && pixel[3] != 255) { + float a = pixel[3] / 255.0f; + float ra = 1.0f / a; + float inv_a = 255.0f * (1 - ra); + pixel[0] = (unsigned char) (pixel[0]*ra + inv_a); + pixel[1] = (unsigned char) (pixel[1]*ra + inv_a); + pixel[2] = (unsigned char) (pixel[2]*ra + inv_a); + } + } + } + } + + // convert to desired output format + if (req_comp && req_comp != 4) { + if (ri->bits_per_channel == 16) + out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h); + else + out = stbi__convert_format(out, 4, req_comp, w, h); + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + + if (comp) *comp = 4; + *y = h; + *x = w; + + return out; +} +#endif + +// ************************************************************************************************* +// Softimage PIC loader +// by Tom Seddon +// +// See http://softimage.wiki.softimage.com/index.php/INFO:_PIC_file_format +// See http://ozviz.wasp.uwa.edu.au/~pbourke/dataformats/softimagepic/ + +#ifndef STBI_NO_PIC +static int stbi__pic_is4(stbi__context *s,const char *str) +{ + int i; + for (i=0; i<4; ++i) + if (stbi__get8(s) != (stbi_uc)str[i]) + return 0; + + return 1; +} + +static int stbi__pic_test_core(stbi__context *s) +{ + int i; + + if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) + return 0; + + for(i=0;i<84;++i) + stbi__get8(s); + + if (!stbi__pic_is4(s,"PICT")) + return 0; + + return 1; +} + +typedef struct +{ + stbi_uc size,type,channel; +} stbi__pic_packet; + +static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest) +{ + int mask=0x80, i; + + for (i=0; i<4; ++i, mask>>=1) { + if (channel & mask) { + if (stbi__at_eof(s)) return stbi__errpuc("bad file","PIC file too short"); + dest[i]=stbi__get8(s); + } + } + + return dest; +} + +static void stbi__copyval(int channel,stbi_uc *dest,const stbi_uc *src) +{ + int mask=0x80,i; + + for (i=0;i<4; ++i, mask>>=1) + if (channel&mask) + dest[i]=src[i]; +} + +static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result) +{ + int act_comp=0,num_packets=0,y,chained; + stbi__pic_packet packets[10]; + + // this will (should...) cater for even some bizarre stuff like having data + // for the same channel in multiple packets. + do { + stbi__pic_packet *packet; + + if (num_packets==sizeof(packets)/sizeof(packets[0])) + return stbi__errpuc("bad format","too many packets"); + + packet = &packets[num_packets++]; + + chained = stbi__get8(s); + packet->size = stbi__get8(s); + packet->type = stbi__get8(s); + packet->channel = stbi__get8(s); + + act_comp |= packet->channel; + + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (reading packets)"); + if (packet->size != 8) return stbi__errpuc("bad format","packet isn't 8bpp"); + } while (chained); + + *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel? + + for(y=0; ytype) { + default: + return stbi__errpuc("bad format","packet has bad compression type"); + + case 0: {//uncompressed + int x; + + for(x=0;xchannel,dest)) + return 0; + break; + } + + case 1://Pure RLE + { + int left=width, i; + + while (left>0) { + stbi_uc count,value[4]; + + count=stbi__get8(s); + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pure read count)"); + + if (count > left) + count = (stbi_uc) left; + + if (!stbi__readval(s,packet->channel,value)) return 0; + + for(i=0; ichannel,dest,value); + left -= count; + } + } + break; + + case 2: {//Mixed RLE + int left=width; + while (left>0) { + int count = stbi__get8(s), i; + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (mixed read count)"); + + if (count >= 128) { // Repeated + stbi_uc value[4]; + + if (count==128) + count = stbi__get16be(s); + else + count -= 127; + if (count > left) + return stbi__errpuc("bad file","scanline overrun"); + + if (!stbi__readval(s,packet->channel,value)) + return 0; + + for(i=0;ichannel,dest,value); + } else { // Raw + ++count; + if (count>left) return stbi__errpuc("bad file","scanline overrun"); + + for(i=0;ichannel,dest)) + return 0; + } + left-=count; + } + break; + } + } + } + } + + return result; +} + +static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri) +{ + stbi_uc *result; + int i, x,y, internal_comp; + STBI_NOTUSED(ri); + + if (!comp) comp = &internal_comp; + + for (i=0; i<92; ++i) + stbi__get8(s); + + x = stbi__get16be(s); + y = stbi__get16be(s); + + if (y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + if (x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pic header)"); + if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode"); + + stbi__get32be(s); //skip `ratio' + stbi__get16be(s); //skip `fields' + stbi__get16be(s); //skip `pad' + + // intermediate buffer is RGBA + result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0); + if (!result) return stbi__errpuc("outofmem", "Out of memory"); + memset(result, 0xff, x*y*4); + + if (!stbi__pic_load_core(s,x,y,comp, result)) { + STBI_FREE(result); + result=0; + } + *px = x; + *py = y; + if (req_comp == 0) req_comp = *comp; + result=stbi__convert_format(result,4,req_comp,x,y); + + return result; +} + +static int stbi__pic_test(stbi__context *s) +{ + int r = stbi__pic_test_core(s); + stbi__rewind(s); + return r; +} +#endif + +// ************************************************************************************************* +// GIF loader -- public domain by Jean-Marc Lienher -- simplified/shrunk by stb + +#ifndef STBI_NO_GIF +typedef struct +{ + stbi__int16 prefix; + stbi_uc first; + stbi_uc suffix; +} stbi__gif_lzw; + +typedef struct +{ + int w,h; + stbi_uc *out; // output buffer (always 4 components) + stbi_uc *background; // The current "background" as far as a gif is concerned + stbi_uc *history; + int flags, bgindex, ratio, transparent, eflags; + stbi_uc pal[256][4]; + stbi_uc lpal[256][4]; + stbi__gif_lzw codes[8192]; + stbi_uc *color_table; + int parse, step; + int lflags; + int start_x, start_y; + int max_x, max_y; + int cur_x, cur_y; + int line_size; + int delay; +} stbi__gif; + +static int stbi__gif_test_raw(stbi__context *s) +{ + int sz; + if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0; + sz = stbi__get8(s); + if (sz != '9' && sz != '7') return 0; + if (stbi__get8(s) != 'a') return 0; + return 1; +} + +static int stbi__gif_test(stbi__context *s) +{ + int r = stbi__gif_test_raw(s); + stbi__rewind(s); + return r; +} + +static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp) +{ + int i; + for (i=0; i < num_entries; ++i) { + pal[i][2] = stbi__get8(s); + pal[i][1] = stbi__get8(s); + pal[i][0] = stbi__get8(s); + pal[i][3] = transp == i ? 0 : 255; + } +} + +static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info) +{ + stbi_uc version; + if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') + return stbi__err("not GIF", "Corrupt GIF"); + + version = stbi__get8(s); + if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF"); + if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF"); + + stbi__g_failure_reason = ""; + g->w = stbi__get16le(s); + g->h = stbi__get16le(s); + g->flags = stbi__get8(s); + g->bgindex = stbi__get8(s); + g->ratio = stbi__get8(s); + g->transparent = -1; + + if (g->w > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + if (g->h > STBI_MAX_DIMENSIONS) return stbi__err("too large","Very large image (corrupt?)"); + + if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments + + if (is_info) return 1; + + if (g->flags & 0x80) + stbi__gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1); + + return 1; +} + +static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp) +{ + stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif)); + if (!g) return stbi__err("outofmem", "Out of memory"); + if (!stbi__gif_header(s, g, comp, 1)) { + STBI_FREE(g); + stbi__rewind( s ); + return 0; + } + if (x) *x = g->w; + if (y) *y = g->h; + STBI_FREE(g); + return 1; +} + +static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) +{ + stbi_uc *p, *c; + int idx; + + // recurse to decode the prefixes, since the linked-list is backwards, + // and working backwards through an interleaved image would be nasty + if (g->codes[code].prefix >= 0) + stbi__out_gif_code(g, g->codes[code].prefix); + + if (g->cur_y >= g->max_y) return; + + idx = g->cur_x + g->cur_y; + p = &g->out[idx]; + g->history[idx / 4] = 1; + + c = &g->color_table[g->codes[code].suffix * 4]; + if (c[3] > 128) { // don't render transparent pixels; + p[0] = c[2]; + p[1] = c[1]; + p[2] = c[0]; + p[3] = c[3]; + } + g->cur_x += 4; + + if (g->cur_x >= g->max_x) { + g->cur_x = g->start_x; + g->cur_y += g->step; + + while (g->cur_y >= g->max_y && g->parse > 0) { + g->step = (1 << g->parse) * g->line_size; + g->cur_y = g->start_y + (g->step >> 1); + --g->parse; + } + } +} + +static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) +{ + stbi_uc lzw_cs; + stbi__int32 len, init_code; + stbi__uint32 first; + stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear; + stbi__gif_lzw *p; + + lzw_cs = stbi__get8(s); + if (lzw_cs > 12) return NULL; + clear = 1 << lzw_cs; + first = 1; + codesize = lzw_cs + 1; + codemask = (1 << codesize) - 1; + bits = 0; + valid_bits = 0; + for (init_code = 0; init_code < clear; init_code++) { + g->codes[init_code].prefix = -1; + g->codes[init_code].first = (stbi_uc) init_code; + g->codes[init_code].suffix = (stbi_uc) init_code; + } + + // support no starting clear code + avail = clear+2; + oldcode = -1; + + len = 0; + for(;;) { + if (valid_bits < codesize) { + if (len == 0) { + len = stbi__get8(s); // start new block + if (len == 0) + return g->out; + } + --len; + bits |= (stbi__int32) stbi__get8(s) << valid_bits; + valid_bits += 8; + } else { + stbi__int32 code = bits & codemask; + bits >>= codesize; + valid_bits -= codesize; + // @OPTIMIZE: is there some way we can accelerate the non-clear path? + if (code == clear) { // clear code + codesize = lzw_cs + 1; + codemask = (1 << codesize) - 1; + avail = clear + 2; + oldcode = -1; + first = 0; + } else if (code == clear + 1) { // end of stream code + stbi__skip(s, len); + while ((len = stbi__get8(s)) > 0) + stbi__skip(s,len); + return g->out; + } else if (code <= avail) { + if (first) { + return stbi__errpuc("no clear code", "Corrupt GIF"); + } + + if (oldcode >= 0) { + p = &g->codes[avail++]; + if (avail > 8192) { + return stbi__errpuc("too many codes", "Corrupt GIF"); + } + + p->prefix = (stbi__int16) oldcode; + p->first = g->codes[oldcode].first; + p->suffix = (code == avail) ? p->first : g->codes[code].first; + } else if (code == avail) + return stbi__errpuc("illegal code in raster", "Corrupt GIF"); + + stbi__out_gif_code(g, (stbi__uint16) code); + + if ((avail & codemask) == 0 && avail <= 0x0FFF) { + codesize++; + codemask = (1 << codesize) - 1; + } + + oldcode = code; + } else { + return stbi__errpuc("illegal code in raster", "Corrupt GIF"); + } + } + } +} + +// this function is designed to support animated gifs, although stb_image doesn't support it +// two back is the image from two frames ago, used for a very specific disposal format +static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back) +{ + int dispose; + int first_frame; + int pi; + int pcount; + STBI_NOTUSED(req_comp); + + // on first frame, any non-written pixels get the background colour (non-transparent) + first_frame = 0; + if (g->out == 0) { + if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header + if (!stbi__mad3sizes_valid(4, g->w, g->h, 0)) + return stbi__errpuc("too large", "GIF image is too large"); + pcount = g->w * g->h; + g->out = (stbi_uc *) stbi__malloc(4 * pcount); + g->background = (stbi_uc *) stbi__malloc(4 * pcount); + g->history = (stbi_uc *) stbi__malloc(pcount); + if (!g->out || !g->background || !g->history) + return stbi__errpuc("outofmem", "Out of memory"); + + // image is treated as "transparent" at the start - ie, nothing overwrites the current background; + // background colour is only used for pixels that are not rendered first frame, after that "background" + // color refers to the color that was there the previous frame. + memset(g->out, 0x00, 4 * pcount); + memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent) + memset(g->history, 0x00, pcount); // pixels that were affected previous frame + first_frame = 1; + } else { + // second frame - how do we dispose of the previous one? + dispose = (g->eflags & 0x1C) >> 2; + pcount = g->w * g->h; + + if ((dispose == 3) && (two_back == 0)) { + dispose = 2; // if I don't have an image to revert back to, default to the old background + } + + if (dispose == 3) { // use previous graphic + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi]) { + memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 ); + } + } + } else if (dispose == 2) { + // restore what was changed last frame to background before that frame; + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi]) { + memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 ); + } + } + } else { + // This is a non-disposal case eithe way, so just + // leave the pixels as is, and they will become the new background + // 1: do not dispose + // 0: not specified. + } + + // background is what out is after the undoing of the previou frame; + memcpy( g->background, g->out, 4 * g->w * g->h ); + } + + // clear my history; + memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame + + for (;;) { + int tag = stbi__get8(s); + switch (tag) { + case 0x2C: /* Image Descriptor */ + { + stbi__int32 x, y, w, h; + stbi_uc *o; + + x = stbi__get16le(s); + y = stbi__get16le(s); + w = stbi__get16le(s); + h = stbi__get16le(s); + if (((x + w) > (g->w)) || ((y + h) > (g->h))) + return stbi__errpuc("bad Image Descriptor", "Corrupt GIF"); + + g->line_size = g->w * 4; + g->start_x = x * 4; + g->start_y = y * g->line_size; + g->max_x = g->start_x + w * 4; + g->max_y = g->start_y + h * g->line_size; + g->cur_x = g->start_x; + g->cur_y = g->start_y; + + // if the width of the specified rectangle is 0, that means + // we may not see *any* pixels or the image is malformed; + // to make sure this is caught, move the current y down to + // max_y (which is what out_gif_code checks). + if (w == 0) + g->cur_y = g->max_y; + + g->lflags = stbi__get8(s); + + if (g->lflags & 0x40) { + g->step = 8 * g->line_size; // first interlaced spacing + g->parse = 3; + } else { + g->step = g->line_size; + g->parse = 0; + } + + if (g->lflags & 0x80) { + stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1); + g->color_table = (stbi_uc *) g->lpal; + } else if (g->flags & 0x80) { + g->color_table = (stbi_uc *) g->pal; + } else + return stbi__errpuc("missing color table", "Corrupt GIF"); + + o = stbi__process_gif_raster(s, g); + if (!o) return NULL; + + // if this was the first frame, + pcount = g->w * g->h; + if (first_frame && (g->bgindex > 0)) { + // if first frame, any pixel not drawn to gets the background color + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi] == 0) { + g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be; + memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 ); + } + } + } + + return o; + } + + case 0x21: // Comment Extension. + { + int len; + int ext = stbi__get8(s); + if (ext == 0xF9) { // Graphic Control Extension. + len = stbi__get8(s); + if (len == 4) { + g->eflags = stbi__get8(s); + g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths. + + // unset old transparent + if (g->transparent >= 0) { + g->pal[g->transparent][3] = 255; + } + if (g->eflags & 0x01) { + g->transparent = stbi__get8(s); + if (g->transparent >= 0) { + g->pal[g->transparent][3] = 0; + } + } else { + // don't need transparent + stbi__skip(s, 1); + g->transparent = -1; + } + } else { + stbi__skip(s, len); + break; + } + } + while ((len = stbi__get8(s)) != 0) { + stbi__skip(s, len); + } + break; + } + + case 0x3B: // gif stream termination code + return (stbi_uc *) s; // using '1' causes warning on some compilers + + default: + return stbi__errpuc("unknown code", "Corrupt GIF"); + } + } +} + +static void *stbi__load_gif_main_outofmem(stbi__gif *g, stbi_uc *out, int **delays) +{ + STBI_FREE(g->out); + STBI_FREE(g->history); + STBI_FREE(g->background); + + if (out) STBI_FREE(out); + if (delays && *delays) STBI_FREE(*delays); + return stbi__errpuc("outofmem", "Out of memory"); +} + +static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp) +{ + if (stbi__gif_test(s)) { + int layers = 0; + stbi_uc *u = 0; + stbi_uc *out = 0; + stbi_uc *two_back = 0; + stbi__gif g; + int stride; + int out_size = 0; + int delays_size = 0; + + STBI_NOTUSED(out_size); + STBI_NOTUSED(delays_size); + + memset(&g, 0, sizeof(g)); + if (delays) { + *delays = 0; + } + + do { + u = stbi__gif_load_next(s, &g, comp, req_comp, two_back); + if (u == (stbi_uc *) s) u = 0; // end of animated gif marker + + if (u) { + *x = g.w; + *y = g.h; + ++layers; + stride = g.w * g.h * 4; + + if (out) { + void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride ); + if (!tmp) + return stbi__load_gif_main_outofmem(&g, out, delays); + else { + out = (stbi_uc*) tmp; + out_size = layers * stride; + } + + if (delays) { + int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers ); + if (!new_delays) + return stbi__load_gif_main_outofmem(&g, out, delays); + *delays = new_delays; + delays_size = layers * sizeof(int); + } + } else { + out = (stbi_uc*)stbi__malloc( layers * stride ); + if (!out) + return stbi__load_gif_main_outofmem(&g, out, delays); + out_size = layers * stride; + if (delays) { + *delays = (int*) stbi__malloc( layers * sizeof(int) ); + if (!*delays) + return stbi__load_gif_main_outofmem(&g, out, delays); + delays_size = layers * sizeof(int); + } + } + memcpy( out + ((layers - 1) * stride), u, stride ); + if (layers >= 2) { + two_back = out - 2 * stride; + } + + if (delays) { + (*delays)[layers - 1U] = g.delay; + } + } + } while (u != 0); + + // free temp buffer; + STBI_FREE(g.out); + STBI_FREE(g.history); + STBI_FREE(g.background); + + // do the final conversion after loading everything; + if (req_comp && req_comp != 4) + out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h); + + *z = layers; + return out; + } else { + return stbi__errpuc("not GIF", "Image was not as a gif type."); + } +} + +static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *u = 0; + stbi__gif g; + memset(&g, 0, sizeof(g)); + STBI_NOTUSED(ri); + + u = stbi__gif_load_next(s, &g, comp, req_comp, 0); + if (u == (stbi_uc *) s) u = 0; // end of animated gif marker + if (u) { + *x = g.w; + *y = g.h; + + // moved conversion to after successful load so that the same + // can be done for multiple frames. + if (req_comp && req_comp != 4) + u = stbi__convert_format(u, 4, req_comp, g.w, g.h); + } else if (g.out) { + // if there was an error and we allocated an image buffer, free it! + STBI_FREE(g.out); + } + + // free buffers needed for multiple frame loading; + STBI_FREE(g.history); + STBI_FREE(g.background); + + return u; +} + +static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp) +{ + return stbi__gif_info_raw(s,x,y,comp); +} +#endif + +// ************************************************************************************************* +// Radiance RGBE HDR loader +// originally by Nicolas Schulz +#ifndef STBI_NO_HDR +static int stbi__hdr_test_core(stbi__context *s, const char *signature) +{ + int i; + for (i=0; signature[i]; ++i) + if (stbi__get8(s) != signature[i]) + return 0; + stbi__rewind(s); + return 1; +} + +static int stbi__hdr_test(stbi__context* s) +{ + int r = stbi__hdr_test_core(s, "#?RADIANCE\n"); + stbi__rewind(s); + if(!r) { + r = stbi__hdr_test_core(s, "#?RGBE\n"); + stbi__rewind(s); + } + return r; +} + +#define STBI__HDR_BUFLEN 1024 +static char *stbi__hdr_gettoken(stbi__context *z, char *buffer) +{ + int len=0; + char c = '\0'; + + c = (char) stbi__get8(z); + + while (!stbi__at_eof(z) && c != '\n') { + buffer[len++] = c; + if (len == STBI__HDR_BUFLEN-1) { + // flush to end of line + while (!stbi__at_eof(z) && stbi__get8(z) != '\n') + ; + break; + } + c = (char) stbi__get8(z); + } + + buffer[len] = 0; + return buffer; +} + +static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp) +{ + if ( input[3] != 0 ) { + float f1; + // Exponent + f1 = (float) ldexp(1.0f, input[3] - (int)(128 + 8)); + if (req_comp <= 2) + output[0] = (input[0] + input[1] + input[2]) * f1 / 3; + else { + output[0] = input[0] * f1; + output[1] = input[1] * f1; + output[2] = input[2] * f1; + } + if (req_comp == 2) output[1] = 1; + if (req_comp == 4) output[3] = 1; + } else { + switch (req_comp) { + case 4: output[3] = 1; /* fallthrough */ + case 3: output[0] = output[1] = output[2] = 0; + break; + case 2: output[1] = 1; /* fallthrough */ + case 1: output[0] = 0; + break; + } + } +} + +static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + char buffer[STBI__HDR_BUFLEN]; + char *token; + int valid = 0; + int width, height; + stbi_uc *scanline; + float *hdr_data; + int len; + unsigned char count, value; + int i, j, k, c1,c2, z; + const char *headerToken; + STBI_NOTUSED(ri); + + // Check identifier + headerToken = stbi__hdr_gettoken(s,buffer); + if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0) + return stbi__errpf("not HDR", "Corrupt HDR image"); + + // Parse header + for(;;) { + token = stbi__hdr_gettoken(s,buffer); + if (token[0] == 0) break; + if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; + } + + if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format"); + + // Parse width and height + // can't use sscanf() if we're not using stdio! + token = stbi__hdr_gettoken(s,buffer); + if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); + token += 3; + height = (int) strtol(token, &token, 10); + while (*token == ' ') ++token; + if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); + token += 3; + width = (int) strtol(token, NULL, 10); + + if (height > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)"); + if (width > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)"); + + *x = width; + *y = height; + + if (comp) *comp = 3; + if (req_comp == 0) req_comp = 3; + + if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0)) + return stbi__errpf("too large", "HDR image is too large"); + + // Read data + hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0); + if (!hdr_data) + return stbi__errpf("outofmem", "Out of memory"); + + // Load image data + // image data is stored as some number of sca + if ( width < 8 || width >= 32768) { + // Read flat data + for (j=0; j < height; ++j) { + for (i=0; i < width; ++i) { + stbi_uc rgbe[4]; + main_decode_loop: + stbi__getn(s, rgbe, 4); + stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp); + } + } + } else { + // Read RLE-encoded data + scanline = NULL; + + for (j = 0; j < height; ++j) { + c1 = stbi__get8(s); + c2 = stbi__get8(s); + len = stbi__get8(s); + if (c1 != 2 || c2 != 2 || (len & 0x80)) { + // not run-length encoded, so we have to actually use THIS data as a decoded + // pixel (note this can't be a valid pixel--one of RGB must be >= 128) + stbi_uc rgbe[4]; + rgbe[0] = (stbi_uc) c1; + rgbe[1] = (stbi_uc) c2; + rgbe[2] = (stbi_uc) len; + rgbe[3] = (stbi_uc) stbi__get8(s); + stbi__hdr_convert(hdr_data, rgbe, req_comp); + i = 1; + j = 0; + STBI_FREE(scanline); + goto main_decode_loop; // yes, this makes no sense + } + len <<= 8; + len |= stbi__get8(s); + if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); } + if (scanline == NULL) { + scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0); + if (!scanline) { + STBI_FREE(hdr_data); + return stbi__errpf("outofmem", "Out of memory"); + } + } + + for (k = 0; k < 4; ++k) { + int nleft; + i = 0; + while ((nleft = width - i) > 0) { + count = stbi__get8(s); + if (count > 128) { + // Run + value = stbi__get8(s); + count -= 128; + if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } + for (z = 0; z < count; ++z) + scanline[i++ * 4 + k] = value; + } else { + // Dump + if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } + for (z = 0; z < count; ++z) + scanline[i++ * 4 + k] = stbi__get8(s); + } + } + } + for (i=0; i < width; ++i) + stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp); + } + if (scanline) + STBI_FREE(scanline); + } + + return hdr_data; +} + +static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp) +{ + char buffer[STBI__HDR_BUFLEN]; + char *token; + int valid = 0; + int dummy; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + if (stbi__hdr_test(s) == 0) { + stbi__rewind( s ); + return 0; + } + + for(;;) { + token = stbi__hdr_gettoken(s,buffer); + if (token[0] == 0) break; + if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; + } + + if (!valid) { + stbi__rewind( s ); + return 0; + } + token = stbi__hdr_gettoken(s,buffer); + if (strncmp(token, "-Y ", 3)) { + stbi__rewind( s ); + return 0; + } + token += 3; + *y = (int) strtol(token, &token, 10); + while (*token == ' ') ++token; + if (strncmp(token, "+X ", 3)) { + stbi__rewind( s ); + return 0; + } + token += 3; + *x = (int) strtol(token, NULL, 10); + *comp = 3; + return 1; +} +#endif // STBI_NO_HDR + +#ifndef STBI_NO_BMP +static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp) +{ + void *p; + stbi__bmp_data info; + + info.all_a = 255; + p = stbi__bmp_parse_header(s, &info); + if (p == NULL) { + stbi__rewind( s ); + return 0; + } + if (x) *x = s->img_x; + if (y) *y = s->img_y; + if (comp) { + if (info.bpp == 24 && info.ma == 0xff000000) + *comp = 3; + else + *comp = info.ma ? 4 : 3; + } + return 1; +} +#endif + +#ifndef STBI_NO_PSD +static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) +{ + int channelCount, dummy, depth; + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + if (stbi__get32be(s) != 0x38425053) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 1) { + stbi__rewind( s ); + return 0; + } + stbi__skip(s, 6); + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) { + stbi__rewind( s ); + return 0; + } + *y = stbi__get32be(s); + *x = stbi__get32be(s); + depth = stbi__get16be(s); + if (depth != 8 && depth != 16) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 3) { + stbi__rewind( s ); + return 0; + } + *comp = 4; + return 1; +} + +static int stbi__psd_is16(stbi__context *s) +{ + int channelCount, depth; + if (stbi__get32be(s) != 0x38425053) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 1) { + stbi__rewind( s ); + return 0; + } + stbi__skip(s, 6); + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) { + stbi__rewind( s ); + return 0; + } + STBI_NOTUSED(stbi__get32be(s)); + STBI_NOTUSED(stbi__get32be(s)); + depth = stbi__get16be(s); + if (depth != 16) { + stbi__rewind( s ); + return 0; + } + return 1; +} +#endif + +#ifndef STBI_NO_PIC +static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp) +{ + int act_comp=0,num_packets=0,chained,dummy; + stbi__pic_packet packets[10]; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) { + stbi__rewind(s); + return 0; + } + + stbi__skip(s, 88); + + *x = stbi__get16be(s); + *y = stbi__get16be(s); + if (stbi__at_eof(s)) { + stbi__rewind( s); + return 0; + } + if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) { + stbi__rewind( s ); + return 0; + } + + stbi__skip(s, 8); + + do { + stbi__pic_packet *packet; + + if (num_packets==sizeof(packets)/sizeof(packets[0])) + return 0; + + packet = &packets[num_packets++]; + chained = stbi__get8(s); + packet->size = stbi__get8(s); + packet->type = stbi__get8(s); + packet->channel = stbi__get8(s); + act_comp |= packet->channel; + + if (stbi__at_eof(s)) { + stbi__rewind( s ); + return 0; + } + if (packet->size != 8) { + stbi__rewind( s ); + return 0; + } + } while (chained); + + *comp = (act_comp & 0x10 ? 4 : 3); + + return 1; +} +#endif + +// ************************************************************************************************* +// Portable Gray Map and Portable Pixel Map loader +// by Ken Miller +// +// PGM: http://netpbm.sourceforge.net/doc/pgm.html +// PPM: http://netpbm.sourceforge.net/doc/ppm.html +// +// Known limitations: +// Does not support comments in the header section +// Does not support ASCII image data (formats P2 and P3) + +#ifndef STBI_NO_PNM + +static int stbi__pnm_test(stbi__context *s) +{ + char p, t; + p = (char) stbi__get8(s); + t = (char) stbi__get8(s); + if (p != 'P' || (t != '5' && t != '6')) { + stbi__rewind( s ); + return 0; + } + return 1; +} + +static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *out; + STBI_NOTUSED(ri); + + ri->bits_per_channel = stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n); + if (ri->bits_per_channel == 0) + return 0; + + if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)"); + + *x = s->img_x; + *y = s->img_y; + if (comp) *comp = s->img_n; + + if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0)) + return stbi__errpuc("too large", "PNM too large"); + + out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0); + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) { + STBI_FREE(out); + return stbi__errpuc("bad PNM", "PNM file truncated"); + } + + if (req_comp && req_comp != s->img_n) { + if (ri->bits_per_channel == 16) { + out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y); + } else { + out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y); + } + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + return out; +} + +static int stbi__pnm_isspace(char c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; +} + +static void stbi__pnm_skip_whitespace(stbi__context *s, char *c) +{ + for (;;) { + while (!stbi__at_eof(s) && stbi__pnm_isspace(*c)) + *c = (char) stbi__get8(s); + + if (stbi__at_eof(s) || *c != '#') + break; + + while (!stbi__at_eof(s) && *c != '\n' && *c != '\r' ) + *c = (char) stbi__get8(s); + } +} + +static int stbi__pnm_isdigit(char c) +{ + return c >= '0' && c <= '9'; +} + +static int stbi__pnm_getinteger(stbi__context *s, char *c) +{ + int value = 0; + + while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) { + value = value*10 + (*c - '0'); + *c = (char) stbi__get8(s); + if((value > 214748364) || (value == 214748364 && *c > '7')) + return stbi__err("integer parse overflow", "Parsing an integer in the PPM header overflowed a 32-bit int"); + } + + return value; +} + +static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) +{ + int maxv, dummy; + char c, p, t; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + stbi__rewind(s); + + // Get identifier + p = (char) stbi__get8(s); + t = (char) stbi__get8(s); + if (p != 'P' || (t != '5' && t != '6')) { + stbi__rewind(s); + return 0; + } + + *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm + + c = (char) stbi__get8(s); + stbi__pnm_skip_whitespace(s, &c); + + *x = stbi__pnm_getinteger(s, &c); // read width + if(*x == 0) + return stbi__err("invalid width", "PPM image header had zero or overflowing width"); + stbi__pnm_skip_whitespace(s, &c); + + *y = stbi__pnm_getinteger(s, &c); // read height + if (*y == 0) + return stbi__err("invalid width", "PPM image header had zero or overflowing width"); + stbi__pnm_skip_whitespace(s, &c); + + maxv = stbi__pnm_getinteger(s, &c); // read max value + if (maxv > 65535) + return stbi__err("max value > 65535", "PPM image supports only 8-bit and 16-bit images"); + else if (maxv > 255) + return 16; + else + return 8; +} + +static int stbi__pnm_is16(stbi__context *s) +{ + if (stbi__pnm_info(s, NULL, NULL, NULL) == 16) + return 1; + return 0; +} +#endif + +static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp) +{ +#ifndef STBI_NO_JPEG + if (stbi__jpeg_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_PNG + if (stbi__png_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_GIF + if (stbi__gif_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_BMP + if (stbi__bmp_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_PSD + if (stbi__psd_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_PIC + if (stbi__pic_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_PNM + if (stbi__pnm_info(s, x, y, comp)) return 1; +#endif + +#ifndef STBI_NO_HDR + if (stbi__hdr_info(s, x, y, comp)) return 1; +#endif + + // test tga last because it's a crappy test! +#ifndef STBI_NO_TGA + if (stbi__tga_info(s, x, y, comp)) + return 1; +#endif + return stbi__err("unknown image type", "Image not of any known type, or corrupt"); +} + +static int stbi__is_16_main(stbi__context *s) +{ +#ifndef STBI_NO_PNG + if (stbi__png_is16(s)) return 1; +#endif + +#ifndef STBI_NO_PSD + if (stbi__psd_is16(s)) return 1; +#endif + +#ifndef STBI_NO_PNM + if (stbi__pnm_is16(s)) return 1; +#endif + return 0; +} + +#ifndef STBI_NO_STDIO +STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result; + if (!f) return stbi__err("can't fopen", "Unable to open file"); + result = stbi_info_from_file(f, x, y, comp); + fclose(f); + return result; +} + +STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) +{ + int r; + stbi__context s; + long pos = ftell(f); + stbi__start_file(&s, f); + r = stbi__info_main(&s,x,y,comp); + fseek(f,pos,SEEK_SET); + return r; +} + +STBIDEF int stbi_is_16_bit(char const *filename) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result; + if (!f) return stbi__err("can't fopen", "Unable to open file"); + result = stbi_is_16_bit_from_file(f); + fclose(f); + return result; +} + +STBIDEF int stbi_is_16_bit_from_file(FILE *f) +{ + int r; + stbi__context s; + long pos = ftell(f); + stbi__start_file(&s, f); + r = stbi__is_16_main(&s); + fseek(f,pos,SEEK_SET); + return r; +} +#endif // !STBI_NO_STDIO + +STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__info_main(&s,x,y,comp); +} + +STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int *x, int *y, int *comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); + return stbi__info_main(&s,x,y,comp); +} + +STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__is_16_main(&s); +} + +STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); + return stbi__is_16_main(&s); +} + +#endif // STB_IMAGE_IMPLEMENTATION + +/* + revision history: + 2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs + 2.19 (2018-02-11) fix warning + 2.18 (2018-01-30) fix warnings + 2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug + 1-bit BMP + *_is_16_bit api + avoid warnings + 2.16 (2017-07-23) all functions have 16-bit variants; + STBI_NO_STDIO works again; + compilation fixes; + fix rounding in unpremultiply; + optimize vertical flip; + disable raw_len validation; + documentation fixes + 2.15 (2017-03-18) fix png-1,2,4 bug; now all Imagenet JPGs decode; + warning fixes; disable run-time SSE detection on gcc; + uniform handling of optional "return" values; + thread-safe initialization of zlib tables + 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs + 2.13 (2016-11-29) add 16-bit API, only supported for PNG right now + 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes + 2.11 (2016-04-02) allocate large structures on the stack + remove white matting for transparent PSD + fix reported channel count for PNG & BMP + re-enable SSE2 in non-gcc 64-bit + support RGB-formatted JPEG + read 16-bit PNGs (only as 8-bit) + 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED + 2.09 (2016-01-16) allow comments in PNM files + 16-bit-per-pixel TGA (not bit-per-component) + info() for TGA could break due to .hdr handling + info() for BMP to shares code instead of sloppy parse + can use STBI_REALLOC_SIZED if allocator doesn't support realloc + code cleanup + 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA + 2.07 (2015-09-13) fix compiler warnings + partial animated GIF support + limited 16-bpc PSD support + #ifdef unused functions + bug with < 92 byte PIC,PNM,HDR,TGA + 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value + 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning + 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit + 2.03 (2015-04-12) extra corruption checking (mmozeiko) + stbi_set_flip_vertically_on_load (nguillemot) + fix NEON support; fix mingw support + 2.02 (2015-01-19) fix incorrect assert, fix warning + 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2 + 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG + 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg) + progressive JPEG (stb) + PGM/PPM support (Ken Miller) + STBI_MALLOC,STBI_REALLOC,STBI_FREE + GIF bugfix -- seemingly never worked + STBI_NO_*, STBI_ONLY_* + 1.48 (2014-12-14) fix incorrectly-named assert() + 1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb) + optimize PNG (ryg) + fix bug in interlaced PNG with user-specified channel count (stb) + 1.46 (2014-08-26) + fix broken tRNS chunk (colorkey-style transparency) in non-paletted PNG + 1.45 (2014-08-16) + fix MSVC-ARM internal compiler error by wrapping malloc + 1.44 (2014-08-07) + various warning fixes from Ronny Chevalier + 1.43 (2014-07-15) + fix MSVC-only compiler problem in code changed in 1.42 + 1.42 (2014-07-09) + don't define _CRT_SECURE_NO_WARNINGS (affects user code) + fixes to stbi__cleanup_jpeg path + added STBI_ASSERT to avoid requiring assert.h + 1.41 (2014-06-25) + fix search&replace from 1.36 that messed up comments/error messages + 1.40 (2014-06-22) + fix gcc struct-initialization warning + 1.39 (2014-06-15) + fix to TGA optimization when req_comp != number of components in TGA; + fix to GIF loading because BMP wasn't rewinding (whoops, no GIFs in my test suite) + add support for BMP version 5 (more ignored fields) + 1.38 (2014-06-06) + suppress MSVC warnings on integer casts truncating values + fix accidental rename of 'skip' field of I/O + 1.37 (2014-06-04) + remove duplicate typedef + 1.36 (2014-06-03) + convert to header file single-file library + if de-iphone isn't set, load iphone images color-swapped instead of returning NULL + 1.35 (2014-05-27) + various warnings + fix broken STBI_SIMD path + fix bug where stbi_load_from_file no longer left file pointer in correct place + fix broken non-easy path for 32-bit BMP (possibly never used) + TGA optimization by Arseny Kapoulkine + 1.34 (unknown) + use STBI_NOTUSED in stbi__resample_row_generic(), fix one more leak in tga failure case + 1.33 (2011-07-14) + make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements + 1.32 (2011-07-13) + support for "info" function for all supported filetypes (SpartanJ) + 1.31 (2011-06-20) + a few more leak fixes, bug in PNG handling (SpartanJ) + 1.30 (2011-06-11) + added ability to load files via callbacks to accomidate custom input streams (Ben Wenger) + removed deprecated format-specific test/load functions + removed support for installable file formats (stbi_loader) -- would have been broken for IO callbacks anyway + error cases in bmp and tga give messages and don't leak (Raymond Barbiero, grisha) + fix inefficiency in decoding 32-bit BMP (David Woo) + 1.29 (2010-08-16) + various warning fixes from Aurelien Pocheville + 1.28 (2010-08-01) + fix bug in GIF palette transparency (SpartanJ) + 1.27 (2010-08-01) + cast-to-stbi_uc to fix warnings + 1.26 (2010-07-24) + fix bug in file buffering for PNG reported by SpartanJ + 1.25 (2010-07-17) + refix trans_data warning (Won Chun) + 1.24 (2010-07-12) + perf improvements reading from files on platforms with lock-heavy fgetc() + minor perf improvements for jpeg + deprecated type-specific functions so we'll get feedback if they're needed + attempt to fix trans_data warning (Won Chun) + 1.23 fixed bug in iPhone support + 1.22 (2010-07-10) + removed image *writing* support + stbi_info support from Jetro Lauha + GIF support from Jean-Marc Lienher + iPhone PNG-extensions from James Brown + warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva) + 1.21 fix use of 'stbi_uc' in header (reported by jon blow) + 1.20 added support for Softimage PIC, by Tom Seddon + 1.19 bug in interlaced PNG corruption check (found by ryg) + 1.18 (2008-08-02) + fix a threading bug (local mutable static) + 1.17 support interlaced PNG + 1.16 major bugfix - stbi__convert_format converted one too many pixels + 1.15 initialize some fields for thread safety + 1.14 fix threadsafe conversion bug + header-file-only version (#define STBI_HEADER_FILE_ONLY before including) + 1.13 threadsafe + 1.12 const qualifiers in the API + 1.11 Support installable IDCT, colorspace conversion routines + 1.10 Fixes for 64-bit (don't use "unsigned long") + optimized upsampling by Fabian "ryg" Giesen + 1.09 Fix format-conversion for PSD code (bad global variables!) + 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz + 1.07 attempt to fix C++ warning/errors again + 1.06 attempt to fix C++ warning/errors again + 1.05 fix TGA loading to return correct *comp and use good luminance calc + 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free + 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR + 1.02 support for (subset of) HDR files, float interface for preferred access to them + 1.01 fix bug: possible bug in handling right-side up bmps... not sure + fix bug: the stbi__bmp_load() and stbi__tga_load() functions didn't work at all + 1.00 interface to zlib that skips zlib header + 0.99 correct handling of alpha in palette + 0.98 TGA loader by lonesock; dynamically add loaders (untested) + 0.97 jpeg errors on too large a file; also catch another malloc failure + 0.96 fix detection of invalid v value - particleman@mollyrocket forum + 0.95 during header scan, seek to markers in case of padding + 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same + 0.93 handle jpegtran output; verbose errors + 0.92 read 4,8,16,24,32-bit BMP files of several formats + 0.91 output 24-bit Windows 3.0 BMP files + 0.90 fix a few more warnings; bump version number to approach 1.0 + 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd + 0.60 fix compiling as c++ + 0.59 fix warnings: merge Dave Moore's -Wall fixes + 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian + 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available + 0.56 fix bug: zlib uncompressed mode len vs. nlen + 0.55 fix bug: restart_interval not initialized to 0 + 0.54 allow NULL for 'int *comp' + 0.53 fix bug in png 3->4; speedup png decoding + 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments + 0.51 obey req_comp requests, 1-component jpegs return as 1-component, + on 'test' only check type, not whether we support this variant + 0.50 (2006-11-19) + first released version +*/ + + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ diff --git a/src/ui/ui_basic_widgets.c b/src/ui/ui_basic_widgets.c index 7edbfd2b..9cad0cf7 100644 --- a/src/ui/ui_basic_widgets.c +++ b/src/ui/ui_basic_widgets.c @@ -330,6 +330,75 @@ ui_line_editf(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, return result; } +//////////////////////////////// +//~ rjf: Images + +typedef struct UI_ImageDrawData UI_ImageDrawData; +struct UI_ImageDrawData +{ + R_Handle texture; + R_Tex2DSampleKind sample_kind; + Rng2F32 region; + Vec4F32 tint; + F32 blur; +}; + +internal UI_BOX_CUSTOM_DRAW(ui_image_draw) +{ + UI_ImageDrawData *draw_data = (UI_ImageDrawData *)user_data; + if(r_handle_match(draw_data->texture, r_handle_zero())) + { + R_Rect2DInst *inst = d_rect(box->rect, v4f32(0, 0, 0, 0), 0, 0, 1.f); + MemoryCopyArray(inst->corner_radii, box->corner_radii); + } + else D_Tex2DSampleKindScope(draw_data->sample_kind) + { + R_Rect2DInst *inst = d_img(box->rect, draw_data->region, draw_data->texture, draw_data->tint, 0, 0, 0); + MemoryCopyArray(inst->corner_radii, box->corner_radii); + } + if(draw_data->blur > 0.01f) + { + Rng2F32 clip = box->rect; + for(UI_Box *b = box->parent; !ui_box_is_nil(b); b = b->parent) + { + if(b->flags & UI_BoxFlag_Clip) + { + clip = intersect_2f32(b->rect, clip); + } + } + R_PassParams_Blur *blur = d_blur(intersect_2f32(clip, box->rect), draw_data->blur, 0); + MemoryCopyArray(blur->corner_radii, box->corner_radii); + } +} + +internal UI_Signal +ui_image(R_Handle texture, R_Tex2DSampleKind sample_kind, Rng2F32 region, Vec4F32 tint, F32 blur, String8 string) +{ + UI_Box *box = ui_build_box_from_string(0, string); + UI_ImageDrawData *draw_data = push_array(ui_build_arena(), UI_ImageDrawData, 1); + draw_data->texture = texture; + draw_data->sample_kind = sample_kind; + draw_data->region = region; + draw_data->tint = tint; + draw_data->blur = blur; + ui_box_equip_custom_draw(box, ui_image_draw, draw_data); + UI_Signal sig = ui_signal_from_box(box); + return sig; +} + +internal UI_Signal +ui_imagef(R_Handle texture, R_Tex2DSampleKind sample_kind, Rng2F32 region, Vec4F32 tint, F32 blur, char *fmt, ...) +{ + Temp scratch = scratch_begin(0, 0); + va_list args; + va_start(args, fmt); + String8 string = push_str8fv(scratch.arena, fmt, args); + va_end(args); + UI_Signal result = ui_image(texture, sample_kind, region, tint, blur, string); + scratch_end(scratch); + return result; +} + //////////////////////////////// //~ rjf: Special Buttons diff --git a/src/ui/ui_basic_widgets.h b/src/ui/ui_basic_widgets.h index c6bd0f01..cc934a52 100644 --- a/src/ui/ui_basic_widgets.h +++ b/src/ui/ui_basic_widgets.h @@ -80,6 +80,12 @@ internal UI_Signal ui_hover_labelf(char *fmt, ...); internal UI_Signal ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, String8 string); internal UI_Signal ui_line_editf(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, char *fmt, ...); +//////////////////////////////// +//~ rjf: Images + +internal UI_Signal ui_image(R_Handle texture, R_Tex2DSampleKind sample_kind, Rng2F32 region, Vec4F32 tint, F32 blur, String8 string); +internal UI_Signal ui_imagef(R_Handle texture, R_Tex2DSampleKind sample_kind, Rng2F32 region, Vec4F32 tint, F32 blur, char *fmt, ...); + //////////////////////////////// //~ rjf: Special Buttons diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index be62687e..51f45dc2 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -527,6 +527,12 @@ ui_dt(void) //- rjf: drag data +internal Vec2F32 +ui_drag_start_mouse(void) +{ + return ui_state->drag_start_mouse; +} + internal Vec2F32 ui_drag_delta(void) { @@ -596,6 +602,12 @@ ui_active_key(UI_MouseButtonKind button_kind) return ui_state->active_box_key[button_kind]; } +internal UI_Key +ui_drop_hot_key(void) +{ + return ui_state->drop_hot_box_key; +} + //- rjf: controls over interaction internal void @@ -934,7 +946,7 @@ ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_act } //- rjf: setup parent box for tooltip - UI_FixedX(ui_state->mouse.x+15.f) UI_FixedY(ui_state->mouse.y) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f)) + UI_FixedX(ui_state->mouse.x+15.f) UI_FixedY(ui_state->mouse.y+15.f) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f)) { ui_set_next_child_layout_axis(Axis2_Y); ui_state->tooltip_root = ui_build_box_from_stringf(0, "###tooltip_%I64x", window.u64[0]); @@ -976,6 +988,11 @@ ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_act } } + //- rjf: reset drop-hot key + { + ui_state->drop_hot_box_key = ui_key_zero(); + } + //- rjf: reset active if our active box is disabled for(EachEnumVal(UI_MouseButtonKind, k)) { @@ -1084,17 +1101,20 @@ ui_end_build(void) //- rjf: ensure special floating roots are within screen bounds UI_Box *floating_roots[] = {ui_state->tooltip_root, ui_state->ctx_menu_root}; + B32 force_contain[] = {0, 1}; for(U64 idx = 0; idx < ArrayCount(floating_roots); idx += 1) { UI_Box *root = floating_roots[idx]; if(!ui_box_is_nil(root)) { Rng2F32 window_rect = os_client_rect_from_window(ui_window()); + Vec2F32 window_dim = dim_2f32(window_rect); Rng2F32 root_rect = root->rect; + Vec2F32 root_rect_dim = dim_2f32(root_rect); Vec2F32 shift = { - -ClampBot(0, root_rect.x1 - window_rect.x1), - -ClampBot(0, root_rect.y1 - window_rect.y1), + -ClampBot(0, root_rect.x1 - window_rect.x1) * (root_rect_dim.x < root->font_size*15.f || force_contain[idx]), + -ClampBot(0, root_rect.y1 - window_rect.y1) * (root_rect_dim.y < root->font_size*15.f || force_contain[idx]), }; Rng2F32 new_root_rect = shift_2f32(root_rect, shift); root->fixed_position = new_root_rect.p0; @@ -1711,7 +1731,6 @@ internal void ui_tooltip_end_base(void) { ui_pop_flags(); - ui_pop_transparency(); ui_pop_parent(); ui_pop_parent(); } @@ -2283,7 +2302,7 @@ ui_box_text_position(UI_Box *box) case UI_TextAlign_Center: { Vec2F32 advance = box->display_string_runs.dim; - result.x = (box->rect.p0.x + box->rect.p1.x)/2 - advance.x/2; + result.x = floor_f32((box->rect.p0.x + box->rect.p1.x)/2 - advance.x/2 - 1.f); result.x = ClampBot(result.x, box->rect.x0); }break; case UI_TextAlign_Right: @@ -2519,8 +2538,13 @@ ui_signal_from_box(UI_Box *box) { Swap(F32, delta.x, delta.y); } - sig.scroll.x += (S16)(delta.x/30.f); - sig.scroll.y += (S16)(delta.y/30.f); + Vec2S16 delta16 = v2s16((S16)(delta.x/30.f), (S16)(delta.y/30.f)); + if(delta.x > 0 && delta16.x == 0) { delta16.x = +1; } + if(delta.x < 0 && delta16.x == 0) { delta16.x = -1; } + if(delta.y > 0 && delta16.y == 0) { delta16.y = +1; } + if(delta.y < 0 && delta16.y == 0) { delta16.y = -1; } + sig.scroll.x += delta16.x; + sig.scroll.y += delta16.y; taken = 1; } @@ -2712,6 +2736,32 @@ ui_signal_from_box(UI_Box *box) } } + ////////////////////////////// + //- rjf: mouse is over this box's rect, drop site, no other drop hot key? -> set drop hot key + // + { + if(box->flags & UI_BoxFlag_DropSite && + contains_2f32(rect, ui_state->mouse) && + !contains_2f32(blacklist_rect, ui_state->mouse) && + (ui_key_match(ui_state->drop_hot_box_key, ui_key_zero()) || ui_key_match(ui_state->drop_hot_box_key, box->key))) + { + ui_state->drop_hot_box_key = box->key; + } + } + + ////////////////////////////// + //- rjf: mouse is not over this box's rect, but this is the drop hot key? -> zero drop hot key + // + { + if(box->flags & UI_BoxFlag_DropSite && + (!contains_2f32(rect, ui_state->mouse) || + contains_2f32(blacklist_rect, ui_state->mouse)) && + ui_key_match(ui_state->drop_hot_box_key, box->key)) + { + ui_state->drop_hot_box_key = ui_key_zero(); + } + } + ////////////////////////////// //- rjf: clicking on something outside the context menu kills the context menu // diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 3b511a92..d0f48eb6 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -198,57 +198,58 @@ typedef U64 UI_BoxFlags; //- rjf: interaction # define UI_BoxFlag_MouseClickable (UI_BoxFlags)(1ull<<0) # define UI_BoxFlag_KeyboardClickable (UI_BoxFlags)(1ull<<1) -# define UI_BoxFlag_ClickToFocus (UI_BoxFlags)(1ull<<2) -# define UI_BoxFlag_Scroll (UI_BoxFlags)(1ull<<3) -# define UI_BoxFlag_ViewScrollX (UI_BoxFlags)(1ull<<4) -# define UI_BoxFlag_ViewScrollY (UI_BoxFlags)(1ull<<5) -# define UI_BoxFlag_ViewClampX (UI_BoxFlags)(1ull<<6) -# define UI_BoxFlag_ViewClampY (UI_BoxFlags)(1ull<<7) -# define UI_BoxFlag_FocusHot (UI_BoxFlags)(1ull<<8) -# define UI_BoxFlag_FocusActive (UI_BoxFlags)(1ull<<9) -# define UI_BoxFlag_FocusHotDisabled (UI_BoxFlags)(1ull<<10) -# define UI_BoxFlag_FocusActiveDisabled (UI_BoxFlags)(1ull<<11) -# define UI_BoxFlag_DefaultFocusNavX (UI_BoxFlags)(1ull<<12) -# define UI_BoxFlag_DefaultFocusNavY (UI_BoxFlags)(1ull<<13) -# define UI_BoxFlag_DefaultFocusEdit (UI_BoxFlags)(1ull<<14) -# define UI_BoxFlag_FocusNavSkip (UI_BoxFlags)(1ull<<15) -# define UI_BoxFlag_Disabled (UI_BoxFlags)(1ull<<16) +# define UI_BoxFlag_DropSite (UI_BoxFlags)(1ull<<2) +# define UI_BoxFlag_ClickToFocus (UI_BoxFlags)(1ull<<3) +# define UI_BoxFlag_Scroll (UI_BoxFlags)(1ull<<4) +# define UI_BoxFlag_ViewScrollX (UI_BoxFlags)(1ull<<5) +# define UI_BoxFlag_ViewScrollY (UI_BoxFlags)(1ull<<6) +# define UI_BoxFlag_ViewClampX (UI_BoxFlags)(1ull<<7) +# define UI_BoxFlag_ViewClampY (UI_BoxFlags)(1ull<<8) +# define UI_BoxFlag_FocusHot (UI_BoxFlags)(1ull<<9) +# define UI_BoxFlag_FocusActive (UI_BoxFlags)(1ull<<10) +# define UI_BoxFlag_FocusHotDisabled (UI_BoxFlags)(1ull<<11) +# define UI_BoxFlag_FocusActiveDisabled (UI_BoxFlags)(1ull<<12) +# define UI_BoxFlag_DefaultFocusNavX (UI_BoxFlags)(1ull<<13) +# define UI_BoxFlag_DefaultFocusNavY (UI_BoxFlags)(1ull<<14) +# define UI_BoxFlag_DefaultFocusEdit (UI_BoxFlags)(1ull<<15) +# define UI_BoxFlag_FocusNavSkip (UI_BoxFlags)(1ull<<16) +# define UI_BoxFlag_Disabled (UI_BoxFlags)(1ull<<17) //- rjf: layout -# define UI_BoxFlag_FloatingX (UI_BoxFlags)(1ull<<17) -# define UI_BoxFlag_FloatingY (UI_BoxFlags)(1ull<<18) -# define UI_BoxFlag_FixedWidth (UI_BoxFlags)(1ull<<19) -# define UI_BoxFlag_FixedHeight (UI_BoxFlags)(1ull<<20) -# define UI_BoxFlag_AllowOverflowX (UI_BoxFlags)(1ull<<21) -# define UI_BoxFlag_AllowOverflowY (UI_BoxFlags)(1ull<<22) -# define UI_BoxFlag_SkipViewOffX (UI_BoxFlags)(1ull<<23) -# define UI_BoxFlag_SkipViewOffY (UI_BoxFlags)(1ull<<24) +# define UI_BoxFlag_FloatingX (UI_BoxFlags)(1ull<<18) +# define UI_BoxFlag_FloatingY (UI_BoxFlags)(1ull<<19) +# define UI_BoxFlag_FixedWidth (UI_BoxFlags)(1ull<<20) +# define UI_BoxFlag_FixedHeight (UI_BoxFlags)(1ull<<21) +# define UI_BoxFlag_AllowOverflowX (UI_BoxFlags)(1ull<<22) +# define UI_BoxFlag_AllowOverflowY (UI_BoxFlags)(1ull<<23) +# define UI_BoxFlag_SkipViewOffX (UI_BoxFlags)(1ull<<24) +# define UI_BoxFlag_SkipViewOffY (UI_BoxFlags)(1ull<<25) //- rjf: appearance / animation -# define UI_BoxFlag_DrawDropShadow (UI_BoxFlags)(1ull<<25) -# define UI_BoxFlag_DrawBackgroundBlur (UI_BoxFlags)(1ull<<26) -# define UI_BoxFlag_DrawBackground (UI_BoxFlags)(1ull<<27) -# define UI_BoxFlag_DrawBorder (UI_BoxFlags)(1ull<<28) -# define UI_BoxFlag_DrawSideTop (UI_BoxFlags)(1ull<<29) -# define UI_BoxFlag_DrawSideBottom (UI_BoxFlags)(1ull<<30) -# define UI_BoxFlag_DrawSideLeft (UI_BoxFlags)(1ull<<31) -# define UI_BoxFlag_DrawSideRight (UI_BoxFlags)(1ull<<32) -# define UI_BoxFlag_DrawText (UI_BoxFlags)(1ull<<33) -# define UI_BoxFlag_DrawTextFastpathCodepoint (UI_BoxFlags)(1ull<<34) -# define UI_BoxFlag_DrawHotEffects (UI_BoxFlags)(1ull<<35) -# define UI_BoxFlag_DrawActiveEffects (UI_BoxFlags)(1ull<<36) -# define UI_BoxFlag_DrawOverlay (UI_BoxFlags)(1ull<<37) -# define UI_BoxFlag_DrawBucket (UI_BoxFlags)(1ull<<38) -# define UI_BoxFlag_Clip (UI_BoxFlags)(1ull<<39) -# define UI_BoxFlag_AnimatePosX (UI_BoxFlags)(1ull<<40) -# define UI_BoxFlag_AnimatePosY (UI_BoxFlags)(1ull<<41) -# define UI_BoxFlag_DisableTextTrunc (UI_BoxFlags)(1ull<<42) -# define UI_BoxFlag_DisableIDString (UI_BoxFlags)(1ull<<43) -# define UI_BoxFlag_DisableFocusViz (UI_BoxFlags)(1ull<<44) -# define UI_BoxFlag_RequireFocusBackground (UI_BoxFlags)(1ull<<45) -# define UI_BoxFlag_HasDisplayString (UI_BoxFlags)(1ull<<46) -# define UI_BoxFlag_HasFuzzyMatchRanges (UI_BoxFlags)(1ull<<47) -# define UI_BoxFlag_RoundChildrenByParent (UI_BoxFlags)(1ull<<48) +# define UI_BoxFlag_DrawDropShadow (UI_BoxFlags)(1ull<<26) +# define UI_BoxFlag_DrawBackgroundBlur (UI_BoxFlags)(1ull<<27) +# define UI_BoxFlag_DrawBackground (UI_BoxFlags)(1ull<<28) +# define UI_BoxFlag_DrawBorder (UI_BoxFlags)(1ull<<29) +# define UI_BoxFlag_DrawSideTop (UI_BoxFlags)(1ull<<30) +# define UI_BoxFlag_DrawSideBottom (UI_BoxFlags)(1ull<<31) +# define UI_BoxFlag_DrawSideLeft (UI_BoxFlags)(1ull<<32) +# define UI_BoxFlag_DrawSideRight (UI_BoxFlags)(1ull<<33) +# define UI_BoxFlag_DrawText (UI_BoxFlags)(1ull<<34) +# define UI_BoxFlag_DrawTextFastpathCodepoint (UI_BoxFlags)(1ull<<35) +# define UI_BoxFlag_DrawHotEffects (UI_BoxFlags)(1ull<<36) +# define UI_BoxFlag_DrawActiveEffects (UI_BoxFlags)(1ull<<37) +# define UI_BoxFlag_DrawOverlay (UI_BoxFlags)(1ull<<38) +# define UI_BoxFlag_DrawBucket (UI_BoxFlags)(1ull<<39) +# define UI_BoxFlag_Clip (UI_BoxFlags)(1ull<<40) +# define UI_BoxFlag_AnimatePosX (UI_BoxFlags)(1ull<<41) +# define UI_BoxFlag_AnimatePosY (UI_BoxFlags)(1ull<<42) +# define UI_BoxFlag_DisableTextTrunc (UI_BoxFlags)(1ull<<43) +# define UI_BoxFlag_DisableIDString (UI_BoxFlags)(1ull<<44) +# define UI_BoxFlag_DisableFocusViz (UI_BoxFlags)(1ull<<45) +# define UI_BoxFlag_RequireFocusBackground (UI_BoxFlags)(1ull<<46) +# define UI_BoxFlag_HasDisplayString (UI_BoxFlags)(1ull<<47) +# define UI_BoxFlag_HasFuzzyMatchRanges (UI_BoxFlags)(1ull<<48) +# define UI_BoxFlag_RoundChildrenByParent (UI_BoxFlags)(1ull<<49) //- rjf: bundles # define UI_BoxFlag_Clickable (UI_BoxFlag_MouseClickable|UI_BoxFlag_KeyboardClickable) @@ -493,6 +494,7 @@ struct UI_State //- rjf: user interaction state UI_Key hot_box_key; UI_Key active_box_key[UI_MouseButtonKind_COUNT]; + UI_Key drop_hot_box_key; UI_Key clipboard_copy_key; U64 press_timestamp_history_us[UI_MouseButtonKind_COUNT][3]; UI_Key press_key_history[UI_MouseButtonKind_COUNT][3]; @@ -617,6 +619,7 @@ internal String8 ui_icon_string_from_kind(UI_IconKind icon_kind); internal F32 ui_dt(void); //- rjf: drag data +internal Vec2F32 ui_drag_start_mouse(void); internal Vec2F32 ui_drag_delta(void); internal void ui_store_drag_data(String8 string); internal String8 ui_get_drag_data(U64 min_required_size); @@ -630,6 +633,7 @@ internal D_FancyRunList ui_string_hover_runs(Arena *arena); //- rjf: interaction keys internal UI_Key ui_hot_key(void); internal UI_Key ui_active_key(UI_MouseButtonKind button_kind); +internal UI_Key ui_drop_hot_key(void); //- rjf: controls over interaction internal void ui_kill_action(void);