fixed image problems

This commit is contained in:
aap 2020-07-23 12:36:43 +02:00
parent 01f021fdbf
commit 4946235d49
2 changed files with 24 additions and 12 deletions

View File

@ -411,6 +411,7 @@ Image::convertTo32(void)
} }
newpixels = rwNewT(uint8, newstride*this->height, MEMDUR_EVENT | ID_IMAGE); newpixels = rwNewT(uint8, newstride*this->height, MEMDUR_EVENT | ID_IMAGE);
uint8 *pixels32 = newpixels;
for(int y = 0; y < this->height; y++){ for(int y = 0; y < this->height; y++){
uint8 *line = pixels; uint8 *line = pixels;
uint8 *newline = newpixels; uint8 *newline = newpixels;
@ -429,7 +430,7 @@ Image::convertTo32(void)
this->stride = newstride; this->stride = newstride;
this->pixels = nil; this->pixels = nil;
this->palette = nil; this->palette = nil;
this->setPixels(newpixels); this->setPixels(pixels32);
} }
void void

View File

@ -94,7 +94,7 @@ readTGA(const char *filename)
assert(palDepth == 24 || palDepth == 32); assert(palDepth == 24 || palDepth == 32);
}else{ }else{
depth = header.depth; depth = header.depth;
assert(depth == 24 || depth == 32); assert(depth == 16 || depth == 24 || depth == 32);
} }
image = Image::create(header.width, header.height, depth); image = Image::create(header.width, header.height, depth);
@ -125,16 +125,28 @@ readTGA(const char *filename)
for(int y = 0; y < image->height; y++){ for(int y = 0; y < image->height; y++){
uint8 *line = pixels; uint8 *line = pixels;
for(int x = 0; x < image->width; x++){ for(int x = 0; x < image->width; x++){
if(palette) switch(image->depth){
*line++ = file.readU8(); case 4:
else{ case 8:
line[0] = file.readU8();
break;
case 16:
line[0] = file.readU8();
line[1] = file.readU8();
break;
case 24:
line[2] = file.readU8(); line[2] = file.readU8();
line[1] = file.readU8(); line[1] = file.readU8();
line[0] = file.readU8(); line[0] = file.readU8();
line += 3; break;
if(depth == 32) case 32:
*line++ = file.readU8(); line[2] = file.readU8();
line[1] = file.readU8();
line[0] = file.readU8();
line[3] = file.readU8();
break;
} }
line += image->bpp;
} }
pixels += (header.descriptor&0x20) ? pixels += (header.descriptor&0x20) ?
image->stride : -image->stride; image->stride : -image->stride;
@ -187,26 +199,25 @@ writeTGA(Image *image, const char *filename)
switch(image->depth){ switch(image->depth){
case 4: case 4:
case 8: case 8:
file.writeU8(*p++); file.writeU8(p[0]);
break; break;
case 16: case 16:
file.writeU8(p[0]); file.writeU8(p[0]);
file.writeU8(p[1]); file.writeU8(p[1]);
p += 2;
break; break;
case 24: case 24:
file.writeU8(p[2]); file.writeU8(p[2]);
file.writeU8(p[1]); file.writeU8(p[1]);
file.writeU8(p[0]); file.writeU8(p[0]);
p += 3;
break; break;
case 32: case 32:
file.writeU8(p[2]); file.writeU8(p[2]);
file.writeU8(p[1]); file.writeU8(p[1]);
file.writeU8(p[0]); file.writeU8(p[0]);
file.writeU8(p[3]); file.writeU8(p[3]);
p += 4; break;
} }
p += image->bpp;
} }
line += image->stride; line += image->stride;
} }