#ifndef HYPERDRM_SOURCE_BRIDGE_H #define HYPERDRM_SOURCE_BRIDGE_H static unsigned bridge_phase,bridge_sequence; static uint64_t bridge_started,bridge_clear_at,bridge_fade_at,bridge_last_sent; static unsigned char bridge_from[16][3],bridge_to[16][3]; static CaptureSource bridge_source; static char *region_command(const unsigned char colors[16][3],const LedBlend *mapping,unsigned count,unsigned duration){ if(!count || !mapping)return NULL; if(!strcmp(target.receiver,"HyperHDR"))return spatial_image_command_duration(colors,PRIORITY,duration); size_t capacity=256+(size_t)count*12;char *line=malloc(capacity);if(!line)return NULL; size_t n=(size_t)snprintf(line,capacity,"{\"command\":\"color\",\"priority\":%d,\"duration\":%u,\"origin\":\"HyperDRM\",\"color\":[",PRIORITY,duration); for(unsigned i=0;i=3000){if(bridge_clear())bridge_phase=0;return;} if(bridge_phase==1 && capture_source==SOURCE_PICCAP && piccap_connected && stream.stage==4){ if(bridge_clear()){bridge_sequence=stream.sequence;bridge_clear_at=now;bridge_phase=2;} }else if(bridge_phase==1 && now-bridge_last_sent>=100 && stream.stage==4){ if(bridge_send(bridge_from))bridge_last_sent=now; }else if(bridge_phase==2 && stream.valid && stream.sequence>bridge_sequence && stream.updated>=bridge_clear_at+150){ memcpy(bridge_to,stream.colors,sizeof(bridge_to));bridge_fade_at=now;bridge_phase=3; bool black=true;for(unsigned r=0;r<16;r++)for(unsigned c=0;c<3;c++)if(bridge_to[r][c]>3)black=false; if(black)bridge_phase=0; } if(bridge_phase==3 && now-bridge_last_sent>=100){ if(now-bridge_fade_at>=500){if(bridge_clear())bridge_phase=0;} else {unsigned char colors[16][3];continuity_mix(bridge_from,bridge_to,(unsigned)(now-bridge_fade_at),colors);if(bridge_send(colors))bridge_last_sent=now;} } } #endif