as converting a 24-bit image to 12 bits?
in
Programming Questions
•
4 months ago
as converting a 24-bit image to 12 bits?
hello, here I made a Boseto on how to convert. I have party
that 12 bits = 4 bits (red) +4 bits (green) +4 bits (blue), and 16 colors, rgb channel.
the problem as you can see it takes rojisos tones (red).
How can solve this?
hello, here I made a Boseto on how to convert. I have party
that 12 bits = 4 bits (red) +4 bits (green) +4 bits (blue), and 16 colors, rgb channel.
the problem as you can see it takes rojisos tones (red).
How can solve this?
- size(800,405);
PImage myImage = loadImage("http://files.vividscreen.com/soft/cf900f8a80efde07b94c19211830d059/Naruto-Forever-128x128th.jpg");
image(myImage, 0, 0);
int count=0;
int buff[]=new int [myImage.width*myImage.height*3];
int bu[]=new int [myImage.width*myImage.height*3];
////////////////////////////////////////////////////////
myImage.loadPixels();
for (int i = 0; i < myImage.width*myImage.width; i++) {
myImage.pixels[i] = myImage.pixels[i];
int R = int (red(myImage.pixels[i]));
int G = int (green(myImage.pixels[i]));
int B = int (blue(myImage.pixels[i]));
buff[count]=R;
buff[count+1]=G;
buff[count+2]=B;
count=count+3;
}
myImage.updatePixels();
//////////////////////////////////////////////////////////////////////////////
int buff12bits[]={0,17,34,48,68,85,102,119,136,153,170,187,204,221,238,255};
for(int ic=0;ic<myImage.width*myImage.height*3;ic++){
if( buff[ic] >=0 && buff[ic] <16 ){
bu[ic]=0;
}
if( buff[ic] >=16 && buff[ic] <32 ){
bu[ic]=1;
}
if( buff[ic] >=32 && buff[ic] <48 ){
bu[ic]=2;
}
if( buff[ic] >=48 && buff[ic] <64 ){
bu[ic]=3;
}
if( buff[ic] >=64 && buff[ic] <80 ){
bu[ic]=4;
}
if( buff[ic] >=80 && buff[ic] <96 ){
bu[ic]=5;
}
if( buff[ic] >=96 && buff[ic] <112 ){
bu[ic]=6;
}
if( buff[ic] >=112 && buff[ic] <128 ){
bu[ic]=7;
}
if( buff[ic] >=128 && buff[ic] <144 ){
bu[ic]=8;
}
if( buff[ic] >=144 && buff[ic] <160 ){
buff[ic]=9;
}
if( buff[ic] >=160 && buff[ic] <176 ){
bu[ic]=10;
}
if( buff[ic] >=176 && buff[ic] <192 ){
bu[ic]=11;
}
if( buff[ic] >=192 && buff[ic] <208 ){
bu[ic]=12;
}
if( buff[ic] >=208 && buff[ic] <224 ){
bu[ic]=13;
}
if( buff[ic] >=224 && buff[ic] <240 ){
bu[ic]=14;
}
if( buff[ic] >=240 ){
bu[ic]=15;
}
}
////////////////////////////////////////////////////////////////////////////////////
int color12bits[]=new int [myImage.width*myImage.height];
int p=0;
///////////////////////////////////////////////////////
for(int i=0;i<myImage.width*myImage.height*3;i+=3){
color12bits[p]= color( buff12bits[ bu[i] ],buff12bits[ bu[i+1] ],buff12bits[ bu[i+2] ]);
p++;
}
/////////////////////////////////////////////////////////////////////////////////
myImage.loadPixels();
for (int i = 0; i < myImage.width*myImage.width; i++) {
//int buff12bits[]={0,17,34,48,68,85,102,119,136,153,170,187,204,221,238,255};
myImage.pixels[i] =color12bits[i];
}
myImage.updatePixels();
image(myImage, 320, 0);
1