Volver al índice
docs/publicacion/ExposedSkinAudit.java
import ar.com.companeros.identity.HostSkinAtlas;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.Arrays;
import javax.imageio.ImageIO;
/** Checks pixel provenance; arbitrary skin colours and clothing remain valid. */
public final class ExposedSkinAudit {
private static long checks;
private static void require(boolean condition, String message) {
checks++;
if (!condition) throw new AssertionError(message);
}
private static void fillBase(int[] pixels, int height, int u, int v, int width, int h) {
for (int y=v; y<Math.min(height,v+h); y++) for (int x=u; x<u+width; x++)
pixels[y*64+x]=0xFF000000 | (x+1)<<16 | (y+1)<<8 | ((x*13+y)&255);
}
private static int[] synthetic(int height, boolean slim, boolean blueHands) {
int[] pixels=new int[64*height];
fillBase(pixels,height,0,0,32,16); fillBase(pixels,height,0,16,56,16);
if (height==64) {
fillBase(pixels,height,16,48,32,16);
// A genuine second layer must survive flattening unchanged by this correction.
pixels[42*64+44]=0x8000CCFF;
pixels[58*64+52]=0x90CC00FF;
}
if (slim) {
for(int y=20;y<32;y++) {pixels[y*64+54]=0;pixels[y*64+55]=0;}
for(int y=52;y<64;y++) {pixels[y*64+46]=0;pixels[y*64+47]=0;}
}
if(blueHands) {
for(int y=26;y<32;y++) for(int x=40;x<56;x++) pixels[y*64+x]=0xFF0066FF;
for(int y=16;y<20;y++) for(int x=48;x<52;x++) pixels[y*64+x]=0xFF0066FF;
for(int y=58;y<64;y++) for(int x=32;x<48;x++) pixels[y*64+x]=0xFF0066FF;
for(int y=48;y<52;y++) for(int x=40;x<44;x++) pixels[y*64+x]=0xFF0066FF;
}
return pixels;
}
private static void patch(int[] current,int[] baseline,int sx,int sy,int dx,int dy,int w,int h,String label) {
for(int y=0;y<h;y++) for(int x=0;x<w;x++)
require(current[(dy+y)*128+dx+x]==baseline[(sy+y)*128+sx+x],label+" differs at "+x+","+y);
}
private static void arm(int[] current,int[] baseline,int u,int v,int target,String label) {
String[] sides={"outer","front","inner","back"};
for(int face=0;face<4;face++) patch(current,baseline,u+face*4,v+10,target+face*4,4,4,6,label+" "+sides[face]);
patch(current,baseline,u+4,v+12,target+4,0,4,4,label+" elbow end");
patch(current,baseline,u+8,v,target+8,0,4,4,label+" wrist end");
}
public static void main(String[] args) throws Exception {
BufferedImage reference=ImageIO.read(new File(args[1]));
int[] steve=reference.getRGB(0,0,64,64,null,0,64);
int[][] sources={synthetic(32,false,false),synthetic(64,false,false),synthetic(64,true,false),steve,synthetic(64,false,true)};
String[] names={"legacy32","standard64_overlay","slim64_overlay","vanilla_steve","blue_custom_skin"};
int[] heights={32,64,64,64,64};
int cases=0;
try(var loader=new URLClassLoader(new java.net.URL[]{Path.of(args[0]).toUri().toURL()},null)) {
var original=loader.loadClass("ar.com.companeros.identity.HostSkinAtlas").getMethod("compose",int[].class,int.class,int.class);
for(int input=0;input<sources.length;input++) for(int stage=0;stage<5;stage++) {
int[] pixels=sources[input].clone(),saved=pixels.clone();
int[] before=(int[])original.invoke(null,pixels.clone(),heights[input],stage);
int[] atlas=HostSkinAtlas.compose(pixels,heights[input],stage);
require(Arrays.equals(saved,pixels),names[input]+" input mutated");
for(int y=0;y<64;y++) for(int x=0;x<64;x++)
require(atlas[y*128+x]==before[y*128+x],names[input]+" original skin changed at "+x+","+y+" stage "+stage);
arm(atlas,before,40,16,64,names[input]+" right arm");
arm(atlas,before,32,48,80,names[input]+" left arm");
for(int y=0;y<8;y++) for(int x=0;x<16;x++)
require(atlas[(12+y)*128+64+x]==before[(28+y%4)*128+44+x%4],names[input]+" neck tile differs");
if(input==3 && stage==0) {
// An exact positional regression, not a cyan colour filter.
require(before[22*128+48]!=atlas[0*128+72],"Steve wrist still samples the sleeve's first texel");
}
if(input==4 && stage==0)
require(atlas[72]==0xFF0066FF,"Legitimate blue custom hand was recoloured");
cases++;
}
}
System.out.println("{\"passed\":true,\"cases\":"+cases+",\"pixel_and_input_checks\":"+checks+",\"stages_per_skin\":5,\"skin_types\":[\"legacy32\",\"standard64_overlay\",\"slim64_overlay\",\"vanilla_steve\",\"blue_custom_skin\"],\"input_immutable\":true,\"original_64x64_unchanged\":true,\"six_arm_faces_match_anatomical_sources\":true,\"neck_matches_host_hand_skin\":true,\"custom_blue_preserved\":true}");
}
}