blob: 69f4a5bce5f447667c674573afbe906639d077d2 (
plain) (
tree)
|
|
/*
* Copyright (c) 2022, yzrh <yzrh@noema.org>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "cnki_jbig.h"
#include "jbig2.h"
int
cnki_jbig2(char **bitmap, int *bitmap_size,
int *bitmap_width, int *bitmap_height,
const char * restrict jbig, int jbig_size)
{
dib_t *dib = malloc(sizeof(dib_t));
if (dib == NULL)
return 1;
memcpy(dib, jbig, 40);
int width_padded = (dib->width * dib->depth + 7) / 8;
*bitmap_size = dib->height * width_padded;
*bitmap = malloc(*bitmap_size);
if (*bitmap == NULL) {
free(dib);
return 1;
}
strdec_jbig2(bitmap, jbig + 48, jbig_size - 48);
*bitmap_width = dib->width;
*bitmap_height = dib->height;
free(dib);
return 0;
}
|