108 lines
3.3 KiB
C
108 lines
3.3 KiB
C
/* *****************************************************************************
|
|
* decode/mcs/picture.c -- decode an MCS picture.
|
|
* 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/>.
|
|
* ************************************************************************** */
|
|
#include <libg1m/internals.h>
|
|
|
|
/**
|
|
* g1m_decode_mcs_capture:
|
|
* Decode a capture.
|
|
*
|
|
* @arg handle the handle to make.
|
|
* @arg buffer the buffer to read from.
|
|
* @arg head the pre-filled head to complete and use.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int g1m_decode_mcs_capture(g1m_mcsfile_t **handle, g1m_buffer_t *buffer,
|
|
g1m_mcshead_t *head)
|
|
{
|
|
/* read header */
|
|
DREAD(hd, mcs_captureheader)
|
|
hd.width = be16toh(hd.width);
|
|
hd.height = be16toh(hd.height);
|
|
|
|
/* make final head and file */
|
|
head->g1m_mcshead_width = hd.width;
|
|
head->g1m_mcshead_height = hd.height;
|
|
int err = g1m_make_mcsfile(handle, head);
|
|
if (err) return (err);
|
|
g1m_mcsfile_t *h = *handle;
|
|
|
|
/* print info */
|
|
log_info("capture is %dx%d sized", h->g1m_mcsfile_head.g1m_mcshead_width,
|
|
h->g1m_mcsfile_head.g1m_mcshead_height);
|
|
|
|
/* read raw data */
|
|
size_t pic_size = g1m_picturesize_1bit_packed(head->g1m_mcshead_width,
|
|
head->g1m_mcshead_height);
|
|
uint8_t pic_raw[pic_size]; READ(pic_raw, pic_size)
|
|
|
|
/* get the image and return */
|
|
if ((err = g1m_decode_picture(h->g1m_mcsfile_pics[0],
|
|
g1m_pictureformat_1bit_packed, pic_raw,
|
|
head->g1m_mcshead_width, head->g1m_mcshead_height))) {
|
|
g1m_free_mcsfile(*handle);
|
|
*handle = NULL;
|
|
return (err);
|
|
}
|
|
|
|
/* no error! */
|
|
return (0);
|
|
}
|
|
|
|
/**
|
|
* g1m_decode_mcs_picture:
|
|
* Decode a picture.
|
|
*
|
|
* @arg handle the handle to make.
|
|
* @arg buffer the buffer to read from.
|
|
* @arg head the pre-filled head to complete and use.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int g1m_decode_mcs_picture(g1m_mcsfile_t **handle, g1m_buffer_t *buffer,
|
|
g1m_mcshead_t *head)
|
|
{
|
|
/* make final head */
|
|
head->g1m_mcshead_width = 128;
|
|
head->g1m_mcshead_height = 64;
|
|
int err = g1m_make_mcsfile(handle, head);
|
|
if (err) return (err);
|
|
g1m_mcsfile_t *h = *handle;
|
|
|
|
/* get the images */
|
|
size_t pic_size = g1m_picturesize_1bit_packed(head->g1m_mcshead_width,
|
|
head->g1m_mcshead_height);
|
|
uint8_t pics_raw[pic_size * 2]; READ(pics_raw, pic_size * 2)
|
|
|
|
/* decode the images */
|
|
if ((err = g1m_decode_picture(h->g1m_mcsfile_pics[0],
|
|
g1m_pictureformat_1bit_packed, pics_raw, head->g1m_mcshead_width,
|
|
head->g1m_mcshead_height))
|
|
|| (err = g1m_decode_picture(h->g1m_mcsfile_pics[1],
|
|
g1m_pictureformat_1bit_packed, &pics_raw[pic_size],
|
|
head->g1m_mcshead_width, head->g1m_mcshead_height))) {
|
|
g1m_free_mcsfile(*handle);
|
|
*handle = NULL;
|
|
return (err);
|
|
}
|
|
|
|
/* no error */
|
|
return (0);
|
|
}
|