Skip to content

Commit

Permalink
Added the ability to decode a FLIF file directly from a FILE* pointer…
Browse files Browse the repository at this point in the history
… to the API

Added #includes for stdio.h
  • Loading branch information
Traneptora committed May 17, 2017
1 parent 3f3fb63 commit 52622e4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/library/flif-interface-private_dec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ limitations under the License.

#pragma once

#include <stdio.h>

#include "flif-interface-private_common.hpp"
#include "../flif-dec.hpp"

Expand All @@ -26,6 +28,7 @@ struct FLIF_DECODER
FLIF_DECODER();

int32_t decode_file(const char* filename);
int32_t decode_filepointer(FILE *file, const char* filename);
int32_t decode_memory(const void* buffer, size_t buffer_size_bytes);
int32_t abort();
size_t num_images();
Expand Down
27 changes: 24 additions & 3 deletions src/library/flif-interface_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include <stdio.h>

#include "flif-interface-private_dec.hpp"
#include "flif-interface_common.cpp"

Expand All @@ -31,12 +33,17 @@ FLIF_DECODER::FLIF_DECODER()


int32_t FLIF_DECODER::decode_file(const char* filename) {
internal_images.clear();
images.clear();

FILE *file = fopen(filename,"rb");
if(!file)
return 0;

return decode_filepointer(file, filename);
}

int32_t FLIF_DECODER::decode_filepointer(FILE *file, const char *filename) {
internal_images.clear();
images.clear();

FileIO fio(file, filename);

working = true;
Expand Down Expand Up @@ -207,6 +214,20 @@ FLIF_DLLEXPORT int32_t FLIF_API flif_decoder_decode_file(FLIF_DECODER* decoder,
return 0;
}

/*!
* The filename here is used for error messages.
* It would be helpful to pass an actual filename here, but a non-NULL dummy one can be used instead.
* \return non-zero if the function succeeded
*/
FLIF_DLLEXPORT int32_t FLIF_API flif_decoder_decode_filepointer(FLIF_DECODER* decoder, FILE* filepointer, const char *filename) {
try
{
return decoder->decode_filepointer(filepointer, filename);
}
catch(...) {}
return 0;
}

/*!
* \return non-zero if the function succeeded
*/
Expand Down
9 changes: 9 additions & 0 deletions src/library/flif_dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include <stdio.h>

#include "flif_common.h"

#ifdef __cplusplus
Expand All @@ -38,6 +40,13 @@ extern "C" {
// decode a FLIF blob in memory: buffer should point to the blob and buffer_size_bytes should be its size
FLIF_DLLIMPORT int32_t FLIF_API flif_decoder_decode_memory(FLIF_DECODER* decoder, const void* buffer, size_t buffer_size_bytes);

/*
* Decode a given FLIF from a file pointer
* The filename here is used for error messages.
* It would be helpful to pass an actual filename here, but a non-NULL dummy one can be used instead.
*/
FLIF_DLLIMPORT int32_t FLIF_API flif_decoder_decode_filepointer(FLIF_DECODER* decoder, FILE *filepointer, const char *filename);

// returns the number of frames (1 if it is not an animation)
FLIF_DLLIMPORT size_t FLIF_API flif_decoder_num_images(FLIF_DECODER* decoder);
// only relevant for animations: returns the loop count (0 = loop forever)
Expand Down

0 comments on commit 52622e4

Please sign in to comment.