cake
/
libg1m
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libg1m/include/libg1m.h

200 lines
8.4 KiB
C

/* *****************************************************************************
* libg1m.h -- libg1m main public header.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*
* WARNING: Do NOT include this header using <libg1m-(version)/libg1m.h>!
*
* Compile using one of these:
*
* libg1m-config --cflags
* pkg-config libg1m --cflags
*
* and include using <libg1m.h>.
* ************************************************************************** */
#ifndef LIBG1M_H
# define LIBG1M_H
# include <libg1m/config.h>
# include <libg1m/buffer.h>
# include <libg1m/handle.h>
# include <libg1m/picture.h>
# include <libg1m/fontcharacter.h>
# include <stdio.h>
# include <stdint.h>
# include <time.h>
# 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_handle_t **g1m_arg_handle, const char *g1m_arg_path,
g1m_buffer_t *g1m_arg_buffer, g1m_type_t g1m_arg_allowed_types);
extern void g1m_free(g1m_handle_t *g1m_arg_handle);
/* open a handle using FILEs */
#ifndef G1M_DISABLED_FILE
extern int g1m_open(g1m_handle_t **g1m_arg_handle, const char *g1m_arg_path,
g1m_type_t g1m_arg_allowed_types);
extern int g1m_fopen(g1m_handle_t **g1m_arg_handle, const char *g1m_arg_path,
FILE *g1m_arg_stream, g1m_type_t g1m_arg_allowed_types);
#endif
/* Make a handle */
extern int g1m_make_mcs(g1m_handle_t **g1m_arg_handle, int g1m_arg_count);
extern int g1m_make_fkey(g1m_handle_t **g1m_arg_handle,
g1m_platform_t g1m_arg_platform, int g1m_arg_count);
extern int g1m_make_lang(g1m_handle_t **g1m_arg_handle,
g1m_platform_t g1m_arg_platform, int g1m_arg_count);
extern int g1m_make_picture(g1m_handle_t **g1m_arg_handle,
unsigned int g1m_arg_width, unsigned int g1m_arg_height);
extern int g1m_make_addin(g1m_handle_t **g1m_arg_handle,
g1m_platform_t g1m_arg_platform, size_t g1m_arg_size,
const char *g1m_arg_name, const char *g1m_arg_internal_name,
const g1m_version_t *g1m_arg_version, const time_t *g1m_arg_created);
/* encode a handle, get the extension */
extern int g1m_encode(g1m_handle_t *g1m_arg_handle,
g1m_buffer_t *g1m_arg_buffer);
/* put into a FILE */
#ifndef G1M_DISABLED_FILE
extern int g1m_write(g1m_handle_t *g1m_arg_handle, const char *g1m_arg_path);
extern int g1m_fwrite(g1m_handle_t *g1m_arg_handle, FILE *g1m_arg_stream);
#endif
/* ************************************************************************** */
/* Main MCS functions */
/* ************************************************************************** */
/* make an MCS file out of a head */
extern int g1m_make_mcsfile(g1m_mcsfile_t **g1m_arg_handle,
const g1m_mcshead_t *g1m_arg_rawhead);
extern void g1m_free_mcsfile(g1m_mcsfile_t *g1m_arg_handle);
/* open MCS head for decoding, correct it for encoding */
extern int g1m_decode_mcsfile_head(g1m_mcshead_t *g1m_arg_head,
int g1m_arg_raw, const unsigned char *g1m_arg_group,
const unsigned char *g1m_arg_dirname, const unsigned char *g1m_arg_filename,
uint_fast32_t g1m_arg_filesize);
int g1m_correct_mcsfile_head(g1m_mcshead_t *g1m_arg_head);
/* open and decode MCS file */
extern int g1m_decode_mcsfile(g1m_mcsfile_t **g1m_arg_handle,
const g1m_mcshead_t *g1m_arg_head, g1m_buffer_t *g1m_arg_buffer);
extern int g1m_decode_mcsfile_data(g1m_mcsfile_t **g1m_arg_handle,
const g1m_mcshead_t *g1m_arg_head, const unsigned char *g1m_arg_data,
size_t g1m_arg_size);
/* encode an MCS file */
extern int g1m_encode_mcsfile(g1m_mcsfile_t *g1m_arg_handle,
g1m_buffer_t *g1m_arg_buffer);
# define g1m_announce_mcsfile(handle, size) \
(g1m_encode_mcsfile(handle, (g1m_buffer_t[]){{ \
(void*)size, 0, NULL, NULL, g1m_announce_callback, NULL}}))
/* open CAS head for decoding, correct it for encoding */
extern int g1m_decode_casfile_head(g1m_mcshead_t *g1m_arg_head,
g1m_buffer_t *g1m_arg_buffer);
extern int g1m_decode_casfile_part(g1m_mcsfile_t *g1m_arg_file,
g1m_buffer_t *g1m_arg_buffer);
extern int g1m_correct_casfile_head(g1m_mcshead_t *g1m_arg_head);
/* announce, encode a CAS head */
extern int g1m_encode_casfile_head(g1m_mcshead_t *g1m_arg_head,
g1m_buffer_t *g1m_arg_buffer);
extern int g1m_encode_casfile_part(g1m_mcsfile_t *g1m_arg_file,
g1m_buffer_t *g1m_arg_buffer);
/* ************************************************************************** */
/* MCS archive management */
/* ************************************************************************** */
/* create and insert an MCS file into a MCS archive */
extern int g1m_mcs_insert(g1m_handle_t *g1m_arg_handle,
g1m_mcsfile_t **g1m_arg_tofile, const g1m_mcshead_t *g1m_arg_head);
/* sort an MCS archive for encoding,
* compare two MCS files (utility function used by the first) */
extern int g1m_mcs_sort(g1m_handle_t *g1m_arg_handle);
extern int g1m_compare_mcsfiles(const g1m_mcsfile_t *g1m_arg_first_file,
const g1m_mcsfile_t *g1m_arg_second_file);
/* ************************************************************************** */
/* Miscallaneous utilities */
/* ************************************************************************** */
/* Picture decoding/encoding */
extern int g1m_decode_picture(uint32_t **g1m_arg_pixels,
g1m_pictureformat_t g1m_arg_format, const unsigned char *g1m_arg_raw,
unsigned int g1m_arg_width, unsigned int g1m_arg_height);
extern int g1m_encode_picture(const uint32_t **g1m_arg_pixels,
g1m_pictureformat_t g1m_arg_format, unsigned char *g1m_arg_raw,
unsigned int g1m_arg_width, unsigned int g1m_arg_height);
/* Version decoding/encoding */
extern int g1m_check_version(const char *g1m_arg_raw);
extern int g1m_decode_version(const char *g1m_arg_raw,
g1m_version_t *g1m_arg_version);
extern int g1m_encode_version(const g1m_version_t *g1m_arg_version,
char *g1m_arg_raw);
/* Date decoding/encoding */
extern int g1m_check_date(const char *g1m_arg_raw);
extern int g1m_decode_date(const char *g1m_arg_raw, time_t *g1m_arg_date);
extern int g1m_encode_date(const time_t *g1m_arg_date, char *g1m_arg_raw);
/* Announce callback that just contributes to a size_t. */
extern int g1m_announce_callback(void *g1m_arg_cookie, size_t g1m_arg_size);
# ifdef __cplusplus
}
# endif
#endif /* LIBG1M_H */