cake
/
libg1m
Archived
1
0
Fork 0

Modified MCS management utilities

This commit is contained in:
Thomas Touhey 2016-12-19 16:48:27 +01:00
parent f722b78c6b
commit 0a05b034d7
2 changed files with 69 additions and 6 deletions

View File

@ -221,6 +221,17 @@ int g1m_parse_mcsfile_content(g1m_mcsfile_t **handle, FILE *stream,
void g1m_free(g1m_t *handle);
void g1m_free_mcsfile(g1m_mcsfile_t *handle);
/* ************************************************************************** */
/* MCS file manipulation */
/* ************************************************************************** */
/* add MCS files */
int g1m_putmcs_program(g1m_t *handle, g1m_mcsfile_t **pfile,
char *name, char *password, char *content);
int g1m_putmcs_capture(g1m_t *handle, g1m_mcsfile_t **pfile,
int id, int width, int height, uint32_t **pixels);
int g1m_putmcs_picture(g1m_t *handle, g1m_mcsfile_t **pfile,
int id, uint32_t **pixels_one, uint32_t **pixels_two);
# ifdef __cplusplus
}
# endif

View File

@ -80,13 +80,14 @@ found:;
* Put a program in a MCS handle.
*
* @arg handle the handle.
* @arg pfile pointer to the file pointer to set.
* @arg name the name of the program.
* @arg password the password (NULL if none).
* @return the error code (0 if ok).
*/
int g1m_putmcs_program(g1m_t *handle, char *name, char *password,
char *content)
int g1m_putmcs_program(g1m_t *handle, g1m_mcsfile_t **pfile,
char *name, char *password, char *content)
{
/* check if the operation is supported */
if (~handle->type & g1m_type_mcs) return (g1m_error_op);
@ -106,6 +107,55 @@ int g1m_putmcs_program(g1m_t *handle, char *name, char *password,
else g1m_remove_password(file);
/* no error */
if (pfile) *pfile = file;
return (0);
}
/**
* g1m_putmcs_capture:
* Put a capture in an MCS handle.
*
* @arg handle the handle.
* @arg pfile the file pointer to get file.
* @arg id the capture ID (1 to 20).
* @arg width the capture width.
* @arg height the capture height.
* @arg pic the pixels to copy.
* @return the error code (0 if ok).
*/
int g1m_putmcs_capture(g1m_t *handle, g1m_mcsfile_t **pfile,
int id, int width, int height, uint32_t **pic)
{
/* check if the operation is supported */
if (~handle->type & g1m_type_mcs || id < 1 || id > 20)
return (g1m_error_op);
/* find the file */
g1m_mcsfile_t *file =
find_space_for_file(handle, g1m_mcstype_capture, NULL, id);
if (!file) return (g1m_error_alloc);
/* prepare picture */
file->width = width;
file->height = height;
file->image = NULL;
/* allocate */
file->image = alloc_pixels(width, height);
if (!file->image) return (g1m_error_alloc);
prepare_pixels(file->image, width, height);
/* copy pixels */
uint32_t *pix = &file->image[0][0];
for (int y = 0; y < height; y++) {
uint32_t *line = *pic++;
for (int x = 0; x < width; x++)
*pix++ = *line++;
}
/* no error */
if (pfile) *pfile = file;
return (0);
}
@ -114,14 +164,15 @@ int g1m_putmcs_program(g1m_t *handle, char *name, char *password,
* Put a picture in an MCS handle.
*
* @arg handle the handle.
* @arg pfile the file pointer to get.
* @arg id the picture ID (1 to 20).
* @arg pic_one the first 128x64 image.
* @arg pic_two the second 128x64 image.
* @arg pic_one pixels of the first 128x64 image to copy.
* @arg pic_two pixels of the second 128x64 image to copy.
* @return the error code (0 if ok).
*/
int g1m_putmcs_picture(g1m_t *handle, int id,
uint32_t **pic_one, uint32_t **pic_two)
int g1m_putmcs_picture(g1m_t *handle, g1m_mcsfile_t **pfile,
int id, uint32_t **pic_one, uint32_t **pic_two)
{
/* check if the operation is supported */
if (~handle->type & g1m_type_mcs || id < 1 || id > 20)
@ -164,5 +215,6 @@ int g1m_putmcs_picture(g1m_t *handle, int id,
}
/* no error */
if (pfile) *pfile = file;
return (0);
}