for(i=0;i<d3_l->max_x;i++)
{
sum=*(d3_l->extra+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y);
- sum=sum*255/max;
- memset(buf+1,(unsigned char)sum,2);
- buf[0]=0xff;
+ sum=sum*500/max;
+ buf[2]=0;
+ if(sum<=255) {
+ buf[1]=0;
+ buf[0]=sum;
+ } else {
+ buf[1]=(sum-255);
+ buf[0]=0xff;
+ }
if(write(fd,buf,3)<3)
{
puts("failed writing rgb values to bmp file");
for(i=0;i<d3_l->max_x;i++)
{
sum=*(d3_l->extra+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y);
- sum=sum*255/max;
- memset(buf+1,(unsigned char)sum,2);
- buf[0]=0xff;
+ sum=sum*500/max;
+ buf[2]=0;
+ if(sum<=255) {
+ buf[1]=0;
+ buf[0]=sum;
+ } else {
+ buf[1]=(sum-255);
+ buf[0]=0xff;
+ }
if(write(fd,buf,3)<3)
{
puts("failed writing rgb values to bmp file");
for(i=0;i<d3_l->max_x;i++)
{
sum=*(d3_l->extra+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y);
- sum=sum*255/max;
- memset(buf+1,(unsigned char)sum,2);
- buf[0]=0xff;
+ sum=sum*500/max;
+ buf[2]=0;
+ if(sum<=255) {
+ buf[1]=0;
+ buf[0]=sum;
+ } else {
+ buf[1]=(sum-255);
+ buf[0]=0xff;
+ }
if(write(fd,buf,3)<3)
{
puts("failed writing rgb values to bmp file");