Branch
Hash :
e69dd40c
Author :
Date :
2024-01-23T13:26:41
Reorganize source to make things easier to find
- Move all libjpeg documentation, except for README.ijg, into the doc/
subdirectory.
- Move the TurboJPEG C API documentation from doc/html/ into
doc/turbojpeg/.
- Move all C source code and headers into a src/ subdirectory.
- Move turbojpeg-jni.c into the java/ subdirectory.
Referring to #226, there is no ideal solution to this problem. A
semantically ideal solution would have involved placing all source code,
including the SIMD and Java source code, under src/ (or perhaps placing
C library source code under lib/ and C test program source code under
test/), all header files under include/, and all documentation under
doc/. However:
- To me it makes more sense to have separate top-level directories for
each language, since the SIMD extensions and the Java API are
technically optional features. src/ now contains only the code that
is relevant to the core C API libraries and associated programs.
- I didn't want to bury the java/ and simd/ directories or add a level
of depth to them, since both directories already contain source code
that is 3-4 levels deep.
- I would prefer not to separate the header files from the C source
code, because:
1. It would be disruptive. libjpeg and libjpeg-turbo have
historically placed C source code and headers in the same
directory, and people who are familiar with both projects (self
included) are used to looking for the headers in the same directory
as the C source code.
2. In terms of how the headers are used internally in libjpeg-turbo,
the distinction between public and private headers is a bit fuzzy.
- It didn't make sense to separate the test source code from the library
source code, since there is not a clear distinction in some cases.
(For instance, the IJG image I/O functions are used by cjpeg and djpeg
as well as by the TurboJPEG API.)
This solution is minimally disruptive, since it keeps all C source code
and headers together and keeps java/ and simd/ as top-level directories.
It is a bit awkward, because java/ and simd/ technically contain source
code, even though they are not under src/. However, other solutions
would have been more awkward for different reasons.
Closes #226
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/*
* Copyright (C)2022-2023 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the libjpeg-turbo Project nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "jinclude.h"
#include <errno.h>
#define CHECK_VALUE(actual, expected, desc) \
if (actual != expected) { \
printf("ERROR in line %d: " desc " is %d, should be %d\n", \
__LINE__, actual, expected); \
return -1; \
}
#define CHECK_ERRNO(errno_return, expected_errno) \
CHECK_VALUE(errno_return, expected_errno, "Return value") \
CHECK_VALUE(errno, expected_errno, "errno") \
#ifdef _MSC_VER
void invalid_parameter_handler(const wchar_t *expression,
const wchar_t *function, const wchar_t *file,
unsigned int line, uintptr_t pReserved)
{
}
#endif
int main(int argc, char **argv)
{
#if !defined(NO_GETENV) || !defined(NO_PUTENV)
int err;
#endif
#ifndef NO_GETENV
char env[3];
#endif
#ifdef _MSC_VER
_set_invalid_parameter_handler(invalid_parameter_handler);
#endif
/***************************************************************************/
#ifndef NO_PUTENV
printf("PUTENV_S():\n");
errno = 0;
err = PUTENV_S(NULL, "12");
CHECK_ERRNO(err, EINVAL);
errno = 0;
err = PUTENV_S("TESTENV", NULL);
CHECK_ERRNO(err, EINVAL);
errno = 0;
err = PUTENV_S("TESTENV", "12");
CHECK_ERRNO(err, 0);
printf("SUCCESS!\n\n");
#endif
/***************************************************************************/
#ifndef NO_GETENV
printf("GETENV_S():\n");
errno = 0;
env[0] = 1;
env[1] = 2;
env[2] = 3;
err = GETENV_S(env, 3, NULL);
CHECK_ERRNO(err, 0);
CHECK_VALUE(env[0], 0, "env[0]");
CHECK_VALUE(env[1], 2, "env[1]");
CHECK_VALUE(env[2], 3, "env[2]");
errno = 0;
env[0] = 1;
env[1] = 2;
env[2] = 3;
err = GETENV_S(env, 3, "TESTENV2");
CHECK_ERRNO(err, 0);
CHECK_VALUE(env[0], 0, "env[0]");
CHECK_VALUE(env[1], 2, "env[1]");
CHECK_VALUE(env[2], 3, "env[2]");
errno = 0;
err = GETENV_S(NULL, 3, "TESTENV");
CHECK_ERRNO(err, EINVAL);
errno = 0;
err = GETENV_S(NULL, 0, "TESTENV");
CHECK_ERRNO(err, 0);
errno = 0;
env[0] = 1;
err = GETENV_S(env, 0, "TESTENV");
CHECK_ERRNO(err, EINVAL);
CHECK_VALUE(env[0], 1, "env[0]");
errno = 0;
env[0] = 1;
env[1] = 2;
env[2] = 3;
err = GETENV_S(env, 1, "TESTENV");
CHECK_VALUE(err, ERANGE, "Return value");
CHECK_VALUE(errno, 0, "errno");
CHECK_VALUE(env[0], 0, "env[0]");
CHECK_VALUE(env[1], 2, "env[1]");
CHECK_VALUE(env[2], 3, "env[2]");
errno = 0;
env[0] = 1;
env[1] = 2;
env[2] = 3;
err = GETENV_S(env, 2, "TESTENV");
CHECK_VALUE(err, ERANGE, "Return value");
CHECK_VALUE(errno, 0, "errno");
CHECK_VALUE(env[0], 0, "env[0]");
CHECK_VALUE(env[1], 2, "env[1]");
CHECK_VALUE(env[2], 3, "env[2]");
errno = 0;
env[0] = 1;
env[1] = 2;
env[2] = 3;
err = GETENV_S(env, 3, "TESTENV");
CHECK_ERRNO(err, 0);
CHECK_VALUE(env[0], '1', "env[0]");
CHECK_VALUE(env[1], '2', "env[1]");
CHECK_VALUE(env[2], 0, "env[2]");
printf("SUCCESS!\n\n");
#endif
/***************************************************************************/
return 0;
}