/* ***************************************************************************** * decode/mcs/picture.c -- decode an MCS picture. * 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 . * ************************************************************************** */ #include /** * 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->width = hd.width; head->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->head.width, h->head.height); /* read raw data */ size_t pic_size = g1m_picturesize_1bit_packed(head->width, head->height); uint8_t pic_raw[pic_size]; READ(pic_raw, pic_size) /* get the image and return */ if ((err = g1m_decode_picture(h->pics[0], g1m_pictureformat_1bit_packed, pic_raw, head->width, head->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->width = 128; head->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->width, head->height); uint8_t pics_raw[pic_size * 2]; READ(pics_raw, pic_size * 2) /* decode the images */ if ((err = g1m_decode_picture(h->pics[0], g1m_pictureformat_1bit_packed, pics_raw, head->width, head->height)) || (err = g1m_decode_picture(h->pics[1], g1m_pictureformat_1bit_packed, &pics_raw[pic_size], head->width, head->height))) { g1m_free_mcsfile(*handle); *handle = NULL; return (err); } /* no error */ return (0); }