diff options
author | Lukas Rusak <lorusak@gmail.com> | 2023-04-13 11:57:49 -0700 |
---|---|---|
committer | Lukas Rusak <lorusak@gmail.com> | 2023-04-23 21:03:27 -0700 |
commit | 17800acac12edb0c692037e35f50f4547cfc3fdc (patch) | |
tree | d9f825bb920fd6c10e6aea29c55fa24f810212f6 /tools/depends/native/TexturePacker/src | |
parent | 71c2cf89c4fefa5ac84725e035ccb8cfc06125e8 (diff) |
TexturePacker: JPGDecoder: use CFile as an object
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Diffstat (limited to 'tools/depends/native/TexturePacker/src')
-rw-r--r-- | tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp index fb51dd3d8c..467cfe0cc9 100644 --- a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp +++ b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp @@ -22,19 +22,21 @@ #include "SimpleFS.h" +#include <memory> + #include <jpeglib.h> bool JPGDecoder::CanDecode(const std::string &filename) { - CFile *fp = new CFile(); + CFile fp; bool ret = false; unsigned char magic[2]; - if (fp->Open(filename)) + if (fp.Open(filename)) { //JPEG image files begin with FF D8 and end with FF D9. // check for FF D8 big + little endian on start - uint64_t readbytes = fp->Read(magic, 2); + uint64_t readbytes = fp.Read(magic, 2); if (readbytes == 2) { if ((magic[0] == 0xd8 && magic[1] == 0xff) || @@ -46,9 +48,9 @@ bool JPGDecoder::CanDecode(const std::string &filename) { ret = false; //check on FF D9 big + little endian on end - uint64_t fileSize = fp->GetFileSize(); - fp->Seek(fileSize - 2); - readbytes = fp->Read(magic, 2); + uint64_t fileSize = fp.GetFileSize(); + fp.Seek(fileSize - 2); + readbytes = fp.Read(magic, 2); if (readbytes == 2) { if ((magic[0] == 0xd9 && magic[1] == 0xff) || @@ -57,19 +59,17 @@ bool JPGDecoder::CanDecode(const std::string &filename) } } } - delete fp; + return ret; } bool JPGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) { #define WIDTHBYTES(bits) ((((bits) + 31) / 32) * 4) - CFile *arq = new CFile(); - if (!arq->Open(filename)) - { - delete arq; + + CFile arq; + if (!arq.Open(filename)) return false; - } struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -79,7 +79,7 @@ bool JPGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, arq->getFP()); + jpeg_stdio_src(&cinfo, arq.getFP()); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); @@ -119,7 +119,6 @@ bool JPGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) frames.frameList.push_back(frame); - delete arq; return true; } |