Restore original saturation and brightness

This commit is contained in:
matze19999 committed 2026-10-06 16:23:09 +02:00
1 parent 81087448b2
commit c3a2ac8002
9 files changed
+16 -25

No files matched your search

+2 -11
View File
@@ -1,16 +1,7 @@
#ifndef COLOR_BOOST_H
#define COLOR_BOOST_H
/* HSV saturation x2 and value x1.33, preserving hue and clamping value. */
/* Preserve the original saturation and brightness. */
static inline void boost_color(const unsigned char in[3],unsigned char out[3]){
unsigned lo=in[0],hi=in[0];
for(unsigned c=1;c<3;c++){if(in[c]<lo)lo=in[c];if(in[c]>hi)hi=in[c];}
unsigned chroma=hi-lo;
unsigned peak=(hi*133+50)/100;if(peak>255)peak=255;
if(!chroma){for(unsigned c=0;c<3;c++)out[c]=(unsigned char)peak;return;}
unsigned expanded=chroma*2;if(expanded>hi)expanded=hi;
for(unsigned c=0;c<3;c++){
unsigned value=hi-expanded+((in[c]-lo)*expanded+chroma/2)/chroma;
out[c]=(unsigned char)((value*peak+hi/2)/hi);
}
for(unsigned c=0;c<3;c++)out[c]=in[c];
}
#endif
+2 -2
View File
@@ -175,11 +175,11 @@ static bool handover(void *h,void *m,void *ctx){
static bool status(void *h,void *m,void *ctx){
(void)ctx;char json[4096],safe[512];size_t n=0;
for(size_t i=0;last_error[i] && n+2<sizeof(safe);i++){char c=last_error[i];if(c=='"'||c=='\\')safe[n++]='\\';if((unsigned char)c>=32)safe[n++]=c;}safe[n]=0;
int used=snprintf(json,sizeof(json),"{\"returnValue\":true,\"version\":\"0.7.1\",\"running\":%s,\"colorValid\":%s,\"frames\":%lu,\"captureRecoveries\":%u,\"lastRecoveryMs\":%llu,\"endpoint\":\"127.0.0.1:19444\",\"priority\":%d,\"uid\":%u,\"drmVerified\":false,\"mappingVerified\":false,\"outputColor\":[%u,%u,%u],\"error\":\"%s\",\"regions\":[",(capture||capture_source==SOURCE_PICCAP)?"true":"false",color_valid?"true":"false",frames,capture_recoveries,(unsigned long long)last_recovery_ms,PRIORITY,(unsigned)geteuid(),sent_rgb[0],sent_rgb[1],sent_rgb[2],safe);
int used=snprintf(json,sizeof(json),"{\"returnValue\":true,\"version\":\"0.7.2\",\"running\":%s,\"colorValid\":%s,\"frames\":%lu,\"captureRecoveries\":%u,\"lastRecoveryMs\":%llu,\"endpoint\":\"127.0.0.1:19444\",\"priority\":%d,\"uid\":%u,\"drmVerified\":false,\"mappingVerified\":false,\"outputColor\":[%u,%u,%u],\"error\":\"%s\",\"regions\":[",(capture||capture_source==SOURCE_PICCAP)?"true":"false",color_valid?"true":"false",frames,capture_recoveries,(unsigned long long)last_recovery_ms,PRIORITY,(unsigned)geteuid(),sent_rgb[0],sent_rgb[1],sent_rgb[2],safe);
for(int i=0;i<16;i++)used+=snprintf(json+used,sizeof(json)-used,"%s[%u,%u,%u]",i?",":"",rgb[i][0],rgb[i][1],rgb[i][2]);
used+=snprintf(json+used,sizeof(json)-used,"],\"ledCount\":%u,\"spatialOutput\":%s,\"blackPercent\":[",led_count,led_count?"true":"false");
for(int i=0;i<16;i++)used+=snprintf(json+used,sizeof(json)-used,"%s%u",i?",":"",black_percent[i]);
snprintf(json+used,sizeof(json)-used,"],\"preset\":%u,\"saturationGain\":2.0,\"brightnessGain\":1.33,\"spatialInterpolation\":%s,\"blackBarDetection\":true,\"autostart\":%s,\"retryScheduled\":%s,\"retryPaused\":%s,\"retryBlocked\":%s,\"retryAttempts\":%u,\"piccapInstalled\":%s,\"piccapHandover\":%s,\"piccapConnected\":%s,\"activeSource\":\"%s\",\"playbackProtection\":\"%s\",\"letterboxDetected\":%s}",capture_preset,interpolation_enabled?"true":"false",boot_enabled()?"true":"false",retries.due?"true":"false",retries.paused?"true":"false",retries.blocked?"true":"false",retries.attempts,piccap_installed()?"true":"false",handover_enabled?"true":"false",piccap_connected?"true":"false",piccap_owned?"PicCap":"HyperDRM",protection==PLAYBACK_PROTECTED?"protected":protection==PLAYBACK_CLEAR?"non-secure decoder":"unknown",capture&&letterbox_mode?"true":"false");return respond(h,m,json);
snprintf(json+used,sizeof(json)-used,"],\"preset\":%u,\"saturationGain\":1.0,\"brightnessGain\":1.0,\"spatialInterpolation\":%s,\"blackBarDetection\":true,\"autostart\":%s,\"retryScheduled\":%s,\"retryPaused\":%s,\"retryBlocked\":%s,\"retryAttempts\":%u,\"piccapInstalled\":%s,\"piccapHandover\":%s,\"piccapConnected\":%s,\"activeSource\":\"%s\",\"playbackProtection\":\"%s\",\"letterboxDetected\":%s}",capture_preset,interpolation_enabled?"true":"false",boot_enabled()?"true":"false",retries.due?"true":"false",retries.paused?"true":"false",retries.blocked?"true":"false",retries.attempts,piccap_installed()?"true":"false",handover_enabled?"true":"false",piccap_connected?"true":"false",piccap_owned?"PicCap":"HyperDRM",protection==PLAYBACK_PROTECTED?"protected":protection==PLAYBACK_CLEAR?"non-secure decoder":"unknown",capture&&letterbox_mode?"true":"false");return respond(h,m,json);
}
static int tick(void *unused){
(void)unused;
+4 -4
View File
@@ -5,16 +5,16 @@ int main(void){
unsigned char out[3];
for(unsigned v=0;v<256;v++){
unsigned char gray[3]={v,v,v};boost_color(gray,out);
unsigned expected=(v*133+50)/100;if(expected>255)expected=255;
unsigned expected=v;
assert(out[0]==expected && out[1]==expected && out[2]==expected);
}
unsigned char cyan[3]={93,224,242};boost_color(cyan,out);
assert(out[0]<93 && out[1]>out[0] && out[1]<out[2] && out[2]==255);
assert(out[0]==93 && out[1]==224 && out[2]==242);
for(unsigned c=0;c<3;c++){
unsigned char primary[3]={0};primary[c]=255;boost_color(primary,out);
for(unsigned j=0;j<3;j++)assert(out[j]==primary[j]);
}
unsigned char warm[3]={171,82,0};boost_color(warm,out);
assert(out[0]==227 && out[1]>82 && out[2]==0);
puts("PASS: neutral grays, stronger cyan, brighter warm color, clamped primaries");
assert(out[0]==171 && out[1]==82 && out[2]==0);
puts("PASS: neutral grays, unchanged cyan, warm color and primaries");
}