/* ***************************************************************************** * libg1m.h -- libg1m main public header. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. * libg1m is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3.0 of the License, * or (at your option) any later version. * * libg1m is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * * WARNING: Do NOT include this header using ! * * Compile using one of these: * * libg1m-config --cflags * pkg-config libg1m --cflags * * and include using . * ************************************************************************** */ #ifndef LIBG1M_H # define LIBG1M_H # include # include # include # include # include # include # include # include # ifdef __cplusplus extern "C" { # endif /* ************************************************************************** */ /* Errors */ /* ************************************************************************** */ /* WARNING: Whenever you add/remove errors, think about updating core/strerror! * --- * First, the none error. */ # define g1m_noerror 0x00 # define g1m_error_none 0x00 # define g1m_error_success 0x00 /* Then, the miscallenous errors */ # define g1m_error_unknown 0x01 # define g1m_error_alloc 0x02 # define g1m_error_op 0x03 /* Then, the stream errors */ # define g1m_error_nostream 0x10 # define g1m_error_noread 0x11 # define g1m_error_noseek 0x12 /* unused for now */ # define g1m_error_nowrite 0x13 # define g1m_error_read 0x14 # define g1m_error_write 0x15 /* Then, the decoding errors */ # define g1m_error_unrecognized 0x20 # define g1m_error_magic 0x21 # define g1m_error_checksum 0x22 # define g1m_error_eof 0x23 # define g1m_error_wrong_type 0x24 /* Error type -- for compatibility with old programs using enum */ typedef int g1m_error_t; /* Message getting macro */ extern const char *g1m_error_strings[]; # define g1m_strerror(N) g1m_error_strings[N] # define g1m_geterror(N) g1m_error_strings[N] /* ************************************************************************** */ /* Main functions */ /* ************************************************************************** */ /* open and free a handle */ extern int g1m_decode(g1m_t **handle, const char *path, g1m_buffer_t *buffer, g1m_type_t allowed_types); extern void g1m_free(g1m_t *handle); /* open a handle using FILEs */ #ifndef G1M_DISABLED_FILE extern int g1m_open(g1m_t **handle, const char *path, g1m_type_t allowed_types); extern int g1m_fopen(g1m_t **handle, const char *path, FILE *stream, g1m_type_t allowed_types); #endif /* Make a handle */ extern int g1m_make_mcs(g1m_t **handle, int count); extern int g1m_make_fkey(g1m_t **handle, g1m_platform_t platform, int count); extern int g1m_make_lang(g1m_t **handle, g1m_platform_t platform, int count); extern int g1m_make_picture(g1m_t **handle, unsigned int width, unsigned int height); extern int g1m_make_addin(g1m_t **h, g1m_platform_t platform, size_t size, const g1m_version_t *version, const time_t *created); /* encode a handle, get the extension */ extern int g1m_encode(g1m_t *handle, g1m_buffer_t *buffer); /* put into a FILE */ #ifndef G1M_DISABLED_FILE extern int g1m_write(g1m_t *handle, const char *path); extern int g1m_fwrite(g1m_t *handle, FILE *stream); #endif /* ************************************************************************** */ /* Main MCS functions */ /* ************************************************************************** */ /* make an MCS file out of a head */ extern int g1m_make_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *rawhead); extern int g1m_prepare_mcsfile_heads(g1m_mcshead_t *head, g1m_mcshead_t *heads); extern void g1m_free_mcsfile(g1m_mcsfile_t *handle); /* open MCS head for decoding, correct it for encoding */ extern int g1m_decode_mcsfile_head(g1m_mcshead_t *head, int raw_type, const unsigned char *groupname, const unsigned char *dirname, const unsigned char *filename, uint_fast32_t filesize); int g1m_correct_mcsfile_head(g1m_mcshead_t *head); /* open and decode MCS file */ extern int g1m_decode_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *head, g1m_buffer_t *buffer); extern int g1m_decode_mcsfile_data(g1m_mcsfile_t **handle, const g1m_mcshead_t *head, const unsigned char *data, size_t size); /* open CAS head for decoding * -------------------------- * if the head corresponds to something you want as a file (e.g. * not `g1m_mcstype_end`), then you should make the file using * `g1m_make_mcsfile`, and call `g1m_decode_casfile_part` while the * `g1m_mcsflag_unfinished` flag is set. * Warning: there could be no parts to read! (e.g. unset variable) */ extern int g1m_decode_casfile_head(g1m_mcshead_t *head, g1m_buffer_t *buffer); extern int g1m_decode_casfiles_part(g1m_mcshead_t *head, g1m_mcshead_t *heads, g1m_buffer_t *buffer); extern int g1m_decode_casfile_part(g1m_mcsfile_t *file, g1m_buffer_t *buffer); /* ************************************************************************** */ /* MCS archive management */ /* ************************************************************************** */ /* create and insert an MCS file into a MCS archive */ extern int g1m_mcs_insert(g1m_t *handle, g1m_mcsfile_t **tofile, const g1m_mcshead_t *head); /* sort an MCS archive for encoding, * compare two MCS files (utility function used by the first) */ extern int g1m_mcs_sort(g1m_t *handle); extern int g1m_compare_mcsfiles(const g1m_mcsfile_t *first_file, const g1m_mcsfile_t *second_file); /* ************************************************************************** */ /* Miscallaneous utilities */ /* ************************************************************************** */ /* Picture decoding/encoding */ extern int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, const unsigned char *raw, unsigned int width, unsigned int height); extern int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, unsigned char *raw, unsigned int width, unsigned int height); /* Version decoding/encoding */ extern int g1m_decode_version(const char *raw, g1m_version_t *version); extern int g1m_encode_version(const g1m_version_t *version, char *raw); /* Date decoding/encoding */ extern int g1m_decode_date(const char *raw, time_t *date); extern int g1m_encode_date(const time_t *date, char *raw); # ifdef __cplusplus } # endif #endif /* LIBG1M_H */