@@ -50,7 +50,7 @@ image_c::~image_c()
5050
5151void image_c::CopyRaw (int inType, dword inWidth, dword inHeight, const byte* inDat)
5252{
53- if (dat) delete dat;
53+ if (dat) delete[] dat;
5454 comp = inType & 0xF ;
5555 type = inType;
5656 width = inWidth;
@@ -61,7 +61,7 @@ void image_c::CopyRaw(int inType, dword inWidth, dword inHeight, const byte* inD
6161
6262void image_c::Free ()
6363{
64- delete dat;
64+ delete[] dat;
6565 dat = NULL ;
6666}
6767
@@ -188,7 +188,7 @@ bool targa_c::Load(const char* fileName)
188188 int rlen = ((rlehdr & 0x7F ) + 1 ) * comp;
189189 if (x + rlen > rowSize) {
190190 con->Warning (" TGA '%s': invalid RLE coding (overlong row)" , fileName);
191- delete dat;
191+ delete[] dat;
192192 return true ;
193193 }
194194 if (rlehdr & 0x80 ) {
@@ -225,7 +225,22 @@ bool targa_c::Load(const char* fileName)
225225
226226bool targa_c::Save (const char * fileName)
227227{
228- return true ;
228+ if (type != IMGTYPE_RGB && type != IMGTYPE_RGBA) {
229+ return true ;
230+ }
231+
232+ // Open file
233+ fileOutputStream_c out;
234+ if (out.FileOpen (fileName, true )) {
235+ return true ;
236+ }
237+
238+ auto rc = stbi_write_tga_to_func ([](void * ctx, void * data, int size) {
239+ auto out = (fileOutputStream_c*)ctx;
240+ out->Write (data, size);
241+ }, &out, width, height, comp, dat);
242+
243+ return !rc;
229244}
230245
231246bool targa_c::ImageInfo (const char * fileName, imageInfo_s* info)
@@ -277,14 +292,14 @@ bool jpeg_c::Load(const char* fileName)
277292 return true ;
278293 }
279294 int x, y, in_comp;
280- if (!stbi_info_from_memory (fileData.data (), fileData.size (), &x, &y, &in_comp)) {
295+ if (!stbi_info_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &in_comp)) {
281296 return true ;
282297 }
283298 if (in_comp != 1 && in_comp != 3 ) {
284299 con->Warning (" JPEG '%s': unsupported component count '%d'" , fileName, comp);
285300 return true ;
286301 }
287- stbi_uc* data = stbi_load_from_memory (fileData.data (), fileData.size (), &x, &y, &in_comp, in_comp);
302+ stbi_uc* data = stbi_load_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &in_comp, in_comp);
288303 if (!data) {
289304 stbi_image_free (data);
290305 return true ;
@@ -335,7 +350,7 @@ bool jpeg_c::ImageInfo(const char* fileName, imageInfo_s* info)
335350 return true ;
336351 }
337352 int x, y, comp;
338- if (stbi_info_from_memory (fileData.data (), fileData.size (), &x, &y, &comp)) {
353+ if (stbi_info_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &comp)) {
339354 return true ;
340355 }
341356
@@ -366,14 +381,14 @@ bool png_c::Load(const char* fileName)
366381 return true ;
367382 }
368383 int x, y, in_comp;
369- if (!stbi_info_from_memory (fileData.data (), fileData.size (), &x, &y, &in_comp)) {
384+ if (!stbi_info_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &in_comp)) {
370385 return true ;
371386 }
372387 width = x;
373388 height = y;
374389 comp = (in_comp == 1 || in_comp == 3 ) ? 3 : 4 ;
375390 type = comp == 3 ? IMGTYPE_RGB : IMGTYPE_RGBA;
376- stbi_uc* data = stbi_load_from_memory (fileData.data (), fileData.size (), &x, &y, &in_comp, comp);
391+ stbi_uc* data = stbi_load_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &in_comp, comp);
377392 if (!data) {
378393 stbi_image_free (data);
379394 return true ;
@@ -420,7 +435,7 @@ bool png_c::ImageInfo(const char* fileName, imageInfo_s* info)
420435 return true ;
421436 }
422437 int x, y, comp;
423- if (stbi_info_from_memory (fileData.data (), fileData.size (), &x, &y, &comp)) {
438+ if (stbi_info_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &comp)) {
424439 return true ;
425440 }
426441
@@ -449,7 +464,7 @@ bool gif_c::Load(const char* fileName)
449464 return true ;
450465 }
451466 int x, y, in_comp;
452- stbi_uc* data = stbi_load_from_memory (fileData.data (), fileData.size (), &x, &y, &in_comp, 4 );
467+ stbi_uc* data = stbi_load_from_memory (fileData.data (), ( int ) fileData.size (), &x, &y, &in_comp, 4 );
453468 if (!data || in_comp != 4 ) {
454469 stbi_image_free (data);
455470 return true ;
0 commit comments