parent
9c1cfb034a
commit
d028260053
|
@ -42,7 +42,7 @@ if(WIN32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Loop over all executables:
|
# Loop over all executables:
|
||||||
foreach(exe opj_decompress opj_compress opj_dump)
|
foreach(exe opj_decompress opj_decompress_c_vector opj_compress opj_dump)
|
||||||
add_executable(${exe} ${exe}.c ${common_SRCS})
|
add_executable(${exe} ${exe}.c ${common_SRCS})
|
||||||
if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12")
|
if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12")
|
||||||
target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
|
target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -93,6 +93,7 @@ int imagetotga(opj_image_t * image, const char *outfile);
|
||||||
/* BMP conversion */
|
/* BMP conversion */
|
||||||
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
|
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
|
||||||
int imagetobmp(opj_image_t *image, const char *outfile);
|
int imagetobmp(opj_image_t *image, const char *outfile);
|
||||||
|
int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile);
|
||||||
|
|
||||||
/* TIFF conversion*/
|
/* TIFF conversion*/
|
||||||
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
|
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
|
||||||
|
@ -117,6 +118,8 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters,
|
||||||
opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters,
|
opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters,
|
||||||
raw_cparameters_t *raw_cp);
|
raw_cparameters_t *raw_cp);
|
||||||
|
|
||||||
|
extern int imagetoraw_c_vector(opj_image_t * image, c_vector *outfile,
|
||||||
|
OPJ_BOOL big_endian);
|
||||||
/* PNG conversion*/
|
/* PNG conversion*/
|
||||||
extern int imagetopng(opj_image_t *image, const char *write_idf);
|
extern int imagetopng(opj_image_t *image, const char *write_idf);
|
||||||
extern opj_image_t* pngtoimage(const char *filename,
|
extern opj_image_t* pngtoimage(const char *filename,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -32,6 +32,8 @@ set(OPENJPEG_SRCS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/c_vector.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/c_vector.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
|
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
|
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
|
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
|
||||||
|
|
|
@ -0,0 +1,228 @@
|
||||||
|
//
|
||||||
|
// Created by caesar kekxv on 2020/4/17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "c_vector.h"
|
||||||
|
|
||||||
|
typedef struct c_vector {
|
||||||
|
void *items;
|
||||||
|
size_t total;
|
||||||
|
size_t index;
|
||||||
|
} c_vector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
int c_vector_init(c_vector **cVector) {
|
||||||
|
if (!cVector)return -1;
|
||||||
|
if (NULL != (*cVector))return -2;
|
||||||
|
*cVector = (c_vector *) malloc(sizeof(c_vector));
|
||||||
|
(*cVector)->index = 0;
|
||||||
|
(*cVector)->total = 0;
|
||||||
|
(*cVector)->items = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector size
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_size(c_vector *cVector) {
|
||||||
|
if (!cVector)return -1;
|
||||||
|
return cVector->total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resize c_vector
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
static int c_vector_resize(c_vector *cVector, size_t count) {
|
||||||
|
if (!cVector)return -1;
|
||||||
|
if (cVector->items) {
|
||||||
|
void *items = (void *) realloc(cVector->items, sizeof(void) * count);
|
||||||
|
if (items) {
|
||||||
|
cVector->items = items;
|
||||||
|
cVector->total = count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
cVector->items = (void *) malloc(sizeof(void) * count);
|
||||||
|
if (cVector->items == NULL) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
cVector->total = count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* push back c_vector
|
||||||
|
* @param cVector
|
||||||
|
* @param data
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
int c_vector_push_back(c_vector *cVector, void *data, size_t offset, size_t count) {
|
||||||
|
size_t index = cVector->total;
|
||||||
|
size_t new_size = count + cVector->total;
|
||||||
|
if (c_vector_resize(cVector, new_size) < 0) {
|
||||||
|
// error realloc
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(&(cVector->items[index]), &data[offset], count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* push zero to c_vector
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int c_vector_push_back_zero(c_vector *cVector) {
|
||||||
|
unsigned char data[1] = {0};
|
||||||
|
return c_vector_push_back(cVector, data, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set c_vector data
|
||||||
|
* @param cVector
|
||||||
|
* @param offset
|
||||||
|
* @param data
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, size_t count) {
|
||||||
|
if (cVector->total <= index || index + count >= cVector->total) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(&(cVector->items[index]), &data[offset], count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert data
|
||||||
|
* @param cVector
|
||||||
|
* @param index
|
||||||
|
* @param data
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offset, size_t count) {
|
||||||
|
if (cVector->total <= index) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
size_t last_total = cVector->total;
|
||||||
|
size_t new_size = count + cVector->total;
|
||||||
|
if (c_vector_resize(cVector, new_size) < 0) {
|
||||||
|
// error realloc
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
size_t len = last_total - index;
|
||||||
|
for (size_t i = 1; i <= len; i++) {
|
||||||
|
memcpy(&cVector->items[new_size - i], &cVector->items[last_total - i], 1);
|
||||||
|
}
|
||||||
|
memcpy(&(cVector->items[index]), &data[offset], count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector data
|
||||||
|
* @param cVector
|
||||||
|
* @param offset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *c_vector_get(c_vector *cVector, size_t offset) {
|
||||||
|
if (cVector->total <= offset) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return &cVector->items[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector data
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *c_vector_data(c_vector *cVector) {
|
||||||
|
return c_vector_get(cVector, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* c_vector delete
|
||||||
|
* @param cVector
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
size_t c_vector_delete(c_vector *cVector, size_t offset, size_t count) {
|
||||||
|
if (cVector->total <= offset) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (count + offset >= cVector->total) {
|
||||||
|
cVector->total = cVector->total - offset;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(&(cVector->items[offset]), &(cVector->items[offset + count]), cVector->total - count - offset);
|
||||||
|
cVector->total = cVector->total - count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* free c_vector
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
void c_vector_free(c_vector **cVector) {
|
||||||
|
if (!cVector)return;
|
||||||
|
if (!*cVector)return;
|
||||||
|
if ((*cVector)->items)free((*cVector)->items);
|
||||||
|
(*cVector)->items = NULL;
|
||||||
|
free(*cVector);
|
||||||
|
*cVector = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_vector_seekg(size_t offset, c_vector *cVector) {
|
||||||
|
return c_vector_seek(cVector, offset, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_vector_skip(size_t offset, c_vector *cVector) {
|
||||||
|
return c_vector_seek(cVector, offset, SEEK_CUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_vector_seek(c_vector *cVector, size_t offset, int whence) {
|
||||||
|
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (SEEK_SET == whence) {
|
||||||
|
cVector->index = offset;
|
||||||
|
} else if (SEEK_END == whence) {
|
||||||
|
cVector->index = cVector->total - 1 - offset;
|
||||||
|
} else if (SEEK_CUR == whence) {
|
||||||
|
cVector->index = cVector->total + offset;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t c_vector_read(void *p_buffer, size_t p_nb_bytes, c_vector *v) {
|
||||||
|
if (v->total - v->index < p_nb_bytes) {
|
||||||
|
p_nb_bytes = v->total - v->index;
|
||||||
|
}
|
||||||
|
memcpy(p_buffer, &(v->items[v->index]), p_nb_bytes);
|
||||||
|
v->index += p_nb_bytes;
|
||||||
|
return p_nb_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t c_vector_write(void *p_buffer, size_t p_nb_bytes,
|
||||||
|
c_vector *v) {
|
||||||
|
if (v->index + p_nb_bytes > v->total) {
|
||||||
|
c_vector_resize(v, v->index + p_nb_bytes);
|
||||||
|
}
|
||||||
|
c_vector_set(v, v->index, p_buffer, 0, p_nb_bytes);
|
||||||
|
v->index += p_nb_bytes;
|
||||||
|
return p_nb_bytes;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
//
|
||||||
|
// Created by caesar kekxv on 2020/4/17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef CLANGTOOLS_VECTOR_H
|
||||||
|
#define CLANGTOOLS_VECTOR_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct c_vector;
|
||||||
|
typedef struct c_vector c_vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
int c_vector_init(c_vector **cVector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector size
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_size(c_vector *cVector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resize c_vector
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
static int c_vector_resize(c_vector *cVector, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* push back c_vector
|
||||||
|
* @param cVector
|
||||||
|
* @param data
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
int c_vector_push_back(c_vector *cVector, void *data, size_t offset, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* push zero to c_vector
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int c_vector_push_back_zero(c_vector *cVector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set data
|
||||||
|
* @param cVector
|
||||||
|
* @param index
|
||||||
|
* @param data
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert data
|
||||||
|
* @param cVector
|
||||||
|
* @param index
|
||||||
|
* @param data
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offset, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector data
|
||||||
|
* @param cVector
|
||||||
|
* @param offset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *c_vector_get(c_vector *cVector, size_t offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get c_vector data
|
||||||
|
* @param cVector
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *c_vector_data(c_vector *cVector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* c_vector delete
|
||||||
|
* @param cVector
|
||||||
|
* @param offset
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
size_t c_vector_delete(c_vector *cVector, size_t offset, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* free c_vector
|
||||||
|
* @param cVector
|
||||||
|
*/
|
||||||
|
void c_vector_free(c_vector **cVector);
|
||||||
|
|
||||||
|
int c_vector_seek(c_vector *cVector, size_t offset, int whence);
|
||||||
|
int c_vector_seekg(size_t offset,c_vector *cVector);
|
||||||
|
int c_vector_skip(size_t offset,c_vector *cVector);
|
||||||
|
|
||||||
|
size_t c_vector_read(void *p_buffer, size_t p_nb_bytes, c_vector *v);
|
||||||
|
|
||||||
|
size_t c_vector_write(void *p_buffer, size_t p_nb_bytes, c_vector *v);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //CLANGTOOLS_VECTOR_H
|
File diff suppressed because it is too large
Load Diff
|
@ -130,6 +130,7 @@ typedef uint64_t OPJ_UINT64;
|
||||||
typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
|
typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "c_vector.h"
|
||||||
typedef size_t OPJ_SIZE_T;
|
typedef size_t OPJ_SIZE_T;
|
||||||
|
|
||||||
/* Avoid compile-time warning because parameter is not used */
|
/* Avoid compile-time warning because parameter is not used */
|
||||||
|
@ -1252,6 +1253,24 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream(
|
||||||
OPJ_SIZE_T p_buffer_size,
|
OPJ_SIZE_T p_buffer_size,
|
||||||
OPJ_BOOL p_is_read_stream);
|
OPJ_BOOL p_is_read_stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param fname
|
||||||
|
* @param p_is_read_stream
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
opj_stream_t *OPJ_CALLCONV opj_stream_create_default_c_vector(
|
||||||
|
c_vector *fname, OPJ_BOOL p_is_read_stream);
|
||||||
|
/** Create a stream from a file identified with c_vector
|
||||||
|
* @param v c_vector
|
||||||
|
* @param p_buffer_size size of the chunk used to stream
|
||||||
|
* @param p_is_read_stream whether the stream is a read stream (true) or not (false)
|
||||||
|
*/
|
||||||
|
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_c_vector(
|
||||||
|
c_vector *v,
|
||||||
|
OPJ_SIZE_T p_buffer_size,
|
||||||
|
OPJ_BOOL p_is_read_stream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
event manager functions definitions
|
event manager functions definitions
|
||||||
|
|
Loading…
Reference in New Issue