From a0ce21b06c7097b02dd2d6e117c05d85ed8aa02a Mon Sep 17 00:00:00 2001 From: caesar Date: Sun, 19 Apr 2020 15:41:41 +0800 Subject: [PATCH] fix gcc build --- src/bin/jp2/convertbmp.c | 277 ++++++++++++++++---------- src/bin/jp2/opj_decompress_c_vector.c | 30 ++- src/lib/openjp2/c_vector.c | 54 ++--- src/lib/openjp2/c_vector.h | 32 +-- 4 files changed, 234 insertions(+), 159 deletions(-) diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 1fee5184..cefb3dd0 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -1151,6 +1151,7 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { int w, h; int i, pad; int adjustR, adjustG, adjustB; + OPJ_UINT8 _tmp[100]; if (image->comps[0].prec < 8) { fprintf(stderr, "imagetobmp: Unsupported precision: %d\n", @@ -1182,58 +1183,83 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { /* FILE HEADER */ /* ------------- */ - OPJ_UINT8 _1185[4] = { - (OPJ_UINT8) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff}; - c_vector_push_back(outfile, _1185, 0, 4); - OPJ_UINT8 _1191[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1191, 0, 4); + _tmp[0] = (OPJ_UINT8) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff; + _tmp[1] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); - OPJ_UINT8 _1195[4] = {(54) & 0xff, ((54) >> 8) & 0xff, ((54) >> 16) & 0xff, - ((54) >> 24) & 0xff}; - c_vector_push_back(outfile, _1195, 0, 4); + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (54) & 0xff; + _tmp[1] = ((54) >> 8) & 0xff; + _tmp[2] = ((54) >> 16) & 0xff; + _tmp[3] = ((54) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); /* INFO HEADER */ /* ------------- */ - OPJ_UINT8 _1201[4] = {(40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, - ((40) >> 24) & 0xff}; - c_vector_push_back(outfile, _1201, 0, 4); + _tmp[0] = (40) & 0xff; + _tmp[1] = ((40) >> 8) & 0xff; + _tmp[2] = ((40) >> 16) & 0xff; + _tmp[3] = ((40) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); - OPJ_UINT8 _1205[4] = {(OPJ_UINT8) ((w) & 0xff), - (OPJ_UINT8) ((w) >> 8) & 0xff, - (OPJ_UINT8) ((w) >> 16) & 0xff, - (OPJ_UINT8) ((w) >> 24) & 0xff}; - c_vector_push_back(outfile, _1205, 0, 4); - OPJ_UINT8 _1210[4] = {(OPJ_UINT8) ((h) & 0xff), - (OPJ_UINT8) ((h) >> 8) & 0xff, - (OPJ_UINT8) ((h) >> 16) & 0xff, - (OPJ_UINT8) ((h) >> 24) & 0xff}; - c_vector_push_back(outfile, _1210, 0, 4); - OPJ_UINT8 _1215[4] = {(1) & 0xff, ((1) >> 8) & 0xff, (24) & 0xff, ((24) >> 8) & 0xff}; - c_vector_push_back(outfile, _1215, 0, 4); - OPJ_UINT8 _1218[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1218, 0, 4); - OPJ_UINT8 _1220[4] = {(OPJ_UINT8) (3 * h * w + 3 * h * (w % 2)) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff, - (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff}; - c_vector_push_back(outfile, _1220, 0, 4); - OPJ_UINT8 _1225[4] = {(7834) & 0xff, ((7834) >> 8) & 0xff, - ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff}; - c_vector_push_back(outfile, _1225, 0, 4); - OPJ_UINT8 _1228[4] = {(7834) & 0xff, ((7834) >> 8) & 0xff, - ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff}; - c_vector_push_back(outfile, _1228, 0, 4); - OPJ_UINT8 _1231[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1231, 0, 4); - OPJ_UINT8 _1234[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1234, 0, 4); + _tmp[0] = (OPJ_UINT8) ((w) & 0xff); + _tmp[1] = (OPJ_UINT8) ((w) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((w) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((w) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (OPJ_UINT8) ((h) & 0xff); + _tmp[1] = (OPJ_UINT8) ((h) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (1) & 0xff; + _tmp[1] = ((1) >> 8) & 0xff; + _tmp[2] = (24) & 0xff; + _tmp[3] = ((24) >> 8) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (OPJ_UINT8) (3 * h * w + 3 * h * (w % 2)) & 0xff; + _tmp[1] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (7834) & 0xff; + _tmp[1] = ((7834) >> 8) & 0xff; + _tmp[2] = ((7834) >> 16) & 0xff; + _tmp[3] = ((7834) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (7834) & 0xff; + _tmp[1] = ((7834) >> 8) & 0xff; + _tmp[2] = ((7834) >> 16) & 0xff; + _tmp[3] = ((7834) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); if (image->comps[0].prec > 8) { adjustR = (int) image->comps[0].prec - 8; @@ -1297,8 +1323,10 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { } bc = (OPJ_UINT8) b; - OPJ_UINT8 _1300[3] = {bc, gc, rc}; - c_vector_push_back(outfile, _1300, 0, 3); + _tmp[0] = bc; + _tmp[1] = gc; + _tmp[2] = rc; + c_vector_push_back(outfile, _tmp, 0, 3); if ((i + 1) % w == 0) { for (pad = ((3 * w) % 4) ? (4 - (3 * w) % 4) : 0; pad > 0; pad--) { /* ADD */ @@ -1308,77 +1336,103 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { } } else { /* Gray-scale */ - /* -->> -->> -->> -->> - 8 bits non code (Gray scale) - <<-- <<-- <<-- <<-- */ +/* -->> -->> -->> -->> +8 bits non code (Gray scale) +<<-- <<-- <<-- <<-- */ if (!outfile) { - fprintf(stderr, "ERROR -> failed to writing\n"); + fprintf(stderr, + "ERROR -> failed to writing\n"); return 1; } if (image->numcomps > 1) { - fprintf(stderr, "imagetobmp: only first component of %d is used.\n", + fprintf(stderr, + "imagetobmp: only first component of %d is used.\n", image->numcomps); } w = (int) image->comps[0].w; h = (int) image->comps[0].h; - c_vector_push_back(outfile, "BM", 0, 2); + c_vector_push_back(outfile, + "BM", 0, 2); - /* FILE HEADER */ - /* ------------- */ - OPJ_UINT8 _1331[4] = {(OPJ_UINT8) (h * w + 54 + 1024 + h * (w % 2)) & 0xff, - (OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff, - (OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff, - (OPJ_UINT8) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff}; - c_vector_push_back(outfile, _1331, 0, 4); - OPJ_UINT8 _1336[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1336, 0, 4); +/* FILE HEADER */ +/* ------------- */ + _tmp[0] = (OPJ_UINT8) (h * w + 54 + 1024 + h * (w % 2)) & 0xff; + _tmp[1] = (OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); - OPJ_UINT8 _1340[4] = {(54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff, - ((54 + 1024) >> 16) & 0xff, - ((54 + 1024) >> 24) & 0xff}; - c_vector_push_back(outfile, _1340, 0, 4); + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); - /* INFO HEADER */ - /* ------------- */ - OPJ_UINT8 _1347[4] = {(40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, - ((40) >> 24) & 0xff}; - c_vector_push_back(outfile, _1347, 0, 4); - OPJ_UINT8 _1350[4] = {(OPJ_UINT8) ((w) & 0xff), - (OPJ_UINT8) ((w) >> 8) & 0xff, - (OPJ_UINT8) ((w) >> 16) & 0xff, - (OPJ_UINT8) ((w) >> 24) & 0xff}; - c_vector_push_back(outfile, _1350, 0, 4); - OPJ_UINT8 _1355[4] = {(OPJ_UINT8) ((h) & 0xff), - (OPJ_UINT8) ((h) >> 8) & 0xff, - (OPJ_UINT8) ((h) >> 16) & 0xff, - (OPJ_UINT8) ((h) >> 24) & 0xff}; - c_vector_push_back(outfile, _1355, 0, 4); - OPJ_UINT8 _1360[4] = {(1) & 0xff, ((1) >> 8) & 0xff, (8) & 0xff, ((8) >> 8) & 0xff}; - c_vector_push_back(outfile, _1360, 0, 4); - OPJ_UINT8 _1363[4] = {(0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, - ((0) >> 24) & 0xff}; - c_vector_push_back(outfile, _1363, 0, 4); - OPJ_UINT8 _1366[4] = {(OPJ_UINT8) (h * w + h * (w % 2)) & 0xff, - (OPJ_UINT8) ((h * w + h * (w % 2)) >> 8) & 0xff, - (OPJ_UINT8) ((h * w + h * (w % 2)) >> 16) & 0xff, - (OPJ_UINT8) ((h * w + h * (w % 2)) >> 24) & 0xff}; - c_vector_push_back(outfile, _1366, 0, 4); - OPJ_UINT8 _1371[4] = {(7834) & 0xff, ((7834) >> 8) & 0xff, - ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff}; - c_vector_push_back(outfile, _1371, 0, 4); - OPJ_UINT8 _1374[4] = {(7834) & 0xff, ((7834) >> 8) & 0xff, - ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff}; - c_vector_push_back(outfile, _1374, 0, 4); - OPJ_UINT8 _1377[4] = {(256) & 0xff, ((256) >> 8) & 0xff, - ((256) >> 16) & 0xff, ((256) >> 24) & 0xff}; - c_vector_push_back(outfile, _1377, 0, 4); - OPJ_UINT8 _1380[4] = {(256) & 0xff, ((256) >> 8) & 0xff, - ((256) >> 16) & 0xff, ((256) >> 24) & 0xff}; - c_vector_push_back(outfile, _1380, 0, 4); + _tmp[0] = (54 + 1024) & 0xff; + _tmp[1] = ((54 + 1024) >> 8) & 0xff; + _tmp[2] = ((54 + 1024) >> 16) & 0xff; + _tmp[3] = ((54 + 1024) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + +/* INFO HEADER */ +/* ------------- */ + _tmp[0] = (40) & 0xff; + _tmp[1] = ((40) >> 8) & 0xff; + _tmp[2] = ((40) >> 16) & 0xff; + _tmp[3] = ((40) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (OPJ_UINT8) ((w) & 0xff); + _tmp[1] = (OPJ_UINT8) ((w) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((w) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((w) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (OPJ_UINT8) ((h) & 0xff); + _tmp[1] = (OPJ_UINT8) ((h) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (1) & 0xff; + _tmp[1] = ((1) >> 8) & 0xff; + _tmp[2] = (8) & 0xff; + _tmp[3] = ((8) >> 8) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (0) & 0xff; + _tmp[1] = ((0) >> 8) & 0xff; + _tmp[2] = ((0) >> 16) & 0xff; + _tmp[3] = ((0) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (OPJ_UINT8) (h * w + h * (w % 2)) & 0xff; + _tmp[1] = (OPJ_UINT8) ((h * w + h * (w % 2)) >> 8) & 0xff; + _tmp[2] = (OPJ_UINT8) ((h * w + h * (w % 2)) >> 16) & 0xff; + _tmp[3] = (OPJ_UINT8) ((h * w + h * (w % 2)) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (7834) & 0xff; + _tmp[1] = ((7834) >> 8) & 0xff; + _tmp[2] = ((7834) >> 16) & 0xff; + _tmp[3] = ((7834) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (7834) & 0xff; + _tmp[1] = ((7834) >> 8) & 0xff; + _tmp[2] = ((7834) >> 16) & 0xff; + _tmp[3] = ((7834) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + + _tmp[0] = (256) & 0xff; + _tmp[1] = ((256) >> 8) & 0xff; + _tmp[2] = ((256) >> 16) & 0xff; + _tmp[3] = ((256) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, 0, 4); + _tmp[0] = (256) & 0xff; + _tmp[1] = ((256) >> 8) & 0xff; + _tmp[2] = ((256) >> 16) & 0xff; + _tmp[3] = ((256) >> 24) & 0xff; + c_vector_push_back(outfile, _tmp, + 0, 4); if (image->comps[0].prec > 8) { adjustR = (int) image->comps[0].prec - 8; @@ -1389,8 +1443,12 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { } for (i = 0; i < 256; i++) { - OPJ_UINT8 _1392[4] = {i, i, i, 0}; - c_vector_push_back(outfile, _1392, 0, 4); + _tmp[0] = i; + _tmp[1] = i; + _tmp[2] = i; + _tmp[3] = 0; + c_vector_push_back(outfile, _tmp, + 0, 4); } for (i = 0; i < w * h; i++) { @@ -1407,8 +1465,7 @@ int imagetobmp_c_vector(opj_image_t *image, c_vector *outfile) { r = 0; } - OPJ_UINT8 _1410[1] = {(OPJ_UINT8) r}; - c_vector_push_back(outfile, _1410, 0, 1); + c_vector_push_back(outfile, &r, 0, 1); if ((i + 1) % w == 0) { for (pad = (w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) { /* ADD */ diff --git a/src/bin/jp2/opj_decompress_c_vector.c b/src/bin/jp2/opj_decompress_c_vector.c index ed5fd2c7..e11f06b1 100644 --- a/src/bin/jp2/opj_decompress_c_vector.c +++ b/src/bin/jp2/opj_decompress_c_vector.c @@ -970,7 +970,7 @@ OPJ_FLOAT64 opj_clock(void) { #elif defined(__linux) struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - return ((OPJ_FLOAT64)ts.tv_sec + (OPJ_FLOAT64)ts.tv_nsec * 1e-9); + return ((OPJ_FLOAT64) ts.tv_sec + (OPJ_FLOAT64) ts.tv_nsec * 1e-9); #else /* Unix : use resource usage */ /* FIXME: this counts the total CPU time, instead of the user perceived time */ @@ -1236,6 +1236,15 @@ int main(int argc, char **argv) { OPJ_UINT32 numDecompressedImages = 0; OPJ_UINT32 cp_reduce; + FILE *file; + size_t size; + size_t _size; + int64_t _size1 = 0; + c_vector *v = NULL; + c_vector *outfile = NULL; + unsigned char *buf = NULL; + + /* set decoding parameters to default values */ set_default_parameters(¶meters); @@ -1316,7 +1325,7 @@ int main(int argc, char **argv) { /* read the input file and put it in memory */ /* ---------------------------------------- */ - FILE *file = fopen(parameters.infile, "rb"); + file = fopen(parameters.infile, "rb"); if (!file) { fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); @@ -1325,22 +1334,26 @@ int main(int argc, char **argv) { } fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_END); - size_t size = ftell(file); + _size1 = ftell(file); + if(_size1<0){ + size = (size_t) -_size1; + } else{ + size = (size_t) _size1; + } fseek(file, 0, SEEK_SET); - unsigned char *buf = (unsigned char *) malloc(size * sizeof(unsigned char)); + buf = (unsigned char *) malloc(size * sizeof(unsigned char)); if (!buf) { fclose(file); failed = 1; goto fin; } - size_t _size = fread(buf, 1, size, file); + _size = fread(buf, 1, size, file); fclose(file); if (_size != size) { free(buf); failed = 1; goto fin; } - c_vector *v = NULL; c_vector_init(&v); if (v == NULL) { free(buf); @@ -1627,7 +1640,6 @@ int main(int argc, char **argv) { goto fin; } } - c_vector *outfile = NULL; c_vector_init(&outfile); if (outfile == NULL) { fprintf(stderr, "[ERROR] Outfile c_vector\n"); @@ -1649,7 +1661,7 @@ int main(int argc, char **argv) { } break; case RAW_DFMT: /* RAW */ - if (imagetoraw_c_vector(image, outfile,OPJ_TRUE)) { + if (imagetoraw_c_vector(image, outfile, OPJ_TRUE)) { fprintf(stderr, "[ERROR] Error generating raw file. Outfile %s not generated\n", parameters.outfile); failed = 1; @@ -1659,7 +1671,7 @@ int main(int argc, char **argv) { break; case RAWL_DFMT: /* RAWL */ - if (imagetoraw_c_vector(image, outfile,OPJ_FALSE)) { + if (imagetoraw_c_vector(image, outfile, OPJ_FALSE)) { fprintf(stderr, "[ERROR] Error generating rawl file. Outfile %s not generated\n", parameters.outfile); diff --git a/src/lib/openjp2/c_vector.c b/src/lib/openjp2/c_vector.c index f16f53bb..89fbc929 100644 --- a/src/lib/openjp2/c_vector.c +++ b/src/lib/openjp2/c_vector.c @@ -31,7 +31,7 @@ int c_vector_init(c_vector **cVector) { * @return */ size_t c_vector_size(c_vector *cVector) { - if (!cVector)return -1; + if (!cVector)return 0; return cVector->total; } @@ -39,10 +39,11 @@ size_t c_vector_size(c_vector *cVector) { * resize c_vector * @param cVector */ -static int c_vector_resize(c_vector *cVector, size_t count) { +int c_vector_resize(c_vector *cVector, size_t count) { + void *items = NULL; if (!cVector)return -1; if (cVector->items) { - void *items = (void *) realloc(cVector->items, sizeof(void) * count); + items = (void *) realloc(cVector->items, sizeof(void) * count); if (items) { cVector->items = items; cVector->total = count; @@ -68,13 +69,14 @@ static int c_vector_resize(c_vector *cVector, size_t count) { * @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; + size_t index, new_size; + index = cVector->total; + new_size = count + cVector->total; if (c_vector_resize(cVector, new_size) < 0) { // error realloc return -1; } - memcpy(&(cVector->items[index]), &data[offset], count); + memcpy(cVector->items + index, data + offset, count); return 0; } @@ -98,10 +100,10 @@ int c_vector_push_back_zero(c_vector *cVector) { */ 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; + return 0; } - memcpy(&(cVector->items[index]), &data[offset], count); - return 0; + memcpy(cVector->items + index, data + offset, count); + return count; } /** @@ -114,21 +116,25 @@ size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, * @return */ size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offset, size_t count) { + size_t last_total; + size_t len; + size_t i; + size_t new_size; if (cVector->total <= index) { - return -1; + return 0; } - size_t last_total = cVector->total; - size_t new_size = count + cVector->total; + last_total = cVector->total; + new_size = count + cVector->total; if (c_vector_resize(cVector, new_size) < 0) { // error realloc - return -1; + return 0; } - 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); + len = last_total - index; + for (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; + memcpy(cVector->items + index, data + offset, count); + return count; } /** @@ -141,7 +147,7 @@ void *c_vector_get(c_vector *cVector, size_t offset) { if (cVector->total <= offset) { return NULL; } - return &cVector->items[offset]; + return cVector->items + offset; } /** @@ -161,15 +167,15 @@ void *c_vector_data(c_vector *cVector) { */ size_t c_vector_delete(c_vector *cVector, size_t offset, size_t count) { if (cVector->total <= offset) { - return -1; + return 0; } if (count + offset >= cVector->total) { cVector->total = cVector->total - offset; - return 0; + return count; } - memcpy(&(cVector->items[offset]), &(cVector->items[offset + count]), cVector->total - count - offset); + memcpy(cVector->items + offset, cVector->items + offset + count, cVector->total - count - offset); cVector->total = cVector->total - count; - return 0; + return count; } /** @@ -211,7 +217,7 @@ 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); + memcpy(p_buffer, v->items + v->index, p_nb_bytes); v->index += p_nb_bytes; return p_nb_bytes; } diff --git a/src/lib/openjp2/c_vector.h b/src/lib/openjp2/c_vector.h index 2aab522c..f9aaaa29 100644 --- a/src/lib/openjp2/c_vector.h +++ b/src/lib/openjp2/c_vector.h @@ -16,20 +16,20 @@ typedef struct c_vector c_vector; * init * @param cVector */ -int c_vector_init(c_vector **cVector); +extern int c_vector_init(c_vector **cVector); /** * get c_vector size * @param cVector * @return */ -size_t c_vector_size(c_vector *cVector); +extern size_t c_vector_size(c_vector *cVector); /** * resize c_vector * @param cVector */ -static int c_vector_resize(c_vector *cVector, size_t count); +extern int c_vector_resize(c_vector *cVector, size_t count); /** * push back c_vector @@ -38,14 +38,14 @@ static int c_vector_resize(c_vector *cVector, size_t count); * @param offset * @param count */ -int c_vector_push_back(c_vector *cVector, void *data, size_t offset, size_t count); +extern 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); +extern int c_vector_push_back_zero(c_vector *cVector); /** * set data @@ -56,7 +56,7 @@ int c_vector_push_back_zero(c_vector *cVector); * @param count * @return */ -size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, size_t count); +extern size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, size_t count); /** * insert data @@ -67,7 +67,7 @@ size_t c_vector_set(c_vector *cVector, size_t index, void *data, size_t offset, * @param count * @return */ -size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offset, size_t count); +extern size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offset, size_t count); /** * get c_vector data @@ -75,14 +75,14 @@ size_t c_vector_insert(c_vector *cVector, size_t index, void *data, size_t offse * @param offset * @return */ -void *c_vector_get(c_vector *cVector, size_t offset); +extern void *c_vector_get(c_vector *cVector, size_t offset); /** * get c_vector data * @param cVector * @return */ -void *c_vector_data(c_vector *cVector); +extern void *c_vector_data(c_vector *cVector); /** * c_vector delete @@ -90,21 +90,21 @@ void *c_vector_data(c_vector *cVector); * @param offset * @param count */ -size_t c_vector_delete(c_vector *cVector, size_t offset, size_t count); +extern 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); +extern 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); +extern int c_vector_seek(c_vector *cVector, size_t offset, int whence); +extern int c_vector_seekg(size_t offset,c_vector *cVector); +extern 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); +extern 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); +extern size_t c_vector_write(void *p_buffer, size_t p_nb_bytes, c_vector *v); #endif //CLANGTOOLS_VECTOR_H