Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/leptonica/src/regutils.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /*====================================================================* | |
| 2 - Copyright (C) 2001 Leptonica. All rights reserved. | |
| 3 - | |
| 4 - Redistribution and use in source and binary forms, with or without | |
| 5 - modification, are permitted provided that the following conditions | |
| 6 - are met: | |
| 7 - 1. Redistributions of source code must retain the above copyright | |
| 8 - notice, this list of conditions and the following disclaimer. | |
| 9 - 2. Redistributions in binary form must reproduce the above | |
| 10 - copyright notice, this list of conditions and the following | |
| 11 - disclaimer in the documentation and/or other materials | |
| 12 - provided with the distribution. | |
| 13 - | |
| 14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY | |
| 18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 25 *====================================================================*/ | |
| 26 | |
| 27 #ifndef LEPTONICA_REGUTILS_H | |
| 28 #define LEPTONICA_REGUTILS_H | |
| 29 | |
| 30 /*! | |
| 31 * \file regutils.h | |
| 32 * | |
| 33 * <pre> | |
| 34 * Contains this regression test parameter packaging struct | |
| 35 * struct L_RegParams | |
| 36 * | |
| 37 * The regression test utility allows you to write regression tests | |
| 38 * that compare results with existing "golden files" and with | |
| 39 * compiled in data. | |
| 40 * | |
| 41 * Regression tests can be called in three ways. | |
| 42 * For example, for distance_reg: | |
| 43 * | |
| 44 * Case 1: distance_reg [compare] | |
| 45 * This runs the test against the set of golden files. It | |
| 46 * appends to 'outfile.txt' either "SUCCESS" or "FAILURE", | |
| 47 * as well as the details of any parts of the test that failed. | |
| 48 * It writes to a temporary file stream (fp). | |
| 49 * Using 'compare' on the command line is optional. | |
| 50 * | |
| 51 * Case 2: distance_reg generate | |
| 52 * This generates golden files in /tmp for the reg test. | |
| 53 * | |
| 54 * Case 3: distance_reg display | |
| 55 * This runs the test but makes no comparison of the output | |
| 56 * against the set of golden files. In addition, this displays | |
| 57 * images and plots that are specified in the test under | |
| 58 * control of the display variable. Display is enabled only | |
| 59 * for this case. | |
| 60 * | |
| 61 * Regression tests follow the pattern given below. Tests are | |
| 62 * automatically numbered sequentially, and it is convenient to | |
| 63 * comment each with a number to keep track (for comparison tests | |
| 64 * and for debugging). In an actual case, comparisons of pix and | |
| 65 * of files can occur in any order. We give a specific order here | |
| 66 * for clarity. | |
| 67 * | |
| 68 * L_REGPARAMS *rp; // holds data required by the test functions | |
| 69 * | |
| 70 * // Setup variables; optionally open stream | |
| 71 * if (regTestSetup(argc, argv, &rp)) | |
| 72 * return 1; | |
| 73 * | |
| 74 * // Test pairs of generated pix for identity. This compares | |
| 75 * // two pix; no golden file is generated. | |
| 76 * regTestComparePix(rp, pix1, pix2); // 0 | |
| 77 * | |
| 78 * // Test pairs of generated pix for similarity. This compares | |
| 79 * // two pix; no golden file is generated. The last arg determines | |
| 80 * // if stats are to be written to stderr. | |
| 81 * regTestCompareSimilarPix(rp, pix1, pix2, 15, 0.001, 0); // 1 | |
| 82 * | |
| 83 * // Generation of <newfile*> outputs and testing for identity | |
| 84 * // These files can be anything, of course. | |
| 85 * regTestCheckFile(rp, <newfile0>); // 2 | |
| 86 * regTestCheckFile(rp, <newfile1>); // 3 | |
| 87 * | |
| 88 * // Test pairs of output golden files for identity. Here we | |
| 89 * // are comparing golden files 2 and 3. | |
| 90 * regTestCompareFiles(rp, 2, 3); // 4 | |
| 91 * | |
| 92 * // "Write and check". This writes a pix using a canonical | |
| 93 * // formulation for the local filename and either: | |
| 94 * // case 1: generates a golden file | |
| 95 * // case 2: compares the local file with a golden file | |
| 96 * // case 3: generates local files and displays | |
| 97 * // Here we write the pix compressed with png and jpeg, respectively; | |
| 98 * // Then check against the golden file. The internal %index | |
| 99 * // is incremented; it is embedded in the local filename and, | |
| 100 * // if generating, in the golden file as well. | |
| 101 * regTestWritePixAndCheck(rp, pix1, IFF_PNG); // 5 | |
| 102 * regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); // 6 | |
| 103 * | |
| 104 * // Display if reg test was called in 'display' mode | |
| 105 * pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display); | |
| 106 * | |
| 107 * // Clean up and output result | |
| 108 * regTestCleanup(rp); | |
| 109 * </pre> | |
| 110 */ | |
| 111 | |
| 112 /*----------------------------------------------------------------------------* | |
| 113 * Regression test parameter packer * | |
| 114 *----------------------------------------------------------------------------*/ | |
| 115 | |
| 116 /*! Regression test parameter packer */ | |
| 117 struct L_RegParams | |
| 118 { | |
| 119 FILE *fp; /*!< stream to temporary output file for compare mode */ | |
| 120 char *testname; /*!< name of test, without '_reg' */ | |
| 121 char *tempfile; /*!< name of temp file for compare mode output */ | |
| 122 l_int32 mode; /*!< generate, compare or display */ | |
| 123 l_atomic index; /*!< index into saved files for this test; 0-based */ | |
| 124 l_int32 success; /*!< overall result of the test */ | |
| 125 l_int32 display; /*!< 1 if in display mode; 0 otherwise */ | |
| 126 L_TIMER tstart; /*!< marks beginning of the reg test */ | |
| 127 }; | |
| 128 typedef struct L_RegParams L_REGPARAMS; | |
| 129 | |
| 130 | |
| 131 /*! Running modes for the test */ | |
| 132 /*! Regtest Mode */ | |
| 133 enum { | |
| 134 L_REG_GENERATE = 0, | |
| 135 L_REG_COMPARE = 1, | |
| 136 L_REG_DISPLAY = 2 | |
| 137 }; | |
| 138 | |
| 139 | |
| 140 #endif /* LEPTONICA_REGUTILS_H */ | |
| 141 |
