60 lines
2.1 KiB
C
60 lines
2.1 KiB
C
/* ****************************************************************************
|
|
* picture/size.c -- get picture size.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libcasio.
|
|
* libcasio 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.
|
|
*
|
|
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************* */
|
|
#include "picture.h"
|
|
|
|
/* `casio_get_picture_estimated_size()`: get the estimated size of a picture
|
|
* in bytes out of its format and dimensions. */
|
|
|
|
CASIO_EXTERN(int) casio_get_picture_estimated_size(casio_pictureformat_t fmt,
|
|
unsigned int width, unsigned int height, size_t *sizep)
|
|
{
|
|
switch (fmt) {
|
|
case casio_pictureformat_1bit: /* FALLTHRU */
|
|
case casio_pictureformat_1bit_r: /* FALLTHRU */
|
|
case casio_pictureformat_1bit_old:
|
|
*sizep = ((width / 8) + !!(width % 8)) * height;
|
|
|
|
case casio_pictureformat_1bit_packed: /* FALLTHRU */
|
|
case casio_pictureformat_1bit_packed_r:
|
|
*sizep = (width * height / 8) + !!(width * height % 8);
|
|
|
|
case casio_pictureformat_2bit_dual:
|
|
*sizep = ((width / 8) + !!(width % 8)) * height * 2;
|
|
|
|
case casio_pictureformat_4bit: /* FALLTHRU */
|
|
case casio_pictureformat_4bit_code:
|
|
*sizep = width * height / 2;
|
|
|
|
case casio_pictureformat_4bit_color: /* FALLTHRU */
|
|
case casio_pictureformat_4bit_mono:
|
|
*sizep = ((width / 8) + !!(width % 8)) * height * 4;
|
|
|
|
case casio_pictureformat_casemul:
|
|
*sizep = width * height;
|
|
|
|
case casio_pictureformat_16bit:
|
|
*sizep = width * height * 2;
|
|
|
|
default:
|
|
return (casio_error_op);
|
|
}
|
|
|
|
return (casio_ok);
|
|
}
|