Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added decoding directly from a FILE* pointer to the API #423

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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