|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* This file is part of libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2013 Petri Hintukainen <phintuka@users.sourceforge.net>
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is free software; you can redistribute it and/or
|
|
Packit |
5e46da |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License as published by the Free Software Foundation; either
|
|
Packit |
5e46da |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
5e46da |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5e46da |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
5e46da |
* Lesser General Public License for more details.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License along with this library. If not, see
|
|
Packit |
5e46da |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#if !defined(_BD_RLE_H_)
|
|
Packit |
5e46da |
#define _BD_RLE_H_
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include "overlay.h"
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include "util/attributes.h"
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include <stdint.h>
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* encode state
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
typedef struct {
|
|
Packit |
5e46da |
BD_PG_RLE_ELEM *elem; /* current element */
|
|
Packit |
5e46da |
unsigned int free_elem;/* unused element count */
|
|
Packit |
5e46da |
unsigned int num_elem; /* allocated element count */
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
int error;
|
|
Packit |
5e46da |
} RLE_ENC;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include "util/refcnt.h"
|
|
Packit |
5e46da |
#include "util/macro.h"
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
BD_PRIVATE BD_PG_RLE_ELEM *rle_crop_object(const BD_PG_RLE_ELEM *orig, int width,
|
|
Packit |
5e46da |
int crop_x, int crop_y, int crop_w, int crop_h);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static inline int rle_begin(RLE_ENC *p)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
p->num_elem = 1024;
|
|
Packit |
5e46da |
p->free_elem = 1024;
|
|
Packit |
5e46da |
p->elem = refcnt_realloc(NULL, p->num_elem * sizeof(BD_PG_RLE_ELEM));
|
|
Packit |
5e46da |
if (!p->elem) {
|
|
Packit |
5e46da |
return -1;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
p->elem->len = 0;
|
|
Packit |
5e46da |
p->elem->color = 0xffff;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
p->error = 0;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
return 0;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static inline BD_PG_RLE_ELEM *rle_get(RLE_ENC *p)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
BD_PG_RLE_ELEM *start = (p->elem ? p->elem - (p->num_elem - p->free_elem) : NULL);
|
|
Packit |
5e46da |
if (p->error) {
|
|
Packit |
5e46da |
if (start) {
|
|
Packit |
5e46da |
bd_refcnt_dec(start);
|
|
Packit |
5e46da |
p->elem = NULL;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
return NULL;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
return start;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static inline void rle_end(RLE_ENC *p)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
BD_PG_RLE_ELEM *start = rle_get(p);
|
|
Packit |
5e46da |
if (start) {
|
|
Packit |
5e46da |
bd_refcnt_dec(start);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
p->elem = NULL;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* compression
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
BD_PRIVATE int rle_add_eol(RLE_ENC *p);
|
|
Packit |
5e46da |
BD_PRIVATE int rle_add_bite(RLE_ENC *p, uint8_t color, int len);
|
|
Packit |
5e46da |
BD_PRIVATE int rle_compress_chunk(RLE_ENC *p, const uint8_t *mem, unsigned width);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#endif /* _BD_RLE_H_ */
|