Blame src/lib/openjp3d/raw.c

Packit caffb5
/*
Packit caffb5
 * The copyright in this software is being made available under the 2-clauses
Packit caffb5
 * BSD License, included below. This software may be subject to other third
Packit caffb5
 * party and contributor rights, including patent rights, and no such rights
Packit caffb5
 * are granted under this license.
Packit caffb5
 *
Packit caffb5
 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
Packit caffb5
 * Copyright (c) 2005, Herve Drolon, FreeImage Team
Packit caffb5
 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
Packit caffb5
 * All rights reserved.
Packit caffb5
 *
Packit caffb5
 * Redistribution and use in source and binary forms, with or without
Packit caffb5
 * modification, are permitted provided that the following conditions
Packit caffb5
 * are met:
Packit caffb5
 * 1. Redistributions of source code must retain the above copyright
Packit caffb5
 *    notice, this list of conditions and the following disclaimer.
Packit caffb5
 * 2. Redistributions in binary form must reproduce the above copyright
Packit caffb5
 *    notice, this list of conditions and the following disclaimer in the
Packit caffb5
 *    documentation and/or other materials provided with the distribution.
Packit caffb5
 *
Packit caffb5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
Packit caffb5
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit caffb5
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit caffb5
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit caffb5
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit caffb5
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit caffb5
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit caffb5
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit caffb5
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit caffb5
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit caffb5
 * POSSIBILITY OF SUCH DAMAGE.
Packit caffb5
 */
Packit caffb5
Packit caffb5
#include "opj_includes.h"
Packit caffb5
Packit caffb5
/*
Packit caffb5
==========================================================
Packit caffb5
   local functions
Packit caffb5
==========================================================
Packit caffb5
*/
Packit caffb5
Packit caffb5
Packit caffb5
/*
Packit caffb5
==========================================================
Packit caffb5
   RAW encoding interface
Packit caffb5
==========================================================
Packit caffb5
*/
Packit caffb5
Packit caffb5
opj_raw_t* raw_create()
Packit caffb5
{
Packit caffb5
    opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
Packit caffb5
    return raw;
Packit caffb5
}
Packit caffb5
Packit caffb5
void raw_destroy(opj_raw_t *raw)
Packit caffb5
{
Packit caffb5
    if (raw) {
Packit caffb5
        opj_free(raw);
Packit caffb5
    }
Packit caffb5
}
Packit caffb5
Packit caffb5
int raw_numbytes(opj_raw_t *raw)
Packit caffb5
{
Packit caffb5
    return raw->bp - raw->start;
Packit caffb5
}
Packit caffb5
Packit caffb5
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len)
Packit caffb5
{
Packit caffb5
    raw->start = bp;
Packit caffb5
    raw->lenmax = len;
Packit caffb5
    raw->len = 0;
Packit caffb5
    raw->c = 0;
Packit caffb5
    raw->ct = 0;
Packit caffb5
}
Packit caffb5
Packit caffb5
int raw_decode(opj_raw_t *raw)
Packit caffb5
{
Packit caffb5
    int d;
Packit caffb5
    if (raw->ct == 0) {
Packit caffb5
        raw->ct = 8;
Packit caffb5
        if (raw->len == raw->lenmax) {
Packit caffb5
            raw->c = 0xff;
Packit caffb5
        } else {
Packit caffb5
            if (raw->c == 0xff) {
Packit caffb5
                raw->ct = 7;
Packit caffb5
            }
Packit caffb5
            raw->c = *(raw->start + raw->len);
Packit caffb5
            raw->len++;
Packit caffb5
        }
Packit caffb5
    }
Packit caffb5
    raw->ct--;
Packit caffb5
    d = (raw->c >> raw->ct) & 0x01;
Packit caffb5
Packit caffb5
    return d;
Packit caffb5
}
Packit caffb5