From: ehofman Date: Thu, 13 Jan 2005 18:35:56 +0000 (+0000) Subject: Some small updates to the saving code. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=463ca207ce57d073deaaa69b780bcdd1488fee7e;p=simgear.git Some small updates to the saving code. --- diff --git a/simgear/screen/texture.cxx b/simgear/screen/texture.cxx index f2062d9e..67c5900e 100644 --- a/simgear/screen/texture.cxx +++ b/simgear/screen/texture.cxx @@ -429,50 +429,16 @@ SGTexture::read_r8_texture(const char *name) void SGTexture::write_texture(const char *name) { - SGTexture::ImageRec *image; - int x, y; - - image=ImageWriteOpen(name); - - GLubyte *ptr = texture_data; - for (y=0; ytmp[x]=*ptr; - ptr = ptr + num_colors; - } - fwrite(image->tmp, 1, texture_width, image->file); - } - - if (num_colors > 1) { - ptr = texture_data + 1; - for (y=0; ytmp[x]=*ptr; - ptr = ptr + num_colors; - } - fwrite(image->tmp, 1, texture_width, image->file); - } - - if (num_colors > 2) { - ptr = texture_data + 2; - for (y=0; ytmp[x]=*ptr; - ptr = ptr + num_colors; - } - fwrite(image->tmp, 1, texture_width, image->file); - } - - if (num_colors > 3) { - ptr = texture_data + 3; - for (y=0; ytmp[x]=*ptr; - ptr = ptr + num_colors; - } - fwrite(image->tmp, 1, texture_width, image->file); - } + SGTexture::ImageRec *image = ImageWriteOpen(name); + + for (int c=0; ctmp[x]=*ptr; + ptr = ptr + num_colors; } + fwrite(image->tmp, 1, texture_width, image->file); } } @@ -655,14 +621,14 @@ SGTexture::ImageWriteOpen(const char *fileName) errstr = OUT_OF_MEMORY; return 0; } - if ((image->file = fopen(fileName, "w")) == 0) { + if ((image->file = fopen(fileName, "wb")) == 0) { errstr = FILE_OPEN_ERROR; return 0; } image->imagic = 474; image->type = 0x0001; - image->dim = 0; + image->dim = (num_colors > 1) ? 3 : 2; image->xsize = texture_width; image->ysize = texture_height; image->zsize = num_colors; @@ -670,6 +636,7 @@ SGTexture::ImageWriteOpen(const char *fileName) fwrite(image, 1, 12, image->file); fseek(image->file, 512, SEEK_SET); + if (swapFlag) { ConvertShort(&image->imagic, 6); } @@ -690,13 +657,14 @@ SGTexture::ImageWriteOpen(const char *fileName) } image->rleEnd = 512 + (2 * x); fseek(image->file, 512, SEEK_SET); - fread(image->rowStart, 1, x, image->file); - fread(image->rowSize, 1, x, image->file); + fwrite(image->rowStart, 1, x, image->file); + fwrite(image->rowSize, 1, x, image->file); if (swapFlag) { ConvertUint(image->rowStart, x/(int) sizeof(unsigned)); ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int)); } } + return image; }